From 0798d0fff5b5c866237e5d085e44ea10a1a0ddd5 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Mon, 23 Oct 2023 17:33:26 -0300 Subject: [PATCH 1/8] first stub --- src/content/docs/features/os-info.mdx | 309 +++++++++++++++++++++++++- 1 file changed, 305 insertions(+), 4 deletions(-) diff --git a/src/content/docs/features/os-info.mdx b/src/content/docs/features/os-info.mdx index d49f66dc21..1215d119fb 100644 --- a/src/content/docs/features/os-info.mdx +++ b/src/content/docs/features/os-info.mdx @@ -3,11 +3,312 @@ title: OS Information description: Read information about the operating system. --- -import Stub from '@components/Stub.astro'; import PluginLinks from '@components/PluginLinks.astro'; +import { Tabs, TabItem } from '@astrojs/starlight/components'; +import CommandTabs from '@components/CommandTabs.astro'; + - - Based on https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/os - +Read information about the operating system using the OS Information plugin. + +## Setup + +Install the clipboard plugin to get started. + + + + + 1. Use your project's package manager to add the dependency: + + + + 2. Modify `lib.rs` to initialize the plugin: + + {/* TODO: Revise once https://github.com/tauri-apps/tauri/issues/7696 is in */} + + ```rust + #[cfg_attr(mobile, tauri::mobile_entry_point)] + pub fn run() { + tauri::Builder::default() + // Initialize the plugin + .plugin(tauri_plugin_os::init()) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); + } + ``` + + + + + 1. Run `cargo add tauri-plugin-os` to add the plugin to the project's dependencies in `Cargo.toml`. + + 2. Modify `lib.rs` to initialize the plugin: + + ```rust + // lib.rs + #[cfg_attr(mobile, tauri::mobile_entry_point)] + pub fn run() { + tauri::Builder::default() + // Initialize the plugin + .plugin(tauri_plugin_os::init()) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); + } + ``` + + 3. If you'd like to use in JavaScript then install the npm package as well: + + + + + + + +## Usage + +Here are the available data you can query with the OS Information plugin: + +- [OS Platform](#os-platform) +- [OS Family](#os-family) +- [OS Version](#os-version) +- [OS Type](#os-type) +- [OS Architeture](#os-architeture) +- [OS Locale](#os-locale) +- [OS Executable extension](#os-executable) +- [OS Hostname](#os-hostname) + +{/* TODO: Link to which language to use, frontend vs. backend guide when it's made */} + +The OS Information plugin is available in both JavaScript and Rust. For the examples below consider a machine running Windows 10 22H2. + +### OS Platform + + + + +```js +import { platform } from '@tauri-apps/plugin-os'; + +const platform = await platform(); +console.log(platform); +// Prints "windows" to the console +``` + + + + +```rust +#[tauri::command] +fn get_platform() { + let platform = tauri_plugin_os::platform(); + println!("Platform: {:?}", platform); + // Prints "windows" to the terminal +} +``` + + + + +### OS Family + + + + +```js +import { family } from '@tauri-apps/plugin-os'; + +const family = await family(); +console.log(family); +// Prints "windows" to the console +``` + + + + +```rust +#[tauri::command] +fn get_family() { + let family = tauri_plugin_os::family(); + println!("Family: {:?}", family); + // Prints "windows" to the terminal +} +``` + + + + +### OS Version + + + + +```js +import { version } from '@tauri-apps/plugin-os'; + +const version = await version(); +console.log(version); +// Prints "10.0.19045" to the console +``` + + + + +```rust +#[tauri::command] +fn get_version() { + let version = tauri_plugin_os::version(); + println!("Version: {:?}", version); + // Prints "10.0.19045" to the terminal +} +``` + + + + +### OS Type + + + + +```js +import { type } from '@tauri-apps/plugin-os'; + +const type = await type(); +console.log(type); +// Prints "windows" to the console +``` + + + + +```rust +#[tauri::command] +fn get_type() { + let type = tauri_plugin_os::type_(); + println!("Type: {:?}", type); + // Prints "windows" to the terminal +} +``` + + + + +### OS Architecture + + + + +```js +import { arch } from '@tauri-apps/plugin-os'; + +const arch = await arch(); +console.log(arch); +// Prints "x86_64" to the console +``` + + + + +```rust +#[tauri::command] +fn get_arch() { + let arch = tauri_plugin_os::arch(); + println!("Architecture: {:?}", arch); + // Prints "x86_64" to the terminal +} +``` + + + + +### OS Locale + + + + +```js +import { locale } from '@tauri-apps/plugin-os'; + +const locale = await locale(); +console.log(locale); +// Prints "en-US" to the console +``` + + + + +```rust +#[tauri::command] +fn get_locale() { + let locale = tauri_plugin_os::locale(); + println!("Locale: {:?}", locale); + // Prints "en-US" to the terminal +} +``` + + + + +### OS Executable Extension + + + + +```js +import { exeExtension } from '@tauri-apps/plugin-os'; + +const exeExtension = await exeExtension(); +console.log(exeExtension); +// Prints "exe" to the console +``` + + + + +```rust +#[tauri::command] +fn get_exe_extension() { + let exe_extension = tauri_plugin_os::exe_extension(); + println!("Exe Extension: {:?}", exe_extension); + // Prints "exe" to the terminal +} +``` + + + + +### OS Hostname + + + + +```js +import { hostname } from '@tauri-apps/plugin-os'; + +const hostname = await hostname(); +console.log(hostname); +// Prints "TauriGroup" to the console +``` + + + + +```rust +#[tauri::command] +fn get_hostname() { + let hostname = tauri_plugin_os::hostname(); + println!("Hostname: {:?}", hostname); + // Prints "TauriGroup" to the terminal +} +``` + + + From c7868dedc40cb70deaabcd3121b9bd5d9dda3ac9 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Mon, 23 Oct 2023 17:42:38 -0300 Subject: [PATCH 2/8] add notes --- src/content/docs/features/os-info.mdx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/content/docs/features/os-info.mdx b/src/content/docs/features/os-info.mdx index 1215d119fb..3c5e15aa7d 100644 --- a/src/content/docs/features/os-info.mdx +++ b/src/content/docs/features/os-info.mdx @@ -90,6 +90,7 @@ Here are the available data you can query with the OS Information plugin: The OS Information plugin is available in both JavaScript and Rust. For the examples below consider a machine running Windows 10 22H2. ### OS Platform +Returns a string describing the specific operating system in use. The value is set at compile time. Possible values are 'linux', 'macos', 'ios', 'freebsd', 'dragonfly', 'netbsd', 'openbsd', 'solaris', 'android', 'windows' @@ -119,6 +120,8 @@ fn get_platform() { ### OS Family +Possible values are 'unix', 'windows'. + @@ -147,6 +150,8 @@ fn get_family() { ### OS Version +Returns the current operating system version. + @@ -175,6 +180,8 @@ fn get_version() { ### OS Type +Returns 'linux' on Linux, 'macos' on macOS, 'windows' on Windows, 'ios' on iOS and 'android' on Android + @@ -203,6 +210,8 @@ fn get_type() { ### OS Architecture +Possible values are 'x86', 'x86_64', 'arm', 'aarch64', 'mips', 'mips64', 'powerpc', 'powerpc64', 'riscv64', 's390x', 'sparc64'. + @@ -231,6 +240,8 @@ fn get_arch() { ### OS Locale +Returns a string with a BCP-47 language tag. + @@ -259,6 +270,8 @@ fn get_locale() { ### OS Executable Extension +Returns the file extension, if any, used for executable binaries on this platform. Possible values are 'exe' and '' (empty string). + @@ -287,6 +300,8 @@ fn get_exe_extension() { ### OS Hostname +Returns the host name of the operating system. + From b4ca51f168d826fb200633df4f38f24f78098ca5 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Mon, 23 Oct 2023 18:03:26 -0300 Subject: [PATCH 3/8] remove rust context --- src/content/docs/features/os-info.mdx | 84 +++++++++++---------------- 1 file changed, 34 insertions(+), 50 deletions(-) diff --git a/src/content/docs/features/os-info.mdx b/src/content/docs/features/os-info.mdx index 3c5e15aa7d..534fdfa30d 100644 --- a/src/content/docs/features/os-info.mdx +++ b/src/content/docs/features/os-info.mdx @@ -7,7 +7,6 @@ import PluginLinks from '@components/PluginLinks.astro'; import { Tabs, TabItem } from '@astrojs/starlight/components'; import CommandTabs from '@components/CommandTabs.astro'; - Read information about the operating system using the OS Information plugin. @@ -72,6 +71,8 @@ Install the clipboard plugin to get started. +{/* TODO: ADD eol() usage guide */} + ## Usage Here are the available data you can query with the OS Information plugin: @@ -90,6 +91,7 @@ Here are the available data you can query with the OS Information plugin: The OS Information plugin is available in both JavaScript and Rust. For the examples below consider a machine running Windows 10 22H2. ### OS Platform + Returns a string describing the specific operating system in use. The value is set at compile time. Possible values are 'linux', 'macos', 'ios', 'freebsd', 'dragonfly', 'netbsd', 'openbsd', 'solaris', 'android', 'windows' @@ -107,12 +109,9 @@ console.log(platform); ```rust -#[tauri::command] -fn get_platform() { - let platform = tauri_plugin_os::platform(); - println!("Platform: {:?}", platform); - // Prints "windows" to the terminal -} +let platform = tauri_plugin_os::platform(); +println!("Platform: {}", platform); +// Prints "windows" to the terminal ``` @@ -137,12 +136,9 @@ console.log(family); ```rust -#[tauri::command] -fn get_family() { - let family = tauri_plugin_os::family(); - println!("Family: {:?}", family); - // Prints "windows" to the terminal -} +let family = tauri_plugin_os::family(); +println!("Family: {}", family); +//Prints "windows" to the terminal ``` @@ -167,12 +163,10 @@ console.log(version); ```rust -#[tauri::command] -fn get_version() { - let version = tauri_plugin_os::version(); - println!("Version: {:?}", version); - // Prints "10.0.19045" to the terminal -} +let version = tauri_plugin_os::version(); +println!("Version: {}", version); +// Prints "10.0.19045" to the terminal + ``` @@ -197,12 +191,10 @@ console.log(type); ```rust -#[tauri::command] -fn get_type() { - let type = tauri_plugin_os::type_(); - println!("Type: {:?}", type); - // Prints "windows" to the terminal -} +let os_type = tauri_plugin_os::type_(); +println!("Type: {}", os_type); +// Prints "windows" to the terminal + ``` @@ -227,12 +219,10 @@ console.log(arch); ```rust -#[tauri::command] -fn get_arch() { - let arch = tauri_plugin_os::arch(); - println!("Architecture: {:?}", arch); - // Prints "x86_64" to the terminal -} +let arch = tauri_plugin_os::arch(); +println!("Architecture: {}", arch); +// Prints "x86_64" to the terminal + ``` @@ -257,12 +247,10 @@ console.log(locale); ```rust -#[tauri::command] -fn get_locale() { - let locale = tauri_plugin_os::locale(); - println!("Locale: {:?}", locale); - // Prints "en-US" to the terminal -} +let locale = tauri_plugin_os::locale(); +println!("Locale: {:?}", locale); +// Prints "en-US" to the terminal + ``` @@ -287,12 +275,10 @@ console.log(exeExtension); ```rust -#[tauri::command] -fn get_exe_extension() { - let exe_extension = tauri_plugin_os::exe_extension(); - println!("Exe Extension: {:?}", exe_extension); - // Prints "exe" to the terminal -} +let exe_extension = tauri_plugin_os::exe_extension(); +println!("Exe Extension: {}", exe_extension); +// Prints "exe" to the terminal + ``` @@ -310,19 +296,17 @@ import { hostname } from '@tauri-apps/plugin-os'; const hostname = await hostname(); console.log(hostname); -// Prints "TauriGroup" to the console +// Prints the host name to the console ``` ```rust -#[tauri::command] -fn get_hostname() { - let hostname = tauri_plugin_os::hostname(); - println!("Hostname: {:?}", hostname); - // Prints "TauriGroup" to the terminal -} +let hostname = tauri_plugin_os::hostname(); +println!("Hostname: {}", hostname); +// Prints the host name to the terminal + ``` From 22e41a2cc29f90355fdcc1c1d699afaba7cfccf8 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Mon, 23 Oct 2023 18:21:00 -0300 Subject: [PATCH 4/8] fix: broken anchor --- src/content/docs/features/os-info.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/docs/features/os-info.mdx b/src/content/docs/features/os-info.mdx index 534fdfa30d..45838932a6 100644 --- a/src/content/docs/features/os-info.mdx +++ b/src/content/docs/features/os-info.mdx @@ -81,9 +81,9 @@ Here are the available data you can query with the OS Information plugin: - [OS Family](#os-family) - [OS Version](#os-version) - [OS Type](#os-type) -- [OS Architeture](#os-architeture) +- [OS Architeture](#os-architecture) - [OS Locale](#os-locale) -- [OS Executable extension](#os-executable) +- [OS Executable extension](#os-executable-extension) - [OS Hostname](#os-hostname) {/* TODO: Link to which language to use, frontend vs. backend guide when it's made */} From bc269a20dc29bb6fdfe66935e0338b0333b932ec Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Sun, 5 Nov 2023 19:11:01 -0300 Subject: [PATCH 5/8] simplify guide --- src/content/docs/features/os-info.mdx | 216 +------------------------- 1 file changed, 5 insertions(+), 211 deletions(-) diff --git a/src/content/docs/features/os-info.mdx b/src/content/docs/features/os-info.mdx index 45838932a6..4f63ca4f34 100644 --- a/src/content/docs/features/os-info.mdx +++ b/src/content/docs/features/os-info.mdx @@ -13,7 +13,7 @@ Read information about the operating system using the OS Information plugin. ## Setup -Install the clipboard plugin to get started. +Install the OS Information plugin to get started. @@ -71,28 +71,15 @@ Install the clipboard plugin to get started. -{/* TODO: ADD eol() usage guide */} - ## Usage -Here are the available data you can query with the OS Information plugin: - -- [OS Platform](#os-platform) -- [OS Family](#os-family) -- [OS Version](#os-version) -- [OS Type](#os-type) -- [OS Architeture](#os-architecture) -- [OS Locale](#os-locale) -- [OS Executable extension](#os-executable-extension) -- [OS Hostname](#os-hostname) +With this plugin you can query multiple information from current operational system, here is how you can utilize the OS Information plugin: {/* TODO: Link to which language to use, frontend vs. backend guide when it's made */} -The OS Information plugin is available in both JavaScript and Rust. For the examples below consider a machine running Windows 10 22H2. - -### OS Platform +#### Example: OS Platform -Returns a string describing the specific operating system in use. The value is set at compile time. Possible values are 'linux', 'macos', 'ios', 'freebsd', 'dragonfly', 'netbsd', 'openbsd', 'solaris', 'android', 'windows' +`platform` returns a string describing the specific operating system in use. The value is set at compile time. Possible values are `linux`, `macos`, `ios`, `freebsd`, `dragonfly`, `netbsd`, `openbsd`, `solaris`, `android`, `windows`. @@ -117,197 +104,4 @@ println!("Platform: {}", platform); -### OS Family - -Possible values are 'unix', 'windows'. - - - - -```js -import { family } from '@tauri-apps/plugin-os'; - -const family = await family(); -console.log(family); -// Prints "windows" to the console -``` - - - - -```rust -let family = tauri_plugin_os::family(); -println!("Family: {}", family); -//Prints "windows" to the terminal -``` - - - - -### OS Version - -Returns the current operating system version. - - - - -```js -import { version } from '@tauri-apps/plugin-os'; - -const version = await version(); -console.log(version); -// Prints "10.0.19045" to the console -``` - - - - -```rust -let version = tauri_plugin_os::version(); -println!("Version: {}", version); -// Prints "10.0.19045" to the terminal - -``` - - - - -### OS Type - -Returns 'linux' on Linux, 'macos' on macOS, 'windows' on Windows, 'ios' on iOS and 'android' on Android - - - - -```js -import { type } from '@tauri-apps/plugin-os'; - -const type = await type(); -console.log(type); -// Prints "windows" to the console -``` - - - - -```rust -let os_type = tauri_plugin_os::type_(); -println!("Type: {}", os_type); -// Prints "windows" to the terminal - -``` - - - - -### OS Architecture - -Possible values are 'x86', 'x86_64', 'arm', 'aarch64', 'mips', 'mips64', 'powerpc', 'powerpc64', 'riscv64', 's390x', 'sparc64'. - - - - -```js -import { arch } from '@tauri-apps/plugin-os'; - -const arch = await arch(); -console.log(arch); -// Prints "x86_64" to the console -``` - - - - -```rust -let arch = tauri_plugin_os::arch(); -println!("Architecture: {}", arch); -// Prints "x86_64" to the terminal - -``` - - - - -### OS Locale - -Returns a string with a BCP-47 language tag. - - - - -```js -import { locale } from '@tauri-apps/plugin-os'; - -const locale = await locale(); -console.log(locale); -// Prints "en-US" to the console -``` - - - - -```rust -let locale = tauri_plugin_os::locale(); -println!("Locale: {:?}", locale); -// Prints "en-US" to the terminal - -``` - - - - -### OS Executable Extension - -Returns the file extension, if any, used for executable binaries on this platform. Possible values are 'exe' and '' (empty string). - - - - -```js -import { exeExtension } from '@tauri-apps/plugin-os'; - -const exeExtension = await exeExtension(); -console.log(exeExtension); -// Prints "exe" to the console -``` - - - - -```rust -let exe_extension = tauri_plugin_os::exe_extension(); -println!("Exe Extension: {}", exe_extension); -// Prints "exe" to the terminal - -``` - - - - -### OS Hostname - -Returns the host name of the operating system. - - - - -```js -import { hostname } from '@tauri-apps/plugin-os'; - -const hostname = await hostname(); -console.log(hostname); -// Prints the host name to the console -``` - - - - -```rust -let hostname = tauri_plugin_os::hostname(); -println!("Hostname: {}", hostname); -// Prints the host name to the terminal - -``` - - - +See all available functions in the [JavaScript API](/2/reference/js/os/) or [Rust API](https://docs.rs/tauri-plugin-os/2.0.0-alpha.4/tauri_plugin_os/) references. \ No newline at end of file From ec7ae64eae99f700a337a121cc2a268147eae96a Mon Sep 17 00:00:00 2001 From: Vitor Ayres Date: Mon, 6 Nov 2023 14:41:38 -0300 Subject: [PATCH 6/8] move links further up Co-authored-by: Lorenzo Lewis --- src/content/docs/features/os-info.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/features/os-info.mdx b/src/content/docs/features/os-info.mdx index 4f63ca4f34..4dec1fc849 100644 --- a/src/content/docs/features/os-info.mdx +++ b/src/content/docs/features/os-info.mdx @@ -73,7 +73,7 @@ Install the OS Information plugin to get started. ## Usage -With this plugin you can query multiple information from current operational system, here is how you can utilize the OS Information plugin: +With this plugin you can query multiple information from current operational system. See all available functions in the [JavaScript API](/2/reference/js/os/) or [Rust API](https://docs.rs/tauri-plugin-os/2.0.0-alpha.4/tauri_plugin_os/) references. {/* TODO: Link to which language to use, frontend vs. backend guide when it's made */} From b9ae22df21221856c28fb7f342c69a0ddb85c81c Mon Sep 17 00:00:00 2001 From: Vitor Ayres Date: Mon, 6 Nov 2023 14:42:02 -0300 Subject: [PATCH 7/8] move links further up Co-authored-by: Lorenzo Lewis --- src/content/docs/features/os-info.mdx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/content/docs/features/os-info.mdx b/src/content/docs/features/os-info.mdx index 4dec1fc849..eef0bedcf0 100644 --- a/src/content/docs/features/os-info.mdx +++ b/src/content/docs/features/os-info.mdx @@ -103,5 +103,3 @@ println!("Platform: {}", platform); - -See all available functions in the [JavaScript API](/2/reference/js/os/) or [Rust API](https://docs.rs/tauri-plugin-os/2.0.0-alpha.4/tauri_plugin_os/) references. \ No newline at end of file From 343bed62d9cf879e23f0d6a773d254359f05f175 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Mon, 6 Nov 2023 15:14:26 -0300 Subject: [PATCH 8/8] update rust api url --- src/content/docs/features/os-info.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/features/os-info.mdx b/src/content/docs/features/os-info.mdx index eef0bedcf0..58594db502 100644 --- a/src/content/docs/features/os-info.mdx +++ b/src/content/docs/features/os-info.mdx @@ -73,7 +73,7 @@ Install the OS Information plugin to get started. ## Usage -With this plugin you can query multiple information from current operational system. See all available functions in the [JavaScript API](/2/reference/js/os/) or [Rust API](https://docs.rs/tauri-plugin-os/2.0.0-alpha.4/tauri_plugin_os/) references. +With this plugin you can query multiple information from current operational system. See all available functions in the [JavaScript API](/2/reference/js/os/) or [Rust API](https://docs.rs/tauri-plugin-os/) references. {/* TODO: Link to which language to use, frontend vs. backend guide when it's made */}