انتقل إلى المحتوى

أمثلة شيفرة لتسجيل دخول سطح المكتب وحماية الميزات

انسخ أولًا دالة الاتصال للغتك من الإدارة، ثم عدّل هذه المقاطع لتناسب مشروعك. خذ البريد وكلمة المرور من واجهة الدخول، واستبدل export باسم ميزة موجودة فعلًا في السياسة. يعرض كل مقطع عملية واحدة؛ احتفظ بالعميل نفسه طوال تشغيل التطبيق وأغلقه عند الخروج.

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 في العملية الرئيسية أو خلفية موثوقة، ولا تجعل طلبات الشبكة تعطل مسار الواجهة.