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-api-adapter

v0.3.13

Published

![NPM Version](https://img.shields.io/npm/v/tauri-api-adapter) [![Generate and Deploy Docs](https://github.com/HuakunShen/tauri-api-adapter/actions/workflows/docs.yml/badge.svg)](https://github.com/HuakunShen/tauri-api-adapter/actions/workflows/docs.yml)

Downloads

3,017

Readme

tauri-api-adapter

NPM Version Generate and Deploy Docs CI

Documentation: https://huakunshen.github.io/tauri-api-adapter/

Regular Tauri APIs allow communication between Rust and JavaScript, so system APIs can be called from JavaScript.

This package provides a way to call Tauri APIs from iframe and web worker.

Potential use cases:

  1. Use Tauri APIs within iframe
  2. Use Tauri APIs within web worker
  3. Build extension with iframe and web worker

Usage

Server

Within Regular Webview (have access to Tauri APIs)

I call it server because it serves the API, execute the requests and return the result.

import { IframeParentIO, RPCChannel, WorkerParentIO } from 'kkrpc/browser'
import type { AllPermission } from 'tauri-api-adapter/permissions'

const permissions: AllPermission[] = [
  'clipboard:read-all',
  'fetch:all',
  'dialog:all',
  'fs:read',
  'fs:write',
  'notification:all',
  'os:all',
  'shell:execute',
  'shell:open',
  'updownload:download',
  'updownload:upload',
  'system-info:all',
  'network:port',
  'network:interface'
]
const serverAPI = constructServerAPIWithPermissions(permissions)

const io = new IframeParentIO(iframe.contentWindow)
const rpc = new RPCChannel(io, { expose: serverAPI })

// Or expose to worker
const worker = new Worker('worker.js')
const io = new WorkerParentIO(worker)
const rpc = new RPCChannel(io, {
  expose: serverAPI
})

Client

Within iframe or web worker (no access to native Tauri APIs)

I call it client because it calls the API.

import { clipboard, defaultClientAPI, network, sysInfo } from 'tauri-api-adapter/iframe'
import { clipboard, defaultClientAPI, network, sysInfo } from 'tauri-api-adapter/worker'

console.log('Clipboard Text: ', await clipboard.readText())
console.log(await sysInfo.cpuInfo())
console.log(await network.getNonEmptyInterfaces())

Permission Control

Permission control is provided by the package to limit API access from iframe and web worker.

Tauri 2 comes with a nice and strict permission control system for Tauri Plugins. However it doesn't allow dynamic permission control. Permissions for each window is hard coded during compilation.

In cases where you want to dynamically load content with iframe or web worker, this library gives you the ability to control the permission of each iframe and web worker.

To limit the API access, you need to construct the API object manually.

In the main window, you can construct the API object like this:

The API constructors takes in a list of permission strings. The type can be found in the src/permission. You can also find the type in the documentation.

With clipboard:read-text set, the clipboard API in iframe and worker will only have access to the readText, readHtml, readRtf functions. The image reading related functions will not be available.

Extend API

This library provides a list of predefined APIs (which I personally use in my projects).

  • clipboard
  • dialog
  • notification
  • shell
  • network
  • system info
  • os
  • file system
  • event

This doesn't mean you can only use the provided APIs.

You can extend the functionalities by adding more APIs.

To add support for a new API, add a file to src/api/server/ and src/api/client/ (may not be necessary).

Add the API type to src/api/client/types.

Implement the type in server and client.

Also look at src/iframe.ts and src/worker.ts to see how the API is exposed to iframe and worker.