mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-12-15 07:05:21 +08:00
preload分割
This commit is contained in:
47
plugin/lib/getUtoolsPlugins.js
Normal file
47
plugin/lib/getUtoolsPlugins.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const os = require("os");
|
||||
const _ = require("lodash");
|
||||
|
||||
const pluginInfo = () => {
|
||||
return JSON.parse(fs.readFileSync(path.join(__dirname, "plugin.json")));
|
||||
};
|
||||
|
||||
const getUtoolsPlugins = () => {
|
||||
let root = window.utools.isMacOs()
|
||||
? path.join(os.homedir(), "Library/Application Support/uTools/plugins/")
|
||||
: window.utools.isWindows()
|
||||
? path.join(os.homedir(), "AppData/Roaming/uTools/plugins")
|
||||
: path.join(os.homedir(), ".config/uTools/plugins");
|
||||
let plugins = {};
|
||||
let files = fs.readdirSync(root);
|
||||
let deleted = path.join(root, "deleted");
|
||||
let deletedList = fs.existsSync(deleted)
|
||||
? fs.readFileSync(path.join(root, "deleted"), "utf8").split("|")
|
||||
: [];
|
||||
files.forEach((file) => {
|
||||
if (/[a-zA-Z0-9\-]+\.asar$/.test(file) && !deletedList.includes(file)) {
|
||||
let pluginInfo = JSON.parse(
|
||||
fs.readFileSync(path.join(root, file, "plugin.json"))
|
||||
);
|
||||
pluginInfo.logoPath = path.join(root, file, pluginInfo.logo);
|
||||
let keyWordFeatures = [];
|
||||
pluginInfo.features.forEach((f) => {
|
||||
f.cmds.some((c) => {
|
||||
c.length && keyWordFeatures.push(c);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
if (!_.isEmpty(keyWordFeatures)) {
|
||||
pluginInfo["keyWordFeatures"] = keyWordFeatures;
|
||||
plugins[pluginInfo.pluginName] = pluginInfo;
|
||||
}
|
||||
}
|
||||
});
|
||||
return plugins;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
pluginInfo,
|
||||
getUtoolsPlugins,
|
||||
};
|
||||
Reference in New Issue
Block a user