Skip to content

Commit

Permalink
feat: create OS Information guide #1484 (#1642)
Browse files Browse the repository at this point in the history
* first stub

* add notes

* remove rust context

* fix: broken anchor

* simplify guide

* move links further up

Co-authored-by: Lorenzo Lewis <[email protected]>

* move links further up

Co-authored-by: Lorenzo Lewis <[email protected]>

* update rust api url

---------

Co-authored-by: Lorenzo Lewis <[email protected]>
  • Loading branch information
vasfvitor and lorenzolewis authored Nov 6, 2023
1 parent 515f9aa commit 21f5e0e
Showing 1 changed file with 96 additions and 4 deletions.
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>

0 comments on commit 21f5e0e

Please sign in to comment.