Autostart(自動起動)
Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
システム起動時にアプリを自動的に起動します。
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android | | |
| ios | |
はじめに、「Autostart(自動起動)」プラグインをインストールしてください。
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
npm run tauri add autostartyarn run tauri add autostartpnpm tauri add autostartdeno task tauri add autostartbun tauri add autostartcargo tauri add autostart-
src-tauriフォルダで次のコマンドを実行して、Cargo.toml内のプロジェクトの依存関係にこのプラグインを追加します:cargo add tauri-plugin-autostart --target 'cfg(any(target_os = "macos", windows, target_os = "linux"))' -
追加したプラグインを初期化するために
lib.rsを修正します:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().setup(|app| {#[cfg(desktop)]app.handle().plugin(tauri_plugin_autostart::init(tauri_plugin_autostart::MacosLauncher::LaunchAgent, Some(vec!["--flag1", "--flag2"]) /* アプリに渡す任意の数の引数 */));Ok(())}).run(tauri::generate_context!()).expect("error while running tauri application");} -
お好みの JavaScript パッケージ・マネージャーを使用して、「JavaScript Guest」バインディングをインストールします:
npm install @tauri-apps/plugin-autostartyarn add @tauri-apps/plugin-autostartpnpm add @tauri-apps/plugin-autostartdeno add npm:@tauri-apps/plugin-autostartbun add @tauri-apps/plugin-autostart
「Autostart(自動起動)」プラグインは、JavaScript と Rust の両方で利用できます。
import { enable, isEnabled, disable } from '@tauri-apps/plugin-autostart';// `"withGlobalTauri": true` を使用する場合は、// const { enable, isEnabled, disable } = window.__TAURI__.autostart; を使用できます;
// autostart を有効化await enable();// 有効化状態を確認console.log(`registered for autostart? ${await isEnabled()}`);// autostart を無効化disable();#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() { tauri::Builder::default() .setup(|app| { #[cfg(desktop)] { use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_autostart::ManagerExt;
app.handle().plugin(tauri_plugin_autostart::init( MacosLauncher::LaunchAgent, Some(vec!["--flag1", "--flag2"]), ));
// 「autostart マネージャー」を入手 let autostart_manager = app.autolaunch(); // autostart を有効化 let _ = autostart_manager.enable(); // 有効化状態を確認 println!("registered for autostart? {}", autostart_manager.is_enabled().unwrap()); // autostart を無効化 let _ = autostart_manager.disable(); } Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、capabilities 設定でアクセス権限を変更する必要があります。
詳細については「セキュリティ・レベル Capabilities」の章を参照してください。また、プラグインのアクセス権限を設定するには「プライグン・アクセス権の使用」の章のステップ・バイ・ステップ・ガイドを参照してください。
{ "permissions": [ ..., "autostart:allow-enable", "autostart:allow-disable", "autostart:allow-is-enabled" ]}Default Permission
This permission set configures if your application can enable or disable auto starting the application on boot.
Granted Permissions
It allows all to check, enable and disable the automatic start on boot.
This default permission set includes the following:
allow-enableallow-disableallow-is-enabled
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the disable command without any pre-configured scope. |
|
|
Denies the disable command without any pre-configured scope. |
|
|
Enables the enable command without any pre-configured scope. |
|
|
Denies the enable command without any pre-configured scope. |
|
|
Enables the is_enabled command without any pre-configured scope. |
|
|
Denies the is_enabled command without any pre-configured scope. |
【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】
© 2025 Tauri Contributors. CC-BY / MIT