https://github.com/rubickCenter/rubick-base

desktop automation, screen capture, input listen/simulation, asar compress, color picker for nodejs and electron based on rust. 基于 Rust / WASM 提供截图、取色、键鼠事件监听模拟、压缩解压、图像处理、获取已安装应用等跨平台功能的现代异步 Nodejs 模块,占用空间小, 安装便捷, 使用简单, 高性能, 资源占用极小, 可取代 iohook 和 robotjs

https://github.com/rubickCenter/rubick-base

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.6%) to scientific vocabulary

Keywords

capture color-picker cross-platform electron grpc nodejs rust shortcuts simulation tool
Last synced: 6 months ago · JSON representation

Repository

desktop automation, screen capture, input listen/simulation, asar compress, color picker for nodejs and electron based on rust. 基于 Rust / WASM 提供截图、取色、键鼠事件监听模拟、压缩解压、图像处理、获取已安装应用等跨平台功能的现代异步 Nodejs 模块,占用空间小, 安装便捷, 使用简单, 高性能, 资源占用极小, 可取代 iohook 和 robotjs

Basic Info
  • Host: GitHub
  • Owner: rubickCenter
  • License: mpl-2.0
  • Language: Rust
  • Default Branch: master
  • Homepage:
  • Size: 4.12 MB
Statistics
  • Stars: 95
  • Watchers: 5
  • Forks: 21
  • Open Issues: 5
  • Releases: 13
Archived
Topics
capture color-picker cross-platform electron grpc nodejs rust shortcuts simulation tool
Created over 4 years ago · Last pushed over 2 years ago
Metadata Files
Readme License

README-EN.md

rubickbase

Based on Rust / WASM, a modern asynchronous Nodejs module that provides cross-platform functions such as screenshots, color picking, keyboard and mouse event monitoring simulation, image processing, and access to installed applications. It occupies a small space, is easy to install, simple to use, high performance, and consumes very little resources. , Can replace iohook and robotjs

Features

Device event listening and simulation

  • [x] Get mouse position
  • [x] Keyboard and mouse event monitoring
  • [x] Keyboard event simulation
  • [x] Mouse event simulation
  • [x] Subscribe to shortcut key events

Image and Screen

  • [x] Screenshot
  • [x] Get mouse pixel color (main screen)
  • [x] Image zoom
  • [x] Picture color selection
  • [x] Picture cropping
  • [x] Multiple screenshots

System info

  • [x] Get the list of installed applications (linux✅/macos✅/windows✅)
  • [x] Get detailed information of installed applications (linux✅)
  • [x] Get system language

Other tools

  • [x] asar package compression and decompression (zstd algorithm)

Install

Unlike iohook and robotjs, you don't need to recompile tediously for different versions, everything works out of the box

Whether you are in node or electron, you can install it directly with your favorite package manager:

```

npm

npm install --save rubickbase

yarn

yarn add rubickbase

pnpm

pnpm add rubickbase ```

