Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create OS Information guide #1484 #1642

Merged
merged 8 commits into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 96 additions & 4 deletions src/content/docs/features/os-info.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,103 @@ 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';

<PluginLinks plugin="os" />

<Stub>
Based on https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/os
</Stub>
Read information about the operating system using the OS Information plugin.

## Setup

Install the OS Information plugin to get started.

<Tabs>
<TabItem label="Automatic">

1. Use your project's package manager to add the dependency:

<CommandTabs npm="npm run tauri add os"
yarn="yarn run tauri add os"
pnpm="pnpm tauri add os"
cargo="cargo tauri add os" />

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");
}
```

</TabItem>
<TabItem label="Manual">

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:

<CommandTabs
npm="npm install @tauri-apps/plugin-os"
yarn="yarn add @tauri-apps/plugin-os"
pnpm="pnpm add @tauri-apps/plugin-os"
/>

</TabItem>

</Tabs>

## 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/) references.

{/* TODO: Link to which language to use, frontend vs. backend guide when it's made */}

#### Example: OS Platform

`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`.

<Tabs>
<TabItem label="JavaScript">

```js
import { platform } from '@tauri-apps/plugin-os';

const platform = await platform();
console.log(platform);
// Prints "windows" to the console
```

</TabItem>
<TabItem label="Rust">

```rust
let platform = tauri_plugin_os::platform();
println!("Platform: {}", platform);
// Prints "windows" to the terminal
```

</TabItem>
</Tabs>