mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-28 16:42:47 +08:00
Merge pull request #160 from rubickCenter/fix/apiclass
🐛 fix apiclass & add some feature
This commit is contained in:
commit
9f21823792
@ -3,6 +3,9 @@ import path from "path";
|
|||||||
|
|
||||||
const appPath = app.getPath("cache");
|
const appPath = app.getPath("cache");
|
||||||
|
|
||||||
|
console.log(appPath);
|
||||||
|
|
||||||
|
|
||||||
const PLUGIN_INSTALL_DIR = path.join(appPath, "./rubick-plugins");
|
const PLUGIN_INSTALL_DIR = path.join(appPath, "./rubick-plugins");
|
||||||
|
|
||||||
const DECODE_KEY = {
|
const DECODE_KEY = {
|
||||||
|
@ -3,7 +3,7 @@ import fs from "fs";
|
|||||||
import getLocalDataFile from "./getLocalDataFile";
|
import getLocalDataFile from "./getLocalDataFile";
|
||||||
import { PluginHandler } from "@/core";
|
import { PluginHandler } from "@/core";
|
||||||
import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/main";
|
import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/main";
|
||||||
import { API } from "@/main/common/api";
|
import API from "@/main/common/api";
|
||||||
|
|
||||||
const configPath = path.join(getLocalDataFile(), "./rubick-local-plugin.json");
|
const configPath = path.join(getLocalDataFile(), "./rubick-local-plugin.json");
|
||||||
|
|
||||||
@ -16,12 +16,12 @@ let pluginInstance;
|
|||||||
console.log(registry);
|
console.log(registry);
|
||||||
pluginInstance = new PluginHandler({
|
pluginInstance = new PluginHandler({
|
||||||
baseDir,
|
baseDir,
|
||||||
registry,
|
registry
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
pluginInstance = new PluginHandler({
|
pluginInstance = new PluginHandler({
|
||||||
baseDir,
|
baseDir,
|
||||||
registry,
|
registry
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
@ -38,7 +38,7 @@ global.LOCAL_PLUGINS = {
|
|||||||
);
|
);
|
||||||
plugin = {
|
plugin = {
|
||||||
...plugin,
|
...plugin,
|
||||||
...pluginInfo,
|
...pluginInfo
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
global.LOCAL_PLUGINS.addPlugin(plugin);
|
global.LOCAL_PLUGINS.addPlugin(plugin);
|
||||||
@ -52,12 +52,12 @@ global.LOCAL_PLUGINS = {
|
|||||||
);
|
);
|
||||||
plugin = {
|
plugin = {
|
||||||
...plugin,
|
...plugin,
|
||||||
...pluginInfo,
|
...pluginInfo
|
||||||
};
|
};
|
||||||
// 刷新
|
// 刷新
|
||||||
let currentPlugins = global.LOCAL_PLUGINS.getLocalPlugins();
|
let currentPlugins = global.LOCAL_PLUGINS.getLocalPlugins();
|
||||||
|
|
||||||
currentPlugins = currentPlugins.map((p) => {
|
currentPlugins = currentPlugins.map(p => {
|
||||||
if (p.name === plugin.name) {
|
if (p.name === plugin.name) {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ global.LOCAL_PLUGINS = {
|
|||||||
addPlugin(plugin) {
|
addPlugin(plugin) {
|
||||||
let has = false;
|
let has = false;
|
||||||
const currentPlugins = global.LOCAL_PLUGINS.getLocalPlugins();
|
const currentPlugins = global.LOCAL_PLUGINS.getLocalPlugins();
|
||||||
currentPlugins.some((p) => {
|
currentPlugins.some(p => {
|
||||||
has = p.name === plugin.name;
|
has = p.name === plugin.name;
|
||||||
return has;
|
return has;
|
||||||
});
|
});
|
||||||
@ -96,22 +96,20 @@ global.LOCAL_PLUGINS = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
updatePlugin(plugin) {
|
updatePlugin(plugin) {
|
||||||
global.LOCAL_PLUGINS.PLUGINS = global.LOCAL_PLUGINS.PLUGINS.map(
|
global.LOCAL_PLUGINS.PLUGINS = global.LOCAL_PLUGINS.PLUGINS.map(origin => {
|
||||||
(origin) => {
|
if (origin.name === plugin.name) {
|
||||||
if (origin.name === plugin.name) {
|
return plugin;
|
||||||
return plugin;
|
|
||||||
}
|
|
||||||
return origin;
|
|
||||||
}
|
}
|
||||||
);
|
return origin;
|
||||||
|
});
|
||||||
fs.writeFileSync(configPath, JSON.stringify(global.LOCAL_PLUGINS.PLUGINS));
|
fs.writeFileSync(configPath, JSON.stringify(global.LOCAL_PLUGINS.PLUGINS));
|
||||||
},
|
},
|
||||||
async deletePlugin(plugin) {
|
async deletePlugin(plugin) {
|
||||||
await pluginInstance.uninstall([plugin.name], { isDev: plugin.isDev });
|
await pluginInstance.uninstall([plugin.name], { isDev: plugin.isDev });
|
||||||
global.LOCAL_PLUGINS.PLUGINS = global.LOCAL_PLUGINS.PLUGINS.filter(
|
global.LOCAL_PLUGINS.PLUGINS = global.LOCAL_PLUGINS.PLUGINS.filter(
|
||||||
(p) => plugin.name !== p.name
|
p => plugin.name !== p.name
|
||||||
);
|
);
|
||||||
fs.writeFileSync(configPath, JSON.stringify(global.LOCAL_PLUGINS.PLUGINS));
|
fs.writeFileSync(configPath, JSON.stringify(global.LOCAL_PLUGINS.PLUGINS));
|
||||||
return global.LOCAL_PLUGINS.PLUGINS;
|
return global.LOCAL_PLUGINS.PLUGINS;
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { app, BrowserWindow, protocol } from "electron";
|
import { app, BrowserWindow, protocol } from "electron";
|
||||||
|
import path from "path";
|
||||||
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
|
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
|
||||||
export default () => {
|
export default () => {
|
||||||
let win: any;
|
let win: any;
|
||||||
@ -24,7 +25,8 @@ export default () => {
|
|||||||
contextIsolation: false,
|
contextIsolation: false,
|
||||||
webviewTag: true,
|
webviewTag: true,
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
},
|
preload: path.join(__static, "preload.js")
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
||||||
// Load the url of the dev server if in development mode
|
// Load the url of the dev server if in development mode
|
||||||
@ -42,6 +44,19 @@ export default () => {
|
|||||||
win = undefined;
|
win = undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
win.on("show", () => {
|
||||||
|
win.webContents.executeJavaScript(
|
||||||
|
`window.rubick && window.rubick.hooks && typeof window.rubick.hooks.onShow === "function" && window.rubick.hooks.onShow()`
|
||||||
|
);
|
||||||
|
// win.webContents.openDevTools();
|
||||||
|
});
|
||||||
|
|
||||||
|
win.on("hide", () => {
|
||||||
|
win.webContents.executeJavaScript(
|
||||||
|
`window.rubick && window.rubick.hooks && typeof window.rubick.hooks.onHide === "function" && window.rubick.hooks.onHide()`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// 判断失焦是否隐藏
|
// 判断失焦是否隐藏
|
||||||
win.on("blur", () => {
|
win.on("blur", () => {
|
||||||
const config = { ...global.OP_CONFIG.get() };
|
const config = { ...global.OP_CONFIG.get() };
|
||||||
@ -55,6 +70,6 @@ export default () => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
init,
|
init,
|
||||||
getWindow,
|
getWindow
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -6,7 +6,7 @@ import {
|
|||||||
Notification,
|
Notification,
|
||||||
nativeImage,
|
nativeImage,
|
||||||
clipboard,
|
clipboard,
|
||||||
shell,
|
shell
|
||||||
} from "electron";
|
} from "electron";
|
||||||
import { runner, detach } from "../browsers";
|
import { runner, detach } from "../browsers";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
@ -21,145 +21,155 @@ const dbInstance = new LocalDb(app.getPath("userData"));
|
|||||||
dbInstance.init();
|
dbInstance.init();
|
||||||
|
|
||||||
class API {
|
class API {
|
||||||
static currentPlugin: null | any = null;
|
public currentPlugin: null | any = null;
|
||||||
static DBKEY = "RUBICK_DB_DEFAULT";
|
private DBKEY = "RUBICK_DB_DEFAULT";
|
||||||
|
|
||||||
static getCurrentWindow = (window, e) => {
|
init(mainWindow: BrowserWindow) {
|
||||||
|
// 响应 preload.js 事件
|
||||||
|
ipcMain.on("msg-trigger", async (event, arg) => {
|
||||||
|
const window = arg.winId ? BrowserWindow.fromId(arg.winId) : mainWindow;
|
||||||
|
const data = await this[arg.type](arg, window, event);
|
||||||
|
event.returnValue = data;
|
||||||
|
// event.sender.send(`msg-back-${arg.type}`, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public getCurrentWindow = (window, e) => {
|
||||||
let originWindow = BrowserWindow.fromWebContents(e.sender);
|
let originWindow = BrowserWindow.fromWebContents(e.sender);
|
||||||
if (originWindow !== window) originWindow = detachInstance.getWindow();
|
if (originWindow !== window) originWindow = detachInstance.getWindow();
|
||||||
return originWindow;
|
return originWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
static __EscapeKeyDown = (event, input, window) => {
|
public __EscapeKeyDown = (event, input, window) => {
|
||||||
if (input.type !== "keyDown") return;
|
if (input.type !== "keyDown") return;
|
||||||
if (!(input.meta || input.control || input.shift || input.alt)) {
|
if (!(input.meta || input.control || input.shift || input.alt)) {
|
||||||
if (input.key === "Escape") {
|
if (input.key === "Escape") {
|
||||||
API.removePlugin(null, window);
|
this.removePlugin(null, window);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static loadPlugin({ data: plugin }, window) {
|
public loadPlugin({ data: plugin }, window) {
|
||||||
window.webContents.executeJavaScript(
|
window.webContents.executeJavaScript(
|
||||||
`window.loadPlugin(${JSON.stringify(plugin)})`
|
`window.loadPlugin(${JSON.stringify(plugin)})`
|
||||||
);
|
);
|
||||||
API.openPlugin({ data: plugin }, window);
|
this.openPlugin({ data: plugin }, window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static openPlugin({ data: plugin }, window) {
|
public openPlugin({ data: plugin }, window) {
|
||||||
if (API.currentPlugin && API.currentPlugin.name === plugin.name) return;
|
if (this.currentPlugin && this.currentPlugin.name === plugin.name) return;
|
||||||
window.setSize(window.getSize()[0], 60);
|
window.setSize(window.getSize()[0], 60);
|
||||||
runnerInstance.removeView(window);
|
runnerInstance.removeView(window);
|
||||||
runnerInstance.init(plugin, window);
|
runnerInstance.init(plugin, window);
|
||||||
API.currentPlugin = plugin;
|
this.currentPlugin = plugin;
|
||||||
window.webContents.executeJavaScript(
|
window.webContents.executeJavaScript(
|
||||||
`window.setCurrentPlugin(${JSON.stringify({
|
`window.setCurrentPlugin(${JSON.stringify({
|
||||||
currentPlugin: API.currentPlugin,
|
currentPlugin: this.currentPlugin
|
||||||
})})`
|
})})`
|
||||||
);
|
);
|
||||||
window.show();
|
window.show();
|
||||||
// 按 ESC 退出插件
|
// 按 ESC 退出插件
|
||||||
window.webContents.on("before-input-event", (event, input) =>
|
window.webContents.on("before-input-event", (event, input) =>
|
||||||
API.__EscapeKeyDown(event, input, window)
|
this.__EscapeKeyDown(event, input, window)
|
||||||
);
|
);
|
||||||
runnerInstance
|
runnerInstance
|
||||||
.getView()
|
.getView()
|
||||||
.webContents.on("before-input-event", (event, input) =>
|
.webContents.on("before-input-event", (event, input) =>
|
||||||
API.__EscapeKeyDown(event, input, window)
|
this.__EscapeKeyDown(event, input, window)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static removePlugin(e, window) {
|
public removePlugin(e, window) {
|
||||||
API.currentPlugin = null;
|
this.currentPlugin = null;
|
||||||
runnerInstance.removeView(window);
|
runnerInstance.removeView(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static openPluginDevTools() {
|
public openPluginDevTools() {
|
||||||
runnerInstance.getView().webContents.openDevTools({ mode: "detach" });
|
runnerInstance.getView().webContents.openDevTools({ mode: "detach" });
|
||||||
}
|
}
|
||||||
|
|
||||||
static hideMainWindow(arg, window) {
|
public hideMainWindow(arg, window) {
|
||||||
window.hide();
|
window.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
static showMainWindow(arg, window) {
|
public showMainWindow(arg, window) {
|
||||||
window.show();
|
window.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
static showOpenDialog({ data }, window) {
|
public showOpenDialog({ data }, window) {
|
||||||
dialog.showOpenDialogSync(window, data);
|
dialog.showOpenDialogSync(window, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static setExpendHeight({ data: height }, window: BrowserWindow, e) {
|
public setExpendHeight({ data: height }, window: BrowserWindow, e) {
|
||||||
const originWindow = API.getCurrentWindow(window, e);
|
const originWindow = this.getCurrentWindow(window, e);
|
||||||
if (!originWindow) return;
|
if (!originWindow) return;
|
||||||
const targetHeight = height;
|
const targetHeight = height;
|
||||||
originWindow.setSize(originWindow.getSize()[0], targetHeight);
|
originWindow.setSize(originWindow.getSize()[0], targetHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
static setSubInput({ data }, window, e) {
|
public setSubInput({ data }, window, e) {
|
||||||
const originWindow = API.getCurrentWindow(window, e);
|
const originWindow = this.getCurrentWindow(window, e);
|
||||||
if (!originWindow) return;
|
if (!originWindow) return;
|
||||||
originWindow.webContents.executeJavaScript(
|
originWindow.webContents.executeJavaScript(
|
||||||
`window.setSubInput(${JSON.stringify({
|
`window.setSubInput(${JSON.stringify({
|
||||||
placeholder: data.placeholder,
|
placeholder: data.placeholder
|
||||||
})})`
|
})})`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static subInputBlur() {
|
public subInputBlur() {
|
||||||
runnerInstance.getView().webContents.focus();
|
runnerInstance.getView().webContents.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
static sendSubInputChangeEvent({ data }) {
|
public sendSubInputChangeEvent({ data }) {
|
||||||
runnerInstance.executeHooks("SubInputChange", data);
|
runnerInstance.executeHooks("SubInputChange", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static removeSubInput(data, window, e) {
|
public removeSubInput(data, window, e) {
|
||||||
const originWindow = API.getCurrentWindow(window, e);
|
const originWindow = this.getCurrentWindow(window, e);
|
||||||
if (!originWindow) return;
|
if (!originWindow) return;
|
||||||
originWindow.webContents.executeJavaScript(`window.removeSubInput()`);
|
originWindow.webContents.executeJavaScript(`window.removeSubInput()`);
|
||||||
}
|
}
|
||||||
|
|
||||||
static setSubInputValue({ data }, window, e) {
|
public setSubInputValue({ data }, window, e) {
|
||||||
const originWindow = API.getCurrentWindow(window, e);
|
const originWindow = this.getCurrentWindow(window, e);
|
||||||
if (!originWindow) return;
|
if (!originWindow) return;
|
||||||
originWindow.webContents.executeJavaScript(
|
originWindow.webContents.executeJavaScript(
|
||||||
`window.setSubInputValue(${JSON.stringify({
|
`window.setSubInputValue(${JSON.stringify({
|
||||||
value: data.text,
|
value: data.text
|
||||||
})})`
|
})})`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getPath({ data }) {
|
public getPath({ data }) {
|
||||||
return app.getPath(data.name);
|
return app.getPath(data.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static showNotification({ data: { body } }) {
|
public showNotification({ data: { body } }) {
|
||||||
if (!Notification.isSupported()) return;
|
if (!Notification.isSupported()) return;
|
||||||
"string" != typeof body && (body = String(body));
|
"string" != typeof body && (body = String(body));
|
||||||
const plugin = API.currentPlugin;
|
const plugin = this.currentPlugin;
|
||||||
if (!plugin) return;
|
if (!plugin) return;
|
||||||
const notify = new Notification({
|
const notify = new Notification({
|
||||||
title: plugin.pluginName,
|
title: plugin.pluginName,
|
||||||
body,
|
body,
|
||||||
icon: plugin.logo,
|
icon: plugin.logo
|
||||||
});
|
});
|
||||||
notify.show();
|
notify.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
static copyImage = ({ data }) => {
|
public copyImage = ({ data }) => {
|
||||||
const image = nativeImage.createFromDataURL(data.img);
|
const image = nativeImage.createFromDataURL(data.img);
|
||||||
clipboard.writeImage(image);
|
clipboard.writeImage(image);
|
||||||
};
|
};
|
||||||
|
|
||||||
static copyText({ data }) {
|
public copyText({ data }) {
|
||||||
clipboard.writeText(String(data.text));
|
clipboard.writeText(String(data.text));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static copyFile({ data }) {
|
public copyFile({ data }) {
|
||||||
if (data.file && fs.existsSync(data.file)) {
|
if (data.file && fs.existsSync(data.file)) {
|
||||||
clipboard.writeBuffer(
|
clipboard.writeBuffer(
|
||||||
"NSFilenamesPboardType",
|
"NSFilenamesPboardType",
|
||||||
@ -170,134 +180,126 @@ class API {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dbPut({ data }) {
|
public dbPut({ data }) {
|
||||||
return dbInstance.put(API.DBKEY, data.data);
|
return dbInstance.put(this.DBKEY, data.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static dbGet({ data }) {
|
public dbGet({ data }) {
|
||||||
return dbInstance.get(API.DBKEY, data.id);
|
return dbInstance.get(this.DBKEY, data.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static dbRemove({ data }) {
|
public dbRemove({ data }) {
|
||||||
return dbInstance.remove(API.DBKEY, data.doc);
|
return dbInstance.remove(this.DBKEY, data.doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static dbBulkDocs({ data }) {
|
public dbBulkDocs({ data }) {
|
||||||
return dbInstance.bulkDocs(API.DBKEY, data.docs);
|
return dbInstance.bulkDocs(this.DBKEY, data.docs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static dbAllDocs({ data }) {
|
public dbAllDocs({ data }) {
|
||||||
return dbInstance.allDocs(API.DBKEY, data.key);
|
return dbInstance.allDocs(this.DBKEY, data.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getFeatures() {
|
public getFeatures() {
|
||||||
return API.currentPlugin.features;
|
return this.currentPlugin.features;
|
||||||
}
|
}
|
||||||
|
|
||||||
static setFeature({ data }, window) {
|
public setFeature({ data }, window) {
|
||||||
API.currentPlugin = {
|
this.currentPlugin = {
|
||||||
...API.currentPlugin,
|
...this.currentPlugin,
|
||||||
features: (() => {
|
features: (() => {
|
||||||
let has = false;
|
let has = false;
|
||||||
API.currentPlugin.features.some((feature) => {
|
this.currentPlugin.features.some(feature => {
|
||||||
has = feature.code === data.feature.code;
|
has = feature.code === data.feature.code;
|
||||||
return has;
|
return has;
|
||||||
});
|
});
|
||||||
if (!has) {
|
if (!has) {
|
||||||
return [...API.currentPlugin.features, data.feature];
|
return [...this.currentPlugin.features, data.feature];
|
||||||
}
|
}
|
||||||
return API.currentPlugin.features;
|
return this.currentPlugin.features;
|
||||||
})(),
|
})()
|
||||||
};
|
};
|
||||||
window.webContents.executeJavaScript(
|
window.webContents.executeJavaScript(
|
||||||
`window.updatePlugin(${JSON.stringify({
|
`window.updatePlugin(${JSON.stringify({
|
||||||
currentPlugin: API.currentPlugin,
|
currentPlugin: this.currentPlugin
|
||||||
})})`
|
})})`
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static removeFeature({ data }, window) {
|
public removeFeature({ data }, window) {
|
||||||
API.currentPlugin = {
|
this.currentPlugin = {
|
||||||
...API.currentPlugin,
|
...this.currentPlugin,
|
||||||
features: API.currentPlugin.features.filter((feature) => {
|
features: this.currentPlugin.features.filter(feature => {
|
||||||
if (data.code.type) {
|
if (data.code.type) {
|
||||||
return feature.code.type !== data.code.type;
|
return feature.code.type !== data.code.type;
|
||||||
}
|
}
|
||||||
return feature.code !== data.code;
|
return feature.code !== data.code;
|
||||||
}),
|
})
|
||||||
};
|
};
|
||||||
window.webContents.executeJavaScript(
|
window.webContents.executeJavaScript(
|
||||||
`window.updatePlugin(${JSON.stringify({
|
`window.updatePlugin(${JSON.stringify({
|
||||||
currentPlugin: API.currentPlugin,
|
currentPlugin: this.currentPlugin
|
||||||
})})`
|
})})`
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static sendPluginSomeKeyDownEvent({ data: { modifiers, keyCode } }) {
|
public sendPluginSomeKeyDownEvent({ data: { modifiers, keyCode } }) {
|
||||||
const code = DECODE_KEY[keyCode];
|
const code = DECODE_KEY[keyCode];
|
||||||
if (!code || !runnerInstance.getView()) return;
|
if (!code || !runnerInstance.getView()) return;
|
||||||
if (modifiers.length > 0) {
|
if (modifiers.length > 0) {
|
||||||
runnerInstance.getView().webContents.sendInputEvent({
|
runnerInstance.getView().webContents.sendInputEvent({
|
||||||
type: "keyDown",
|
type: "keyDown",
|
||||||
modifiers,
|
modifiers,
|
||||||
keyCode: code,
|
keyCode: code
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
runnerInstance.getView().webContents.sendInputEvent({
|
runnerInstance.getView().webContents.sendInputEvent({
|
||||||
type: "keyDown",
|
type: "keyDown",
|
||||||
keyCode: code,
|
keyCode: code
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static detachPlugin(e, window) {
|
public detachPlugin(e, window) {
|
||||||
if (!API.currentPlugin) return;
|
if (!this.currentPlugin) return;
|
||||||
const view = window.getBrowserView();
|
const view = window.getBrowserView();
|
||||||
window.setBrowserView(null);
|
window.setBrowserView(null);
|
||||||
window.webContents
|
window.webContents
|
||||||
.executeJavaScript(`window.getMainInputInfo()`)
|
.executeJavaScript(`window.getMainInputInfo()`)
|
||||||
.then((res) => {
|
.then(res => {
|
||||||
detachInstance.init(
|
detachInstance.init(
|
||||||
{
|
{
|
||||||
...API.currentPlugin,
|
...this.currentPlugin,
|
||||||
subInput: res,
|
subInput: res
|
||||||
},
|
},
|
||||||
window.getBounds(),
|
window.getBounds(),
|
||||||
view
|
view
|
||||||
);
|
);
|
||||||
window.webContents.executeJavaScript(`window.initRubick()`);
|
window.webContents.executeJavaScript(`window.initRubick()`);
|
||||||
window.setSize(window.getSize()[0], 60);
|
window.setSize(window.getSize()[0], 60);
|
||||||
API.currentPlugin = null;
|
this.currentPlugin = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static detachInputChange({ data }) {
|
public detachInputChange({ data }) {
|
||||||
API.sendSubInputChangeEvent({ data });
|
this.sendSubInputChangeEvent({ data });
|
||||||
}
|
}
|
||||||
|
|
||||||
static getLocalId() {
|
public getLocalId() {
|
||||||
return encodeURIComponent(app.getPath("home"));
|
return encodeURIComponent(app.getPath("home"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static shellShowItemInFolder({ data }) {
|
public shellShowItemInFolder({ data }) {
|
||||||
shell.showItemInFolder(data.path);
|
shell.showItemInFolder(data.path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static shellBeep() {
|
public shellBeep() {
|
||||||
shell.beep();
|
shell.beep();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (mainWindow: BrowserWindow) => {
|
export default new API();
|
||||||
// 响应 preload.js 事件
|
|
||||||
ipcMain.on("msg-trigger", async (event, arg) => {
|
|
||||||
const window = arg.winId ? BrowserWindow.fromId(arg.winId) : mainWindow;
|
|
||||||
const data = await API[arg.type](arg, window, event);
|
|
||||||
event.returnValue = data;
|
|
||||||
// event.sender.send(`msg-back-${arg.type}`, data);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
@ -3,7 +3,7 @@ import electron, {
|
|||||||
app,
|
app,
|
||||||
globalShortcut,
|
globalShortcut,
|
||||||
protocol,
|
protocol,
|
||||||
BrowserWindow,
|
BrowserWindow
|
||||||
} from "electron";
|
} from "electron";
|
||||||
import { main } from "./browsers";
|
import { main } from "./browsers";
|
||||||
import commonConst from "../common/utils/commonConst";
|
import commonConst from "../common/utils/commonConst";
|
||||||
@ -24,7 +24,7 @@ class App {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
protocol.registerSchemesAsPrivileged([
|
protocol.registerSchemesAsPrivileged([
|
||||||
{ scheme: "app", privileges: { secure: true, standard: true } },
|
{ scheme: "app", privileges: { secure: true, standard: true } }
|
||||||
]);
|
]);
|
||||||
this.windowCreator = main();
|
this.windowCreator = main();
|
||||||
const gotTheLock = app.requestSingleInstanceLock();
|
const gotTheLock = app.requestSingleInstanceLock();
|
||||||
@ -59,8 +59,8 @@ class App {
|
|||||||
onReady() {
|
onReady() {
|
||||||
const readyFunction = () => {
|
const readyFunction = () => {
|
||||||
this.createWindow();
|
this.createWindow();
|
||||||
API(this.windowCreator.getWindow());
|
const mainWindow = this.windowCreator.getWindow();
|
||||||
// this.init()
|
API.init(mainWindow);
|
||||||
createTray(this.windowCreator.getWindow());
|
createTray(this.windowCreator.getWindow());
|
||||||
registerHotKey(this.windowCreator.getWindow());
|
registerHotKey(this.windowCreator.getWindow());
|
||||||
this.systemPlugins.triggerReadyHooks(
|
this.systemPlugins.triggerReadyHooks(
|
||||||
@ -108,7 +108,7 @@ class App {
|
|||||||
|
|
||||||
if (commonConst.dev()) {
|
if (commonConst.dev()) {
|
||||||
if (process.platform === "win32") {
|
if (process.platform === "win32") {
|
||||||
process.on("message", (data) => {
|
process.on("message", data => {
|
||||||
if (data === "graceful-exit") {
|
if (data === "graceful-exit") {
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
:clipboardFile="clipboardFile || []"
|
:clipboardFile="clipboardFile || []"
|
||||||
@choosePlugin="choosePlugin"
|
@choosePlugin="choosePlugin"
|
||||||
@focus="searchFocus"
|
@focus="searchFocus"
|
||||||
|
@clear-search-value="clearSearchValue"
|
||||||
@clearClipbord="clearClipboardFile"
|
@clearClipbord="clearClipboardFile"
|
||||||
@readClipboardContent="readClipboardContent"
|
@readClipboardContent="readClipboardContent"
|
||||||
/>
|
/>
|
||||||
@ -56,8 +57,9 @@ const {
|
|||||||
pluginLoading,
|
pluginLoading,
|
||||||
searchFocus,
|
searchFocus,
|
||||||
clipboardFile,
|
clipboardFile,
|
||||||
|
setSearchValue,
|
||||||
clearClipboardFile,
|
clearClipboardFile,
|
||||||
readClipboardContent,
|
readClipboardContent
|
||||||
} = createPluginManager();
|
} = createPluginManager();
|
||||||
|
|
||||||
initPlugins();
|
initPlugins();
|
||||||
@ -68,8 +70,8 @@ const menuPluginInfo = ref({});
|
|||||||
getPluginInfo({
|
getPluginInfo({
|
||||||
pluginName: "feature",
|
pluginName: "feature",
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
pluginPath: `${__static}/feature/package.json`,
|
pluginPath: `${__static}/feature/package.json`
|
||||||
}).then((res) => {
|
}).then(res => {
|
||||||
menuPluginInfo.value = res;
|
menuPluginInfo.value = res;
|
||||||
remote.getGlobal("LOCAL_PLUGINS").addPlugin(res);
|
remote.getGlobal("LOCAL_PLUGINS").addPlugin(res);
|
||||||
});
|
});
|
||||||
@ -80,12 +82,12 @@ watch([options], () => {
|
|||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
ipcRenderer.sendSync("msg-trigger", {
|
ipcRenderer.sendSync("msg-trigger", {
|
||||||
type: "setExpendHeight",
|
type: "setExpendHeight",
|
||||||
data: getWindowHeight(options.value),
|
data: getWindowHeight(options.value)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const changeIndex = (index) => {
|
const changeIndex = index => {
|
||||||
if (!options.value.length) return;
|
if (!options.value.length) return;
|
||||||
if (
|
if (
|
||||||
currentSelect.value + index > options.value.length - 1 ||
|
currentSelect.value + index > options.value.length - 1 ||
|
||||||
@ -99,7 +101,7 @@ const openMenu = () => {
|
|||||||
openPlugin({
|
openPlugin({
|
||||||
...toRaw(menuPluginInfo.value),
|
...toRaw(menuPluginInfo.value),
|
||||||
feature: menuPluginInfo.value.features[0],
|
feature: menuPluginInfo.value.features[0],
|
||||||
cmd: "插件市场",
|
cmd: "插件市场"
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -107,6 +109,10 @@ const choosePlugin = () => {
|
|||||||
const currentChoose = options.value[currentSelect.value];
|
const currentChoose = options.value[currentSelect.value];
|
||||||
currentChoose.click();
|
currentChoose.click();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const clearSearchValue = () => {
|
||||||
|
setSearchValue("");
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
|
@ -15,15 +15,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<a-input
|
<a-input
|
||||||
id="search"
|
id="search"
|
||||||
|
ref="mainInput"
|
||||||
class="main-input"
|
class="main-input"
|
||||||
@input="(e) => changeValue(e)"
|
@input="e => changeValue(e)"
|
||||||
@keydown.down="(e) => keydownEvent(e, 'down')"
|
@keydown.down="e => keydownEvent(e, 'down')"
|
||||||
@keydown.up="(e) => keydownEvent(e, 'up')"
|
@keydown.up="e => keydownEvent(e, 'up')"
|
||||||
@keydown="(e) => checkNeedInit(e)"
|
@keydown="e => checkNeedInit(e)"
|
||||||
:value="searchValue"
|
:value="searchValue"
|
||||||
:placeholder="placeholder || 'Hi, Rubick2'"
|
:placeholder="placeholder || 'Hi, Rubick2'"
|
||||||
@keypress.enter="(e) => keydownEvent(e, 'enter')"
|
@keypress.enter="e => keydownEvent(e, 'enter')"
|
||||||
@keypress.space="(e) => keydownEvent(e, 'space')"
|
@keypress.space="e => keydownEvent(e, 'space')"
|
||||||
@focus="emit('focus')"
|
@focus="emit('focus')"
|
||||||
>
|
>
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
@ -53,7 +54,6 @@
|
|||||||
import { defineProps, defineEmits, ref, computed } from "vue";
|
import { defineProps, defineEmits, ref, computed } from "vue";
|
||||||
import { ipcRenderer, remote } from "electron";
|
import { ipcRenderer, remote } from "electron";
|
||||||
import { LoadingOutlined, MoreOutlined } from "@ant-design/icons-vue";
|
import { LoadingOutlined, MoreOutlined } from "@ant-design/icons-vue";
|
||||||
|
|
||||||
const opConfig = remote.getGlobal("OP_CONFIG");
|
const opConfig = remote.getGlobal("OP_CONFIG");
|
||||||
const { Menu } = remote;
|
const { Menu } = remote;
|
||||||
|
|
||||||
@ -62,18 +62,18 @@ const config = ref(opConfig.get());
|
|||||||
const props: any = defineProps({
|
const props: any = defineProps({
|
||||||
searchValue: {
|
searchValue: {
|
||||||
type: [String, Number],
|
type: [String, Number],
|
||||||
default: "",
|
default: ""
|
||||||
},
|
},
|
||||||
placeholder: {
|
placeholder: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "",
|
default: ""
|
||||||
},
|
},
|
||||||
currentPlugin: {},
|
currentPlugin: {},
|
||||||
pluginLoading: Boolean,
|
pluginLoading: Boolean,
|
||||||
clipboardFile: (() => [])(),
|
clipboardFile: (() => [])()
|
||||||
});
|
});
|
||||||
|
|
||||||
const changeValue = (e) => {
|
const changeValue = e => {
|
||||||
if (props.currentPlugin.name === "rubick-system-feature") return;
|
if (props.currentPlugin.name === "rubick-system-feature") return;
|
||||||
targetSearch({ value: e.target.value });
|
targetSearch({ value: e.target.value });
|
||||||
emit("onSearch", e);
|
emit("onSearch", e);
|
||||||
@ -86,7 +86,8 @@ const emit = defineEmits([
|
|||||||
"changeSelect",
|
"changeSelect",
|
||||||
"choosePlugin",
|
"choosePlugin",
|
||||||
"focus",
|
"focus",
|
||||||
"readClipboardContent",
|
"clearSearchValue",
|
||||||
|
"readClipboardContent"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const keydownEvent = (e, key: string) => {
|
const keydownEvent = (e, key: string) => {
|
||||||
@ -100,8 +101,8 @@ const keydownEvent = (e, key: string) => {
|
|||||||
type: "sendPluginSomeKeyDownEvent",
|
type: "sendPluginSomeKeyDownEvent",
|
||||||
data: {
|
data: {
|
||||||
keyCode: e.code,
|
keyCode: e.code,
|
||||||
modifiers,
|
modifiers
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
const runPluginDisable = e.target.value === "" || props.currentPlugin.name;
|
const runPluginDisable = e.target.value === "" || props.currentPlugin.name;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
@ -124,7 +125,7 @@ const keydownEvent = (e, key: string) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkNeedInit = (e) => {
|
const checkNeedInit = e => {
|
||||||
const { ctrlKey, metaKey } = e;
|
const { ctrlKey, metaKey } = e;
|
||||||
|
|
||||||
if (e.target.value === "" && e.keyCode === 8) {
|
if (e.target.value === "" && e.keyCode === 8) {
|
||||||
@ -140,7 +141,7 @@ const targetSearch = ({ value }) => {
|
|||||||
if (props.currentPlugin.name) {
|
if (props.currentPlugin.name) {
|
||||||
return ipcRenderer.sendSync("msg-trigger", {
|
return ipcRenderer.sendSync("msg-trigger", {
|
||||||
type: "sendSubInputChangeEvent",
|
type: "sendSubInputChangeEvent",
|
||||||
data: { text: value },
|
data: { text: value }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -149,7 +150,7 @@ const closeTag = () => {
|
|||||||
emit("changeSelect", {});
|
emit("changeSelect", {});
|
||||||
emit("clearClipbord");
|
emit("clearClipbord");
|
||||||
ipcRenderer.send("msg-trigger", {
|
ipcRenderer.send("msg-trigger", {
|
||||||
type: "removePlugin",
|
type: "removePlugin"
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -157,8 +158,8 @@ const showSeparate = () => {
|
|||||||
let pluginMenu: any = [
|
let pluginMenu: any = [
|
||||||
{
|
{
|
||||||
label: config.value.perf.common.hideOnBlur ? "钉住" : "自动隐藏",
|
label: config.value.perf.common.hideOnBlur ? "钉住" : "自动隐藏",
|
||||||
click: changeHideOnBlur,
|
click: changeHideOnBlur
|
||||||
},
|
}
|
||||||
];
|
];
|
||||||
if (props.currentPlugin && props.currentPlugin.logo) {
|
if (props.currentPlugin && props.currentPlugin.logo) {
|
||||||
pluginMenu = pluginMenu.concat([
|
pluginMenu = pluginMenu.concat([
|
||||||
@ -167,23 +168,23 @@ const showSeparate = () => {
|
|||||||
click: () => {
|
click: () => {
|
||||||
ipcRenderer.send("msg-trigger", { type: "openPluginDevTools" });
|
ipcRenderer.send("msg-trigger", { type: "openPluginDevTools" });
|
||||||
// todo
|
// todo
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "当前插件信息",
|
label: "当前插件信息",
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: "简介",
|
label: "简介"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "功能",
|
label: "功能"
|
||||||
},
|
}
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "分离窗口",
|
label: "分离窗口",
|
||||||
click: newWindow,
|
click: newWindow
|
||||||
},
|
}
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
let menu = Menu.buildFromTemplate(pluginMenu);
|
let menu = Menu.buildFromTemplate(pluginMenu);
|
||||||
@ -206,10 +207,19 @@ const getIcon = () => {
|
|||||||
|
|
||||||
const newWindow = () => {
|
const newWindow = () => {
|
||||||
ipcRenderer.send("msg-trigger", {
|
ipcRenderer.send("msg-trigger", {
|
||||||
type: "detachPlugin",
|
type: "detachPlugin"
|
||||||
});
|
});
|
||||||
// todo
|
// todo
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mainInput = ref(null);
|
||||||
|
window.rubick.hooks.onShow = () => {
|
||||||
|
(mainInput.value as unknown as HTMLDivElement).focus();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.rubick.hooks.onHide = () => {
|
||||||
|
emit("clearSearchValue");
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
|
@ -135,6 +135,7 @@ const createPluginManager = (): any => {
|
|||||||
searchValue,
|
searchValue,
|
||||||
placeholder,
|
placeholder,
|
||||||
searchFocus,
|
searchFocus,
|
||||||
|
setSearchValue,
|
||||||
clipboardFile,
|
clipboardFile,
|
||||||
clearClipboardFile,
|
clearClipboardFile,
|
||||||
readClipboardContent,
|
readClipboardContent,
|
||||||
|
1
src/renderer/shims-vue.d.ts
vendored
1
src/renderer/shims-vue.d.ts
vendored
@ -14,6 +14,7 @@ declare const __static: string;
|
|||||||
declare module "lodash.throttle";
|
declare module "lodash.throttle";
|
||||||
|
|
||||||
interface Window {
|
interface Window {
|
||||||
|
rubick: any;
|
||||||
setSubInput: ({ placeholder }: { placeholder: string }) => void;
|
setSubInput: ({ placeholder }: { placeholder: string }) => void;
|
||||||
setSubInputValue: ({ value }: { value: string }) => void;
|
setSubInputValue: ({ value }: { value: string }) => void;
|
||||||
removeSubInput: () => void;
|
removeSubInput: () => void;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user