♻️ 代码重构

This commit is contained in:
muwoo
2021-12-06 18:23:34 +08:00
parent cd41f0561c
commit 1353c440aa
29 changed files with 295 additions and 13562 deletions

View File

@@ -1,13 +1,46 @@
const {remote} = require("electron");
console.log(remote)
const {ipcRenderer} = require("electron");
const ipcSendSync = (type, data) => {
const returnValue = ipcRenderer.sendSync("msg-trigger", {
type,
data,
});
if (returnValue instanceof Error) throw returnValue;
return returnValue;
};
window.rubick = {
getLocalPlugins() {
return remote.getGlobal("LOCAL_PLUGINS").getLocalPlugins();
hooks: {},
// 事件
onPluginEnter(cb) {
console.log(window.rubick.hooks)
typeof cb === "function" && (window.rubick.hooks.onPluginEnter = cb);
},
downloadPlugin(plugin) {
return remote.getGlobal("LOCAL_PLUGINS").downloadPlugin(plugin);
onPluginReady(cb) {
typeof cb === "function" && (window.rubick.hooks.onPluginReady = cb);
},
deletePlugin(plugin) {
return remote.getGlobal("LOCAL_PLUGINS").deletePlugin(plugin);
onPluginOut(cb) {
typeof cb === "function" && (window.rubick.hooks.onPluginOut = cb);
},
// 窗口交互
hideMainWindow() {
ipcSendSync("hideMainWindow");
},
showMainWindow() {
ipcSendSync("showMainWindow");
},
showOpenDialog(options) {
ipcSendSync("showOpenDialog", options);
},
setExpendHeight(height) {
ipcSendSync("setExpendHeight", height);
},
setSubInput(onChange, placeholder = "", isFocus) {
typeof cb === "function" && (window.rubick.hooks.onSubInputChange = onChange);
ipcSendSync("setSubInput", {
placeholder,
isFocus,
});
},
};