Skip to main content
Home

Built and signed on GitHub Actions

This package works with BrowsersIt is unknown whether this package works with Node.js, Deno, Bun
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Bun
This package works with Browsers
JSR Score
35%
Published
9 months ago (2.0.10)

Tauri Plugin system-info

TypeScript Documentation: https://huakunshen.github.io/tauri-plugin-system-info Rust Documentation: https://docs.rs/crate/tauri-plugin-system-info

This is a Tauri plugin for reading system information.

Demo App

Installation

If you are installing from npm and crates.io package registry, make sure the versions for both packages are the same, otherwise, the API may not match.

For Tauri v1 app, use version 1.x, for Tauri v2 app, use version 2.x. (this applies to both npm and crates.io packages)

Rust Install

cargo add tauri-plugin-system-info within src-tauri to add the package.

Or add the following to your Cargo.toml for the latest unpublished version (not recommanded).

tauri-plugin-system-info = { git = "https://github.com/HuakunShen/tauri-plugin-system-info", branch = "v1" } # use v2 branch for Tauri v2 plugin

NPM Install

Run the following to install JavaScript/TypeScript API package.

npm i tauri-plugin-system-info-api
# npm add https://github.com/HuakunShen/tauri-plugin-system-info # or this for latest unpublished version (not recommended)

In main.rs, add the following to your tauri::Builder:

fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_system_info::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Info Supported

  • CPU
  • Network
  • Process
  • Memory
  • Hostname
  • Kernel Version
  • OS Version
  • Battery

Third Party Libraries Used

API

TypeScript

All TypeScript APIs can be found in api.ts.

Return type of each API is added. The object structures can be found in type.ts.

Valibot was used to define type schema and infer TypeScript types. You can import the types exported from the npm package.

The exported Valibot schemas can be used to parse data and make sure the data returned from rust APIs match the desired structure defined in schema.

import {
  allSysInfo,
  memoryInfo,
  staticInfo,
  cpuInfo,
  AllSystemInfo,
  StaticInfo,
  MemoryInfo,
  CpuInfo,
  batteries,
  Batteries,
} from "tauri-plugin-system-info-api";

console.log(AllSystemInfo.parse(await allSysInfo()));
console.log(MemoryInfo.parse(await memoryInfo()));
console.log(StaticInfo.parse(await staticInfo()));
console.log(CpuInfo.parse(await cpuInfo()));
console.log(Batteries.parse(await batteries()));

Rust

The API functions in Rust are all exported, so that you can also build your own commands.

Here is a simple example:

use tauri_plugin_system_info::utils::{SysInfo, SysInfoState};
use tauri_plugin_system_info::commands;
use tauri_plugin_system_info::model::Cpu;

#[tauri::command]
fn cpu_count() -> Result<usize, String> {
    let state = SysInfoState::default();
    let sysinfo = state.sysinfo.lock().unwrap();
    let cpu_count = sysinfo.cpu_count();
    Ok(cpu_count)
}

See https://docs.rs/crate/tauri-plugin-system-info/ for full rust documentation.

SysInfo is the API struct that can be used to access all information. It's like a wrapper for sysinfo APIs and other crates. The reason for doing this is, some structs in third party libraries cannot be cloned or serialized, and thus cannot be sent to the frontend.

I aggregate all the APIs, do structure conversion and serilization with custom code.

Usage

See SvelteKit Example for an example written with SvelteKit.

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@hk/tauri-plugin-system-info-api

Import symbol

import * as tauri_plugin_system_info_api from "@hk/tauri-plugin-system-info-api";
or

Import directly with a jsr specifier

import * as tauri_plugin_system_info_api from "jsr:@hk/tauri-plugin-system-info-api";

Add Package

pnpm i jsr:@hk/tauri-plugin-system-info-api
or (using pnpm 10.8 or older)
pnpm dlx jsr add @hk/tauri-plugin-system-info-api

Import symbol

import * as tauri_plugin_system_info_api from "@hk/tauri-plugin-system-info-api";

Add Package

yarn add jsr:@hk/tauri-plugin-system-info-api
or (using Yarn 4.8 or older)
yarn dlx jsr add @hk/tauri-plugin-system-info-api

Import symbol

import * as tauri_plugin_system_info_api from "@hk/tauri-plugin-system-info-api";

Add Package

vlt install jsr:@hk/tauri-plugin-system-info-api

Import symbol

import * as tauri_plugin_system_info_api from "@hk/tauri-plugin-system-info-api";

Add Package

npx jsr add @hk/tauri-plugin-system-info-api

Import symbol

import * as tauri_plugin_system_info_api from "@hk/tauri-plugin-system-info-api";

Add Package

bunx jsr add @hk/tauri-plugin-system-info-api

Import symbol

import * as tauri_plugin_system_info_api from "@hk/tauri-plugin-system-info-api";