OS Information(OS 情報)
Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
「OS Information(OS 情報)」プラグインを使用して、オペレーティング・システムに関する情報を読み取ります。
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android | ||
| ios |
はじめに、「OS Information」プラグインをインストールしてください。
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
npm run tauri add osyarn run tauri add ospnpm tauri add osdeno task tauri add osbun tauri add oscargo tauri add os-
src-tauriフォルダで次のコマンドを実行して、このプラグインをCargo.toml内のプロジェクトの依存関係に追加します:cargo add tauri-plugin-os -
追加したプラグインを初期化するために
lib.rsを修正します:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_os::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
JavaScript で使用する場合は、npm パッケージもインストールしてください:
npm install @tauri-apps/plugin-osyarn add @tauri-apps/plugin-ospnpm add @tauri-apps/plugin-osdeno add npm:@tauri-apps/plugin-osbun add @tauri-apps/plugin-os
このプラグインを使用すると、現在のオペレーティング・システム*から複数の情報を照会できます。利用可能なすべての関数については、JavaScript API または Rust API の各リファレンスをご覧ください。
* オペレーション・システム: 原文は operational system で、直訳では「運用システム」の意味になりますが、ここでは「オペレーション・システム」の意味に解釈しています。
platform は、使用中のオペレーティング・システムを表す文字列を返します。この値がコンパイル時に設定されます。取り得る値は linux、macos、ios、freebsd、dragonfly、netbsd、openbsd、solaris、android、windows です。
import { platform } from '@tauri-apps/plugin-os';// `"withGlobalTauri": true` を使用する場合は、// const { platform } = window.__TAURI__.os; を使用できます
const currentPlatform = platform();console.log(currentPlatform);// コンソールに「windows」と表示しますlet platform = tauri_plugin_os::platform();println!("Platform: {}", platform);// ターミナルに「windows」と表示しますデフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、capabilities 設定でアクセス権限を変更する必要があります。
詳細については「セキュリティ・レベル Capabilities」の章を参照してください。また、プラグインのアクセス権限を設定するには「プライグン・アクセス権の使用」の章のステップ・バイ・ステップ・ガイドを参照してください。
{ "permissions": [ ..., "os:default" ]}Default Permission
This permission set configures which operating system information are available to gather from the frontend.
Granted Permissions
All information except the host name are available.
This default permission set includes the following:
allow-archallow-exe-extensionallow-familyallow-localeallow-os-typeallow-platformallow-version
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the arch command without any pre-configured scope. |
|
|
Denies the arch command without any pre-configured scope. |
|
|
Enables the exe_extension command without any pre-configured scope. |
|
|
Denies the exe_extension command without any pre-configured scope. |
|
|
Enables the family command without any pre-configured scope. |
|
|
Denies the family command without any pre-configured scope. |
|
|
Enables the hostname command without any pre-configured scope. |
|
|
Denies the hostname command without any pre-configured scope. |
|
|
Enables the locale command without any pre-configured scope. |
|
|
Denies the locale command without any pre-configured scope. |
|
|
Enables the os_type command without any pre-configured scope. |
|
|
Denies the os_type command without any pre-configured scope. |
|
|
Enables the platform command without any pre-configured scope. |
|
|
Denies the platform command without any pre-configured scope. |
|
|
Enables the version command without any pre-configured scope. |
|
|
Denies the version command without any pre-configured scope. |
【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】
© 2025 Tauri Contributors. CC-BY / MIT