#tauri-plugin #system-info #plugin-system #retrieving

bin+lib tauri-plugin-system-info

A tauri plugin for retrieving system info

3 unstable releases

0.2.0 Jan 31, 2024
0.1.1 Sep 4, 2023
0.1.0 Aug 16, 2023

#186 in Operating systems

Download history 7/week @ 2024-01-27 7/week @ 2024-02-17 29/week @ 2024-02-24 3/week @ 2024-03-02 5/week @ 2024-03-09 11/week @ 2024-03-16 23/week @ 2024-03-23 38/week @ 2024-03-30 119/week @ 2024-04-06 2/week @ 2024-04-13

182 downloads per month

MIT license

34KB
767 lines

Tauri Plugin system-info

This is a Tauri plugin for reading system information.

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.

Rust Install

cargo add tauri-plugin-system-info 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 = "main" }

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.

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

The exported zod 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.

use tauri_plugin_system_info::utils::{SysInfo, SysInfoState};

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.

Dependencies

~23–65MB
~1M SLoC