From 2008b62a45ce4bebd77dd1f79f99ac4732367188 Mon Sep 17 00:00:00 2001 From: muwoo <2424880409@qq.com> Date: Wed, 16 Aug 2023 17:57:25 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=94=AF=E6=8C=81=E6=96=B0API?= =?UTF-8?q?=EF=BC=9AgetCopyFiles=20simulateKeyboardTap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- public/preload.js | 10 +++++++++- src/main/common/api.ts | 18 ++++++++++++++++++ yarn.lock | 5 +++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7761f60..8cf2ab8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubick", - "version": "2.4.1", + "version": "2.4.2", "author": "muwoo <2424880409@qq.com>", "private": true, "scripts": { @@ -30,6 +30,7 @@ "get-mac-apps": "^1.0.2", "got": "^11.8.3", "lodash.throttle": "^4.1.1", + "node-key-sender": "^1.0.11", "pouchdb": "^7.2.2", "vue": "^3.0.0", "vue-router": "^4.0.0-0", diff --git a/public/preload.js b/public/preload.js index 894c784..96ac19d 100644 --- a/public/preload.js +++ b/public/preload.js @@ -162,8 +162,16 @@ window.rubick = { shellBeep: () => { ipcSend('shellBeep'); }, - + getFileIcon: (path) => { return ipcSendSync('getFileIcon', { path }); }, + + getCopyedFiles: () => { + return ipcSendSync('getCopyFiles'); + }, + + simulateKeyboardTap: (key, ...modifier) => { + ipcSend('simulateKeyboardTap', { key, modifier }); + }, }; diff --git a/src/main/common/api.ts b/src/main/common/api.ts index 4efc1ed..5ed9f7e 100644 --- a/src/main/common/api.ts +++ b/src/main/common/api.ts @@ -13,7 +13,11 @@ import { runner, detach } from '../browsers'; import fs from 'fs'; import { LocalDb, screenCapture } from '@/core'; import plist from 'plist'; +import ks from 'node-key-sender'; + import { DECODE_KEY } from '@/common/constans/main'; +import getCopyFiles from '@/common/utils/getCopyFiles'; + import mainInstance from '../index'; const runnerInstance = runner(); const detachInstance = detach(); @@ -324,6 +328,20 @@ class API { }); }); } + + public getCopyFiles() { + return getCopyFiles(); + } + + public simulateKeyboardTap({ data: { key, modifier } }) { + let keys = [key.toLowerCase()]; + if (modifier && Array.isArray(modifier) && modifier.length > 0) { + keys = modifier.concat(keys); + ks.sendCombination(keys); + } else { + ks.sendKeys(keys); + } + } } export default new API(); diff --git a/yarn.lock b/yarn.lock index 7e1ee82..8f5816f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8070,6 +8070,11 @@ node-gyp-build@~4.1.0: resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.1.1.tgz#d7270b5d86717068d114cc57fff352f96d745feb" integrity sha512-dSq1xmcPDKPZ2EED2S6zw/b9NKsqzXRE6dVr8TVQnI3FJOTteUMuqF3Qqs6LZg+mLGYJWqQzMbIjMtJqTv87nQ== +node-key-sender@^1.0.11: + version "1.0.11" + resolved "https://registry.npmmirror.com/node-key-sender/-/node-key-sender-1.0.11.tgz#93210f07163607d8daf2874f1a29567d0acdb94c" + integrity sha512-vv2IXd8QdZBFYXaIy02uy2rK6EKj+tOTEuoTxJKS9l8zw8Cz6DeLffR8ompj7N2A3h6XK7aiy+YAcTaeOqwp2Q== + node-libs-browser@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/node-libs-browser/-/node-libs-browser-2.2.1.tgz#b64f513d18338625f90346d27b0d235e631f6425"