From e7da2d3a26ab3fdd493bf2e06b72e97b45031643 Mon Sep 17 00:00:00 2001 From: fofolee Date: Fri, 10 Jan 2025 22:35:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E6=8E=92=E8=A1=A5=E5=85=A8uTools?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E9=80=89=E4=B8=AD=E6=96=87=E4=BB=B6=E3=80=81=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E3=80=81=E6=96=87=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/lib/quickcomposer.js | 1 + .../lib/quickcomposer/status/getSelected.js | 115 ++++++++++++++++++ plugin/lib/quickcomposer/status/index.js | 7 ++ src/js/composer/commands/index.js | 2 + src/js/composer/commands/statusCommands.js | 51 ++++++++ src/js/composer/commands/systemCommands.js | 94 ++++++++++++++ src/js/composer/commands/utoolsCommand.js | 14 +++ 7 files changed, 284 insertions(+) create mode 100644 plugin/lib/quickcomposer/status/getSelected.js create mode 100644 plugin/lib/quickcomposer/status/index.js create mode 100644 src/js/composer/commands/statusCommands.js diff --git a/plugin/lib/quickcomposer.js b/plugin/lib/quickcomposer.js index edd9f0b..c3ab1b2 100644 --- a/plugin/lib/quickcomposer.js +++ b/plugin/lib/quickcomposer.js @@ -9,6 +9,7 @@ const quickcomposer = { audio: require("./quickcomposer/audio"), image: require("./quickcomposer/image"), windows: require("./quickcomposer/windows"), + status: require("./quickcomposer/status"), }; module.exports = quickcomposer; diff --git a/plugin/lib/quickcomposer/status/getSelected.js b/plugin/lib/quickcomposer/status/getSelected.js new file mode 100644 index 0000000..3344633 --- /dev/null +++ b/plugin/lib/quickcomposer/status/getSelected.js @@ -0,0 +1,115 @@ +const { clipboard } = require("electron"); + +/** + * 获取当前选中的文本 + * @returns {Promise} 选中的文本内容 + */ +function text() { + window.utools.hideMainWindow(); + // 保存当前剪贴板内容 + const originalText = clipboard.readText(); + + // 模拟 Ctrl+C/Command+C 复制操作 + if (process.platform === "darwin") { + utools.simulateKeyboardTap("c", "command"); + } else { + utools.simulateKeyboardTap("c", "control"); + } + + // 等待一小段时间确保复制完成 + return new Promise((resolve) => { + setTimeout(() => { + // 获取选中的文本 + const selectedText = clipboard.readText(); + + // 恢复原始剪贴板内容 + clipboard.writeText(originalText); + + resolve(selectedText); + }, 100); + }); +} + +/** + * 获取当前选中的图片 + * @returns {Promise} 选中的图片的base64数据 + */ +function image() { + window.utools.hideMainWindow(); + // 保存当前剪贴板内容 + const originalImage = clipboard.readImage(); + + // 模拟 Ctrl+C/Command+C 复制操作 + if (process.platform === "darwin") { + utools.simulateKeyboardTap("c", "command"); + } else { + utools.simulateKeyboardTap("c", "control"); + } + + return new Promise((resolve, reject) => { + setTimeout(() => { + try { + // 获取剪贴板中的图片 + const image = clipboard.readImage(); + + if (image.isEmpty()) { + // 恢复原始剪贴板内容 + if (!originalImage.isEmpty()) { + clipboard.writeImage(originalImage); + } + resolve(null); + return; + } + + // 将图片转换为 base64 + const base64 = image.toDataURL(); + + // 恢复原始剪贴板内容 + if (!originalImage.isEmpty()) { + clipboard.writeImage(originalImage); + } + + resolve(base64); + } catch (error) { + reject(error); + } + }, 100); + }); +} + +/** + * 获取当前选中的文件 + * @returns {Promise} 选中的文件路径数组 + */ +function files() { + window.utools.hideMainWindow(); + // 保存当前剪贴板内容 + const originalFiles = utools.getCopyedFiles(); + + // 模拟 Ctrl+C/Command+C 复制操作 + if (process.platform === "darwin") { + utools.simulateKeyboardTap("c", "command"); + } else { + utools.simulateKeyboardTap("c", "control"); + } + + return new Promise((resolve) => { + setTimeout(() => { + // 获取选中的文件 + const selectedFiles = utools.getCopyedFiles(); + + // 恢复原始剪贴板内容 + if (originalFiles && originalFiles.length > 0) { + utools.copyFile(originalFiles); + } + + resolve(selectedFiles || []); + }, 100); + }); +} + +module.exports = { + text, + image, + files, +}; diff --git a/plugin/lib/quickcomposer/status/index.js b/plugin/lib/quickcomposer/status/index.js new file mode 100644 index 0000000..d4509ea --- /dev/null +++ b/plugin/lib/quickcomposer/status/index.js @@ -0,0 +1,7 @@ +const getSelected = require("./getSelected"); + +module.exports = { + getSelectedText: getSelected.text, + getSelectedImage: getSelected.image, + getSelectedFiles: getSelected.files, +}; diff --git a/src/js/composer/commands/index.js b/src/js/composer/commands/index.js index 4d6329b..571c9b6 100644 --- a/src/js/composer/commands/index.js +++ b/src/js/composer/commands/index.js @@ -15,11 +15,13 @@ import { screenCommands } from "./screenCommands"; import { audioCommands } from "./audioCommands"; import { imageCommands } from "./imageCommands"; import { windowsCommands } from "./windowsCommands"; +import { statusCommands } from "./statusCommands"; let commands = [ fileCommands, networkCommands, systemCommands, + statusCommands, audioCommands, imageCommands, notifyCommands, diff --git a/src/js/composer/commands/statusCommands.js b/src/js/composer/commands/statusCommands.js new file mode 100644 index 0000000..3d29599 --- /dev/null +++ b/src/js/composer/commands/statusCommands.js @@ -0,0 +1,51 @@ +export const statusCommands = { + label: "获取状态", + icon: "task", + commands: [ + { + value: "utools.readCurrentFolderPath", + label: "获取当前文件管理器路径", + desc: "获取当前文件管理器窗口路径", + icon: "folder", + isAsync: true, + outputVariable: "currentFolderPath", + saveOutput: true, + }, + { + value: "utools.readCurrentBrowserUrl", + label: "获取当前浏览器地址", + desc: "获取当前浏览器窗口URL", + icon: "language", + isAsync: true, + outputVariable: "currentBrowserUrl", + saveOutput: true, + }, + { + value: "quickcomposer.status.getSelectedText", + label: "获取选中文本", + desc: "获取选中的文本", + icon: "text_fields", + isAsync: true, + outputVariable: "selectedText", + saveOutput: true, + }, + { + value: "quickcomposer.status.getSelectedImage", + label: "获取选中的图片", + desc: "获取选中的图片", + icon: "image", + isAsync: true, + outputVariable: "selectedImage", + saveOutput: true, + }, + { + value: "quickcomposer.status.getSelectedFiles", + label: "获取选中的文件", + desc: "获取选中的文件", + icon: "file_present", + isAsync: true, + outputVariable: "selectedFiles", + saveOutput: true, + }, + ], +}; diff --git a/src/js/composer/commands/systemCommands.js b/src/js/composer/commands/systemCommands.js index 5f5b609..20a778e 100644 --- a/src/js/composer/commands/systemCommands.js +++ b/src/js/composer/commands/systemCommands.js @@ -113,6 +113,100 @@ export const systemCommands = { icon: "terminal", isAsync: true, }, + { + value: "utools.getPath", + label: "获取系统路径", + desc: "获取系统路径", + outputVariable: "systemPath", + saveOutput: true, + defaultValue: "home", + config: [ + { + label: "路径类型", + component: "ButtonGroup", + options: [ + { + label: "用户主目录", + value: "home", + }, + { + label: "应用数据目录", + value: "appData", + }, + { + label: "用户数据目录", + value: "userData", + }, + { + label: "缓存目录", + value: "cache", + }, + { + label: "临时目录", + value: "temp", + }, + { + label: "桌面", + value: "desktop", + }, + { + label: "文档", + value: "documents", + }, + { + label: "下载", + value: "downloads", + }, + { + label: "音乐", + value: "music", + }, + { + label: "图片", + value: "pictures", + }, + { + label: "视频", + value: "videos", + }, + { + label: "uTools日志目录", + value: "logs", + }, + { + label: "uTools程序目录", + value: "exe", + }, + { + label: "uTools模块目录", + value: "module", + }, + ], + }, + ], + }, + { + value: "utools.isMacOS", + label: "判断系统类型", + desc: "判断系统类型", + subCommands: [ + { + value: "utools.isMacOS", + label: "是否Mac", + icon: "computer", + }, + { + value: "utools.isWindows", + label: "是否Windows", + icon: "computer", + }, + { + value: "utools.isLinux", + label: "是否Linux", + icon: "computer", + }, + ], + }, { value: "quickcomposer.system.os.arch", label: "系统信息", diff --git a/src/js/composer/commands/utoolsCommand.js b/src/js/composer/commands/utoolsCommand.js index 4e0c6c0..1dfd12a 100644 --- a/src/js/composer/commands/utoolsCommand.js +++ b/src/js/composer/commands/utoolsCommand.js @@ -183,5 +183,19 @@ export const utoolsCommands = { outputVariable: "windowType", saveOutput: true, }, + { + value: "utools.getNativeId", + label: "获取本地ID", + desc: "获取本地ID", + outputVariable: "nativeId", + saveOutput: true, + }, + { + value: "utools.getAppVersion", + label: "获取uTools版本", + desc: "获取uTools版本", + outputVariable: "appVersion", + saveOutput: true, + }, ], };