Notes rubickbase is based on [N-API](https://nodejs.org/api/n-api.html) v6, so the following versions are recommended for Nodejs environment v10.x ,v12.x ,14.x, 15.x, **16.x** Electron environment recommends the following versions v13.x,v14.x ,**v15.x** ,16.x

Quick start

Introducing dependencies

rubickbase supports both cjs and esm specifications, of course you can and recommend using it in TypeScript

js // cjs const { newRubickBase } = require('rubickbase') // esm / typescript import { newRubickBase } from 'rubickbase'

Basic usage

In this example, you get the rubickbase service instance through newRubickbase, you can get all the functions of rubickbase through getAPI

Here get the current mouse position every second

```js const { newRubickBase } = require('rubickbase')

// init rubickbase const rubickBase = newRubickBase()

setInterval(async () => { // start rubickbase and get APIs const api = await rubickBase.getAPI() // print Cursor Position console.log(api.getCursorPosition()) }, 1000) ```

Optional initialization parameters | Parameter name | Parameter meaning | Type | | --------------- | --------------------------------------------------- | ------------- | | port | Port of the GRPC server | number | | logger | Logger | Logger | | tmpdir | Temporary file directory | string | | workerBoot | Whether to start workers together | boolean | | ioEventCallback | Callback function that listens to all device events | EventCallback |
Advanced startup rubickbase is run by a combination of the GRPC server master and multiple workers that provide different functions Generally speaking, when you call `getAPI`, rubickbase will automatically turn on all services, but if you need to run them in a different place or time, you can manually control their life cycle to achieve more refined control First of all, you need to choose not to start the workers when the master starts. At this time, the master will listen to messages from the workers. ```js // init rubickbase const rubickBase = newRubickBase({ workerBoot: false }) rubickBase.start() ``` Then manually start workers where needed ```js const rubickWorker = newRubickWorker() // start all workers rubickWorker.start() // Start ioio worker separately rubickWorker.start('ioio') ``` Note that the life cycle (existence time) of the worker must be shorter than that of the master, otherwise the GRPC client in the worker will throw an exception that the server cannot be found And if you change the port when starting the master, then pass the port to the worker ```js // init rubickbase const rubickBase = newRubickBase({ port: 8001, workerBoot: false }) rubickBase.start() // then const rubickWorker = newRubickWorker({ port: 8001 }) rubickWorker.start() ```
Use the underlying stateless API directly Allows you to directly call some basic APIs without starting the master and workers ```js const { language, sendEvent, getInstalledApps, screenCapture, screenCaptureAll, screenCaptureAroundPosition, } = await newRubickBase().getBasicAPI() ```

Device input event simulation

It is very simple to simulate mouse and keyboard input events, just call sendEvent

Since rubickbase is written in TypeScript, the editor will automatically prompt when writing Event

```js // This will simulate pressing the F1 key api.sendEvent({ device: 'KeyBoard', action: 'Press', info: 'F1', })

// This will simulate pressing the middle mouse button api.sendEvent({ device: 'Mouse', action: 'Press', info: 'Middle', }) ```

Device input event listening

Create a target event channel through the setEventChannel API, and get the subscriber of the corresponding event

```js // Created here to monitor the left mouse button channel const register = api.setEventChannel({ device: 'Mouse', action: 'Press', info: 'Left', })

// View all currently created event channels console.log(api.allEventChannels())

// Register the printing function through registerHook register('myeventchannel', async (e) => { console.log(e) })

// delete event channel api.delEventChannel('myeventchannel')

console.log(api.hasEventChannel('myeventchannel'), api.allEventChannels()) ```

Retrieve and close channels `allEventChannels` can get all existing event channels `hasEventChannel` can determine whether there is a channel with a certain name `delEventChannel` can delete the created event channel

Event fuzzy matching

A device event has three constraints: device action info, you can remove any of these conditions to complete event fuzzy matching

```js // Match the press event of the left mouse button api.setEventChannel({ device: 'Mouse', action: 'Press', info: 'Left', })

// Match the mouse movement event api.setEventChannel({ device: 'Mouse', action: 'Move', })

// Match the press event of all the mouse buttons api.setEventChannel({ device: 'Mouse', action: 'Press', })

// Match all key press events of all devices api.setEventChannel({ action: 'Press', }) ```

Image Processing

rubickbase is based on the high-performance WASM module of Photon for image processing

  1. Take color Image.colorAt

js const color = img.colorAt({ x: 1, y: 1 })

  1. Resize Image.resize

Input width and height, output scaled image

js const newImg = img.resize(100, 100)

Optional scaling algorithm The default nearest neighbor difference algorithm, the image results of other algorithms have smoother edges, you can choose according to your needs Nearest Neighbor Difference Algorithm = 1, Binary Finding Algorithm = 2, CatmullRom Interpolation Algorithm = 3, Gaussian Algorithm = 4, Interpolation Algorithm = 5 ```js const newImg = img.resize(100, 100, 1) ```
  1. Crop Image.crop

Input the point, width and height of the upper left corner, and output the cropped image

js const newImg = img.crop({ x: 5, y: 5 }, 10, 10)

Features at a glance

Rubickbase also has the following features:

  1. Get the current coordinates of the mouse
    getCursorPosition: () => Position

  2. Get the pixel value of the current coordinates of the mouse
    This API is only available for the home screen
    getCursorPositionPixelColor: () => Promise< Color>

  3. Main screen screenshot
    screenCapture: () => Promise< Image>

  4. All screenshots
    screenCaptureAll: () => Promise< Image[]>

  5. Get the image around the mouse
    This API is only available for the home screen
    screenCaptureAroundPosition: (position: Position, width: number, height: number) => Promise< Image>

  6. Get the list of installed applications in the system
    getInstalledApps: (getDetailInfo: boolean = false, extraDirs?: Array< string >) => Promise< string>

    getDetailInfo Whether to obtain application detailed information. Default no (currently only available on Linux)
    extraDirs additional directories to be scanned
    extraDirs additional directories to be scanned
    extraDirs additional directories to be scanned
    Return a list of shortcut paths in JSON format. If getDetailInfo is true, then return a list of application details

    <details>
    <summary> Application details field explanation</summary>
    

    name: name
    iconpath: list of icons of various sizes
    icon
    path: list of icons of various sizes
    iconpath: list of icons of various sizes
    description: application description
    description: application description
    description: application description
    command: application start command
    command: application start command
    command: application start command
    desktop
    entry_path: shortcut path

    </details>
    
    <details>
    <summary> Scanning principle</summary>
    

    Scan the directory where the system stores the shortcuts to get all the applications installed in the system, including the scan format:

    | Platform | Suffix | | -------- | ------------ | | linux | desktop | | macos | app,prefPane | | windows | lnk |

    </details>
    
  7. Get system language language: () => Promise< string>

  8. asar + zstd compression

    It is a superset of electron's official asar format, and zstd compression algorithm is added when packaging

    asarList(path: string): Promise< Array | undefined>
    asarExtractFile(path: string, dest: string): Promise< undefined>
    asarExtract(path: string, dest: string): Promise< undefined>
    asarPack(path: string, dest: string, level?: number): Promise< undefined>

Contribution and contact

Any kind of contribution and open source collaboration are welcome!

The project depends on the pnpm package manager, you need to install it first

npm install -g pnpm

The project adopts fully automated code inspection and construction, and you can use the following commands to develop

| Action | Command | | ------- | ---------------- | | Install | · pnpm i | | Build | · pnpm build | | Commit | · pnpm commit | | Release | · pnpm release |

After paying attention to the official account, send the contact keyword to add me on WeChat:

wechat

LISENCE

MPLv2

Owner

  • Name: rubickCenter
  • Login: rubickCenter
  • Kind: organization
  • Location: China

rubick  项目核心仓库

GitHub Events

Total
  • Watch event: 2
  • Fork event: 1
Last Year
  • Watch event: 2
  • Fork event: 1

Dependencies

packages/rust-backend/Cargo.lock cargo
  • 188 dependencies
example/package.json npm
  • rubickbase ^0.8.3 development
package.json npm
  • @release-it/bumper ^3.0.1 development
  • @types/estree ^0.0.50 development
  • @types/signale ^1.4.2 development
  • bob-esbuild ^2.0.1 development
  • bob-esbuild-cli ^2.0.0 development
  • esbuild ^0.13.5 development
  • gitmoji-changelog ^2.2.1 development
  • gitmoji-cli ^4.7.0 development
  • prettier ^2.4.1 development
  • release-it ^14.11.6 development
  • rollup-plugin-proto ^1.1.2 development
  • zx ^4.2.0 development
packages/rubickbase/package.json npm
  • protobufjs ^6.11.2 development
  • @grpc/grpc-js ^1.4.1
  • @grpc/proto-loader ^0.6.5
  • @silvia-odwyer/photon-node ^0.3.1
  • consola ^2.15.3
  • fs-extra ^10.0.0
  • mali ^0.45.0
packages/rust-backend/package.json npm
  • zx ^4.2.0 development
.github/workflows/ci.yml actions
  • Swatinem/rust-cache v1 composite
  • actions-rs/toolchain v1 composite
  • actions/cache v2 composite
  • actions/checkout v2 composite
  • actions/setup-node v2 composite
  • egor-tensin/setup-mingw v2 composite
  • pnpm/action-setup v2.0.1 composite
  • taiki-e/create-gh-release-action v1 composite
packages/rust-backend/Cargo.toml cargo
example/pnpm-lock.yaml npm
pnpm-lock.yaml npm
  • 885 dependencies