mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-09-24 13:03:30 +08:00
win自动化分类新增监控剪贴板和文件夹,支持等待剪贴板变化和文件夹变化,并返回变化内容
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
const window = require("./window");
|
||||
const message = require("./message");
|
||||
const automation = require("./automation");
|
||||
const monitor = require("./monitor");
|
||||
|
||||
module.exports = {
|
||||
window,
|
||||
message,
|
||||
automation,
|
||||
monitor,
|
||||
};
|
||||
|
48
plugin/lib/quickcomposer/windows/monitor.js
Normal file
48
plugin/lib/quickcomposer/windows/monitor.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
// 读取 monitor.cs 模板
|
||||
const monitorTemplate = fs.readFileSync(
|
||||
path.join(__dirname, "..", "..", "csharp", "monitor.cs"),
|
||||
"utf8"
|
||||
);
|
||||
|
||||
// 监控剪贴板变化
|
||||
const watchClipboard = async function () {
|
||||
const args = ["-type", "clipboard", "-once"];
|
||||
const result = await quickcommand.runCsharp(monitorTemplate, args);
|
||||
if (result && result.startsWith("Error:")) {
|
||||
throw new Error(result.substring(7));
|
||||
}
|
||||
return JSON.parse(result);
|
||||
};
|
||||
|
||||
// 监控文件系统变化
|
||||
const watchFileSystem = async function (watchPath, options = {}) {
|
||||
const { filter = "*.*", recursive = true } = options;
|
||||
|
||||
if (!watchPath) {
|
||||
throw new Error("必须指定监控路径");
|
||||
}
|
||||
|
||||
const args = ["-type", "filesystem", "-path", watchPath, "-once"];
|
||||
|
||||
if (filter !== "*.*") {
|
||||
args.push("-filter", filter);
|
||||
}
|
||||
|
||||
if (!recursive) {
|
||||
args.push("-recursive", "false");
|
||||
}
|
||||
|
||||
const result = await quickcommand.runCsharp(monitorTemplate, args);
|
||||
if (result && result.startsWith("Error:")) {
|
||||
throw new Error(result.substring(7));
|
||||
}
|
||||
return JSON.parse(result);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
watchClipboard,
|
||||
watchFileSystem,
|
||||
};
|
Reference in New Issue
Block a user