本文へ移動

デスクトップアプリのログインと機能制御のコード例

管理画面から対象言語の接続関数をコピーし、以下のコードを既存プロジェクトに組み込みます。メールアドレスとパスワードはログイン画面から受け取り、export はポリシーに実在する機能名へ置き換えてください。各例は 1 回の操作を示しています。実際のアプリでは同じクライアントを実行中ずっと保持し、終了時に閉じます。

Go
Go
app, err := connectLaunch()
if err != nil { return err }
defer app.Close()
if _, err := app.Login(ctx, email, password); err != nil { return err }
return app.RunFeature("export", func() error {
    return exportReport()
})
Python
Python
with connect_launch() as app:
    app.login(email, password)
    result = app.run_feature("export", export_report)
C# / .NET
C# / .NET
await using var app = LaunchConnection.Open();
await app.Login(email, password);
await app.RunFeature("export", async () => {
    await ExportReport();
});
Java
Java
try (var app = LaunchConnection.open()) {
    app.login(email, passwordChars);
    app.runFeature("export", () -> exportReport());
}
JavaScript / Node.js / TypeScript
JavaScript / Node.js / TypeScript
const app = connectLaunch();
try {
  await app.login(email, password);
  const result = await app.runFeature('export', () => exportReport());
} finally {
  await app.close();
}
Rust
Rust
let mut app = connect_launch()?;
app.login(&email, &password)?;
let result = app.run_feature("export", || {
    export_report()?;
    Ok(())
})?;
app.close();
Ruby
Ruby
app = connect_launch
begin
  app.login(email, password)
  result = app.run_feature('export') { export_report }
ensure
  app.close
end
C
C
static int export_action(void *context) {
    return export_report(context); /* Return 1 only on success. */
}

launch_application *app = connect_launch();
if (!app) return 0;
int ok = launch_application_login(app, email, password);
if (ok) ok = launch_application_run_feature(app, "export", export_action, context);
/* Check launch_application_error(app) on failure; never log credentials. */
launch_application_close(app);
return ok;
C++
C++
auto app = connectLaunch();
app.Login(email.c_str(), password.c_str());
app.RunFeature("export", [&] { exportReport(); });

Go の ctx にはアプリのライフサイクルに対応するコンテキストを渡します。Java のパスワードには char[] を使います。C の機能コールバックは処理が成功した場合だけ 1 を返します。Node.js / Electron では SDK をメインプロセスまたは信頼できるバックエンドで動かし、ネットワーク通信で UI スレッドをブロックしないようにします。