npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tauri-plugin-system-info-api

v2.0.8

Published

System Info Plugin for Tauri Apps

Downloads

3,561

Readme

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.

  • Rust Crate: https://crates.io/crates/tauri-plugin-system-info
  • TypeScript API: https://www.npmjs.com/package/tauri-plugin-system-info-api

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

  • [x] CPU
  • [x] Network
  • [x] Process
  • [x] Memory
  • [x] Hostname
  • [x] Kernel Version
  • [x] OS Version
  • [x] 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.