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

rubick-native

v0.0.16-beta

Published

封装常用跨平台能力

Downloads

29

Readme

Rubick Native

封装常用跨平台能力

// 安装
pnpm add rubick-native

贡献

  1. Fork & Clone 本项目
  2. 贡献 Rust 部分: 进入 addon 文件下, 基于 napi 教程进行开发; 使用 pnpm build 命令打包生成 npm 包
  3. 贡献 JavaScript 部分: 在根目录下进行开发, 通过 import { func } from "../addon" 调用 Rust 函数
  4. 提起 PR

API

1. Keyborad & Mouse ✅

  1. mouseClick: 鼠标点击
  2. mouseDown: 鼠标按下
  3. mouseUp: 鼠标抬起
  4. mouseLocaion: 获取鼠标位置
出参 eg
{ x: 485, y: 449 }
  1. mouseMove: 鼠标移动
  2. mouseScrollX: 鼠标滚轮左右滑动(正值向右,负值向左)
  3. mouseScrollY: 鼠标滚轮上下滑动(正值向下,负值向上)
  4. sendKeyboardSimulation: 模拟键盘输入
入参 eg
// - 为按下, - 为抬起;所有可用键 https://github.com/enigo-rs/enigo/blob/master/src/keycodes.rs
 {+CTRL}a{-CTRL}{+SHIFT}Hello World{-SHIFT}
  1. onInputEvent: 键鼠事件监听
入参 eg
(event: MouseKeyBoardEvent) => void;
  • callback: function 监听输入事件的函数
event object eg
{
  "time": { "secs_since_epoch": 1695999163, "nanos_since_epoch": 631148700 }, // 触发时间
  "name": "a", // 输入内容
  "event": { 
    "type":"KeyPress", // 事件类型
    "value": "KeyA" // 事件值
  } 
}
  1. grabInputEvent 键鼠事件监听&拦截

比 onInputEvent 多了拦截键鼠事件的功能,但是在 MacOS 下需要被授予 Accessibility 权限此 API 才能工作,故无拦截需求建议使用 onInputEvent

入参 eg
(event: MouseKeyBoardEvent) => boolean;
  • callback: function 监听输入事件的函数, 返回是否将事件发送给系统

2. Clipboard ✅

可以获取剪贴板中复制的内容:

getClipboardContent()

出参 eg
// type: file
{
  type: 'file',
  content: [
    'C:/Download/test.txt',
    'C:/Download/mywork',
  ]
}
// type: text
{
  type: 'text',
  content: 'hello world'
}
  • type: 'file' | 'text'
  • content: Array | string

3. 获取系统已安装的 app 🕑(Mac/Linux 未支持)

原理:解析系统中所有存放快捷方式的文件夹,解析快捷方式生成应用列表(win)

getSystemApp()

获取系统安装的 APP 列表

入参 eg
  • callback: (app: App) => void | Promise 用于接收应用信息的回调函数
  • extraPath: string 额外需要检索的文件夹

App object:

{
  "name": "TIM",
  "description": null,
  "execPath": "C:\\Program Files (x86)\\Tencent\\TIM\\Bin\\QQScLauncher.exe",
  "shortCutPath": "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\腾讯软件\\TIM\\TIM.lnk",
  "workingDir": "C:\\Program Files (x86)\\Tencent\\TIM\\Bin"
}
  • name: 应用的名称
  • description: 应用详情
  • execPath: 应用的路径
  • shortCutPath: 应用快捷方式地址
  • workingDir: 应用工作目录

getAppIcon()

获取 APP 的图标

入参 eg
  • path: string windows 平台下填写 exe 文件地址;
出参 eg
  • img: string 图标的 base64 编码

4. 获取当前活跃窗口 ✅

  1. getActiveWin: 获取当前活跃窗口
  2. getOpenWin: 获取所有打开的窗口信息
出参 eg
{
  "id": 13200, // 进程 pid
  "os": "win32", // 运行平台
  "title": "test.ts - rubick-native - Visual Studio Code", // 窗口标题
  "position": { "x": -7, "y": -7, "width": 1550, "height": 830 }, // 窗口位置大小
  "info": {
    "processId": 13200, // 进程 pid
    "path": "C:\\Program Files\\Microsoft VS Code\\Code.exe", // 进程地址
    "name": "Visual Studio Code", // 进程名称
    "execName": "Code" // 进程名称
  },
  "usage": { "memory": 111030272 }, // 进程内存占用
  "url": "" // 进程关联 URL
}

5. 获取 finder(macos) 或者 explorer(win) 文件夹当前打开的路径 🕑(Linux 未支持)

  1. getFolderOpenPath
出参 eg
"C://Download/mywork";
  • path: string 返回打开的文件夹路径