mirror of
https://github.com/rubickCenter/rubick
synced 2025-11-19 08:17:44 +08:00
✨ 支持 template 模板 list 模式
This commit is contained in:
@@ -5,4 +5,83 @@ const appPath = app.getPath("cache");
|
||||
|
||||
const PLUGIN_INSTALL_DIR = path.join(appPath, "./rubick-plugins");
|
||||
|
||||
export { PLUGIN_INSTALL_DIR };
|
||||
const DECODE_KEY = {
|
||||
Backspace: "Backspace",
|
||||
Tab: "Tab",
|
||||
Enter: "Enter",
|
||||
MediaPlayPause: "MediaPlayPause",
|
||||
Escape: "Escape",
|
||||
Space: "Space",
|
||||
PageUp: "PageUp",
|
||||
PageDown: "PageDown",
|
||||
End: "End",
|
||||
Home: "Home",
|
||||
ArrowLeft: "Left",
|
||||
ArrowUp: "Up",
|
||||
ArrowRight: "Right",
|
||||
ArrowDown: "Down",
|
||||
PrintScreen: "PrintScreen",
|
||||
Insert: "Insert",
|
||||
Delete: "Delete",
|
||||
Digit0: "0",
|
||||
Digit1: "1",
|
||||
Digit2: "2",
|
||||
Digit3: "3",
|
||||
Digit4: "4",
|
||||
Digit5: "5",
|
||||
Digit6: "6",
|
||||
Digit7: "7",
|
||||
Digit8: "8",
|
||||
Digit9: "9",
|
||||
KeyA: "A",
|
||||
KeyB: "B",
|
||||
KeyC: "C",
|
||||
KeyD: "D",
|
||||
KeyE: "E",
|
||||
KeyF: "F",
|
||||
KeyG: "G",
|
||||
KeyH: "H",
|
||||
KeyI: "I",
|
||||
KeyJ: "J",
|
||||
KeyK: "K",
|
||||
KeyL: "L",
|
||||
KeyM: "M",
|
||||
KeyN: "N",
|
||||
KeyO: "O",
|
||||
KeyP: "P",
|
||||
KeyQ: "Q",
|
||||
KeyR: "R",
|
||||
KeyS: "S",
|
||||
KeyT: "T",
|
||||
KeyU: "U",
|
||||
KeyV: "V",
|
||||
KeyW: "W",
|
||||
KeyX: "X",
|
||||
KeyY: "Y",
|
||||
KeyZ: "Z",
|
||||
F1: "F1",
|
||||
F2: "F2",
|
||||
F3: "F3",
|
||||
F4: "F4",
|
||||
F5: "F5",
|
||||
F6: "F6",
|
||||
F7: "F7",
|
||||
F8: "F8",
|
||||
F9: "F9",
|
||||
F10: "F10",
|
||||
F11: "F11",
|
||||
F12: "F12",
|
||||
Semicolon: ";",
|
||||
Equal: "=",
|
||||
Comma: ",",
|
||||
Minus: "-",
|
||||
Period: ".",
|
||||
Slash: "/",
|
||||
Backquote: "`",
|
||||
BracketLeft: "[",
|
||||
Backslash: "\\",
|
||||
BracketRight: "]",
|
||||
Quote: "'",
|
||||
};
|
||||
|
||||
export { PLUGIN_INSTALL_DIR, DECODE_KEY };
|
||||
|
||||
@@ -3,6 +3,21 @@ import path from "path";
|
||||
import commonConst from "../../common/utils/commonConst";
|
||||
import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/main";
|
||||
|
||||
const getPreloadPath = (plugin, pluginIndexPath) => {
|
||||
const { name, preload, tplPath, indexPath } = plugin;
|
||||
if (commonConst.dev()) {
|
||||
if (name === "rubick-system-feature") {
|
||||
return path.resolve(__static, `../feature/public/preload.js`);
|
||||
}
|
||||
if (tplPath) {
|
||||
return path.resolve(indexPath.replace("file:", ""), `./`, preload);
|
||||
}
|
||||
return path.resolve(pluginIndexPath.replace("file:", ""), `../`, preload);
|
||||
}
|
||||
|
||||
return path.resolve(pluginIndexPath.replace("file:", ""), `../`, preload);
|
||||
};
|
||||
|
||||
export default () => {
|
||||
let view;
|
||||
|
||||
@@ -13,19 +28,12 @@ export default () => {
|
||||
};
|
||||
|
||||
const createView = (plugin, window: BrowserWindow) => {
|
||||
let pluginIndexPath = plugin.indexPath;
|
||||
let pluginIndexPath = plugin.tplPath || plugin.indexPath;
|
||||
if (!pluginIndexPath) {
|
||||
const pluginPath = path.resolve(baseDir, "node_modules", plugin.name);
|
||||
pluginIndexPath = `file://${path.join(pluginPath, "./", plugin.main)}`;
|
||||
}
|
||||
const preload =
|
||||
commonConst.dev() && plugin.name === "rubick-system-feature"
|
||||
? path.resolve(__static, `../feature/public/preload.js`)
|
||||
: path.resolve(
|
||||
pluginIndexPath.replace("file:", ""),
|
||||
`../`,
|
||||
plugin.preload
|
||||
);
|
||||
const preload = getPreloadPath(plugin, pluginIndexPath);
|
||||
|
||||
const ses = session.fromPartition("<" + plugin.name + ">");
|
||||
ses.setPreloads([`${__static}/preload.js`]);
|
||||
@@ -44,10 +52,10 @@ export default () => {
|
||||
});
|
||||
window.setBrowserView(view);
|
||||
view.webContents.loadURL(pluginIndexPath);
|
||||
window.once("ready-to-show", () => {
|
||||
view.webContents.once("dom-ready", () => {
|
||||
window.setSize(800, 660);
|
||||
view.setBounds({ x: 0, y: 60, width: 800, height: 600 });
|
||||
view.setAutoResize({ width: true });
|
||||
window.setSize(800, 660);
|
||||
commonConst.dev() && view.webContents.openDevTools();
|
||||
executeHooks("PluginEnter", plugin.ext);
|
||||
executeHooks("PluginReady", plugin.ext);
|
||||
|
||||
@@ -8,10 +8,10 @@ import {
|
||||
clipboard,
|
||||
} from "electron";
|
||||
import { runner } from "../browsers";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import { LocalDb } from "@/core";
|
||||
import plist from "plist";
|
||||
import { DECODE_KEY } from "@/common/constans/main";
|
||||
|
||||
const runnerInstance = runner();
|
||||
const dbInstance = new LocalDb(app.getPath("userData"));
|
||||
@@ -156,6 +156,22 @@ const API: any = {
|
||||
);
|
||||
return true;
|
||||
},
|
||||
sendPluginSomeKeyDownEvent({ data: { modifiers, keyCode } }) {
|
||||
const code = DECODE_KEY[keyCode];
|
||||
if (!code || !runnerInstance.getView()) return;
|
||||
if (modifiers.length > 0) {
|
||||
runnerInstance.getView().webContents.sendInputEvent({
|
||||
type: "keyDown",
|
||||
modifiers,
|
||||
keyCode: code,
|
||||
});
|
||||
} else {
|
||||
runnerInstance.getView().webContents.sendInputEvent({
|
||||
type: "keyDown",
|
||||
keyCode: code,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default (mainWindow: BrowserWindow) => {
|
||||
|
||||
@@ -5,17 +5,12 @@
|
||||
id="search"
|
||||
class="main-input"
|
||||
@input="(e) => changeValue(e)"
|
||||
@keydown.down="() => emit('changeCurrent', 1)"
|
||||
@keydown.up="() => emit('changeCurrent', -1)"
|
||||
@keydown.down="(e) => keydownEvent(e, 1)"
|
||||
@keydown.up="(e) => keydownEvent(e, -1)"
|
||||
@keydown="e => checkNeedInit(e)"
|
||||
:value="searchValue"
|
||||
:placeholder="placeholder || 'Hi, Rubick2'"
|
||||
@keypress.enter="
|
||||
(e) => targetSearch({ value: e.target.value, type: 'enter' })
|
||||
"
|
||||
@keypress.space="
|
||||
(e) => targetSearch({ value: e.target.value, type: 'space' })
|
||||
"
|
||||
@keypress.enter="(e) => keydownEvent(e)"
|
||||
>
|
||||
<template #suffix>
|
||||
<div class="suffix-tool" >
|
||||
@@ -64,6 +59,7 @@ const props = defineProps({
|
||||
|
||||
const changeValue = (e) => {
|
||||
if (props.currentPlugin.name === "rubick-system-feature") return;
|
||||
targetSearch({ value: e.target.value });
|
||||
emit("onSearch", e);
|
||||
};
|
||||
|
||||
@@ -75,6 +71,27 @@ const emit = defineEmits([
|
||||
"choosePlugin",
|
||||
]);
|
||||
|
||||
const keydownEvent = (e, index) => {
|
||||
const { ctrlKey, shiftKey, altKey, metaKey } = e;
|
||||
const modifiers = [];
|
||||
ctrlKey && modifiers.push("control");
|
||||
shiftKey && modifiers.push("shift");
|
||||
altKey && modifiers.push("alt");
|
||||
metaKey && modifiers.push("meta");
|
||||
ipcRenderer.send("msg-trigger", {
|
||||
type: "sendPluginSomeKeyDownEvent",
|
||||
data: {
|
||||
keyCode: e.code,
|
||||
modifiers,
|
||||
},
|
||||
});
|
||||
if(index) {
|
||||
emit("changeCurrent", index);
|
||||
} else {
|
||||
!props.currentPlugin.name && emit("choosePlugin");
|
||||
}
|
||||
};
|
||||
|
||||
const checkNeedInit = (e) => {
|
||||
if (e.target.value === "" && e.keyCode === 8) {
|
||||
closeTag();
|
||||
@@ -87,8 +104,6 @@ const targetSearch = ({ value, type }) => {
|
||||
type: "sendSubInputChangeEvent",
|
||||
data: { text: value },
|
||||
});
|
||||
} else {
|
||||
emit("choosePlugin");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ const createPluginManager = (): any => {
|
||||
return {
|
||||
...pluginInfo,
|
||||
indexPath: commonConst.dev()
|
||||
? "http://localhost:8080/#/"
|
||||
? "http://localhost:8081/#/"
|
||||
: `file://${path.join(pluginPath, "../", pluginInfo.main)}`,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ import throttle from "lodash.throttle";
|
||||
import { remote } from "electron";
|
||||
import path from "path";
|
||||
import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/renderer";
|
||||
import commonConst from "@/common/utils/commonConst";
|
||||
|
||||
function searchKeyValues(lists, value) {
|
||||
return lists.filter((item) => {
|
||||
@@ -44,16 +45,23 @@ const optionsManager = ({ searchValue, appList, openPlugin, currentPlugin }) =>
|
||||
"node_modules",
|
||||
plugin.name
|
||||
);
|
||||
openPlugin({
|
||||
const pluginDist = {
|
||||
...toRaw(plugin),
|
||||
indexPath: `file://${path.join(
|
||||
pluginPath,
|
||||
"./",
|
||||
plugin.main
|
||||
plugin.main || ""
|
||||
)}`,
|
||||
cmd,
|
||||
feature: fe,
|
||||
});
|
||||
};
|
||||
// 模板文件
|
||||
if (!plugin.main) {
|
||||
pluginDist.tplPath = commonConst.dev()
|
||||
? "http://localhost:8082/#/"
|
||||
: `file://${__static}/tpl/index.html`;
|
||||
}
|
||||
openPlugin(pluginDist);
|
||||
},
|
||||
})),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user