mirror of
https://github.com/rubickCenter/rubick
synced 2025-11-19 00:37:44 +08:00
🚨 增加 prettier
This commit is contained in:
@@ -38,6 +38,12 @@ export default () => {
|
||||
|
||||
const createView = (plugin, window: BrowserWindow) => {
|
||||
let pluginIndexPath = plugin.tplPath || plugin.indexPath;
|
||||
// 再尝试去找
|
||||
if (plugin.name === "rubick-system-feature" && !pluginIndexPath) {
|
||||
pluginIndexPath = commonConst.dev()
|
||||
? "http://localhost:8081/#/"
|
||||
: `file://${__static}/feature/index.html`;
|
||||
}
|
||||
if (!pluginIndexPath) {
|
||||
const pluginPath = path.resolve(baseDir, "node_modules", plugin.name);
|
||||
pluginIndexPath = `file://${path.join(pluginPath, "./", plugin.main)}`;
|
||||
|
||||
@@ -38,7 +38,6 @@ class App {
|
||||
this.onQuit();
|
||||
}
|
||||
}
|
||||
|
||||
beforeReady() {
|
||||
// 系统托盘
|
||||
if (commonConst.macOS()) {
|
||||
@@ -55,7 +54,6 @@ class App {
|
||||
createWindow() {
|
||||
this.windowCreator.init();
|
||||
}
|
||||
|
||||
onReady() {
|
||||
const readyFunction = () => {
|
||||
this.createWindow();
|
||||
|
||||
@@ -35,14 +35,14 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { watch, ref, nextTick, toRaw } from "vue";
|
||||
import { ipcRenderer, remote } from "electron";
|
||||
import Result from "./components/result.vue";
|
||||
import Search from "./components/search.vue";
|
||||
import getWindowHeight from "../common/utils/getWindowHeight";
|
||||
import createPluginManager from "./plugins-manager";
|
||||
import commonConst from "@/common/utils/commonConst";
|
||||
<script setup lang='ts'>
|
||||
import { watch, ref, nextTick, toRaw } from 'vue';
|
||||
import { ipcRenderer, remote } from 'electron';
|
||||
import Result from './components/result.vue';
|
||||
import Search from './components/search.vue';
|
||||
import getWindowHeight from '../common/utils/getWindowHeight';
|
||||
import createPluginManager from './plugins-manager';
|
||||
import commonConst from '@/common/utils/commonConst';
|
||||
|
||||
const {
|
||||
initPlugins,
|
||||
@@ -59,30 +59,30 @@ const {
|
||||
clipboardFile,
|
||||
setSearchValue,
|
||||
clearClipboardFile,
|
||||
readClipboardContent
|
||||
readClipboardContent,
|
||||
} = createPluginManager();
|
||||
|
||||
initPlugins();
|
||||
|
||||
const currentSelect = ref(0);
|
||||
const menuPluginInfo = ref({});
|
||||
const menuPluginInfo: any = ref({});
|
||||
|
||||
getPluginInfo({
|
||||
pluginName: "feature",
|
||||
pluginName: 'feature',
|
||||
// eslint-disable-next-line no-undef
|
||||
pluginPath: `${__static}/feature/package.json`
|
||||
pluginPath: `${__static}/feature/package.json`,
|
||||
}).then(res => {
|
||||
menuPluginInfo.value = res;
|
||||
remote.getGlobal("LOCAL_PLUGINS").addPlugin(res);
|
||||
remote.getGlobal('LOCAL_PLUGINS').addPlugin(res);
|
||||
});
|
||||
|
||||
watch([options], () => {
|
||||
currentSelect.value = 0;
|
||||
if (currentPlugin.value.name) return;
|
||||
nextTick(() => {
|
||||
ipcRenderer.sendSync("msg-trigger", {
|
||||
type: "setExpendHeight",
|
||||
data: getWindowHeight(options.value)
|
||||
ipcRenderer.sendSync('msg-trigger', {
|
||||
type: 'setExpendHeight',
|
||||
data: getWindowHeight(options.value),
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -101,12 +101,12 @@ const openMenu = (ext) => {
|
||||
openPlugin({
|
||||
...toRaw(menuPluginInfo.value),
|
||||
feature: menuPluginInfo.value.features[0],
|
||||
cmd: "插件市场",
|
||||
ext
|
||||
cmd: '插件市场',
|
||||
ext,
|
||||
});
|
||||
};
|
||||
|
||||
window.rubick.openMenu = openMenu
|
||||
window.rubick.openMenu = openMenu;
|
||||
|
||||
const choosePlugin = () => {
|
||||
const currentChoose = options.value[currentSelect.value];
|
||||
@@ -114,11 +114,11 @@ const choosePlugin = () => {
|
||||
};
|
||||
|
||||
const clearSearchValue = () => {
|
||||
setSearchValue("");
|
||||
setSearchValue('');
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
<style lang='less'>
|
||||
.drag-bar {
|
||||
-webkit-app-region: drag;
|
||||
width: 100%;
|
||||
@@ -128,6 +128,7 @@ const clearSearchValue = () => {
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
#components-layout {
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
@@ -135,6 +136,7 @@ const clearSearchValue = () => {
|
||||
width: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.drag {
|
||||
-webkit-app-region: drag;
|
||||
}
|
||||
|
||||
@@ -28,9 +28,10 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import BScroll from "@better-scroll/core";
|
||||
import { defineProps, onMounted, ref } from "vue";
|
||||
<script lang='ts' setup>
|
||||
import BScroll from '@better-scroll/core';
|
||||
import { defineProps, onMounted, ref } from 'vue';
|
||||
|
||||
const scrollDom = ref(null);
|
||||
|
||||
onMounted(() => {
|
||||
@@ -40,7 +41,7 @@ onMounted(() => {
|
||||
const props = defineProps({
|
||||
searchValue: {
|
||||
type: [String, Number],
|
||||
default: "",
|
||||
default: '',
|
||||
},
|
||||
options: {
|
||||
type: Array,
|
||||
@@ -55,11 +56,11 @@ const props = defineProps({
|
||||
});
|
||||
|
||||
const renderTitle = (title) => {
|
||||
if (typeof title !== "string") return;
|
||||
if (typeof title !== 'string') return;
|
||||
if (!props.searchValue) return title;
|
||||
const result = title.toLowerCase().split(props.searchValue.toLowerCase());
|
||||
if (result && result.length > 1) {
|
||||
return `<div>${result[0]}<span style="color: red">${props.searchValue}</span>${result[1]}</div>`;
|
||||
return `<div>${result[0]}<span style='color: red'>${props.searchValue}</span>${result[1]}</div>`;
|
||||
} else {
|
||||
return `<div>${result[0]}</div>`;
|
||||
}
|
||||
|
||||
@@ -51,10 +51,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineProps, defineEmits, ref, computed } from "vue";
|
||||
import { ipcRenderer, remote } from "electron";
|
||||
import { LoadingOutlined, MoreOutlined } from "@ant-design/icons-vue";
|
||||
const opConfig = remote.getGlobal("OP_CONFIG");
|
||||
import { defineProps, defineEmits, ref } from 'vue';
|
||||
import { ipcRenderer, remote } from 'electron';
|
||||
import { LoadingOutlined, MoreOutlined } from '@ant-design/icons-vue';
|
||||
|
||||
const opConfig = remote.getGlobal('OP_CONFIG');
|
||||
const { Menu } = remote;
|
||||
|
||||
const config = ref(opConfig.get());
|
||||
@@ -62,63 +63,63 @@ const config = ref(opConfig.get());
|
||||
const props: any = defineProps({
|
||||
searchValue: {
|
||||
type: [String, Number],
|
||||
default: ""
|
||||
default: '',
|
||||
},
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: ""
|
||||
default: '',
|
||||
},
|
||||
currentPlugin: {},
|
||||
pluginLoading: Boolean,
|
||||
clipboardFile: (() => [])()
|
||||
clipboardFile: (() => [])(),
|
||||
});
|
||||
|
||||
const changeValue = e => {
|
||||
if (props.currentPlugin.name === "rubick-system-feature") return;
|
||||
if (props.currentPlugin.name === 'rubick-system-feature') return;
|
||||
targetSearch({ value: e.target.value });
|
||||
emit("onSearch", e);
|
||||
emit('onSearch', e);
|
||||
};
|
||||
|
||||
const emit = defineEmits([
|
||||
"onSearch",
|
||||
"changeCurrent",
|
||||
"openMenu",
|
||||
"changeSelect",
|
||||
"choosePlugin",
|
||||
"focus",
|
||||
"clearSearchValue",
|
||||
"readClipboardContent"
|
||||
'onSearch',
|
||||
'changeCurrent',
|
||||
'openMenu',
|
||||
'changeSelect',
|
||||
'choosePlugin',
|
||||
'focus',
|
||||
'clearSearchValue',
|
||||
'readClipboardContent',
|
||||
]);
|
||||
|
||||
const keydownEvent = (e, key: string) => {
|
||||
const { ctrlKey, shiftKey, altKey, metaKey } = e;
|
||||
const modifiers: Array<string> = [];
|
||||
ctrlKey && modifiers.push("control");
|
||||
shiftKey && modifiers.push("shift");
|
||||
altKey && modifiers.push("alt");
|
||||
metaKey && modifiers.push("meta");
|
||||
ipcRenderer.send("msg-trigger", {
|
||||
type: "sendPluginSomeKeyDownEvent",
|
||||
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
|
||||
}
|
||||
modifiers,
|
||||
},
|
||||
});
|
||||
const runPluginDisable = e.target.value === "" || props.currentPlugin.name;
|
||||
const runPluginDisable = e.target.value === '' || props.currentPlugin.name;
|
||||
switch (key) {
|
||||
case "up":
|
||||
emit("changeCurrent", -1);
|
||||
case 'up':
|
||||
emit('changeCurrent', -1);
|
||||
break;
|
||||
case "down":
|
||||
emit("changeCurrent", 1);
|
||||
case 'down':
|
||||
emit('changeCurrent', 1);
|
||||
break;
|
||||
case "enter":
|
||||
case 'enter':
|
||||
if (runPluginDisable) return;
|
||||
emit("choosePlugin");
|
||||
emit('choosePlugin');
|
||||
break;
|
||||
case "space":
|
||||
case 'space':
|
||||
if (runPluginDisable || !opConfig.get().perf.common.space) return;
|
||||
emit("choosePlugin");
|
||||
emit('choosePlugin');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -128,63 +129,63 @@ const keydownEvent = (e, key: string) => {
|
||||
const checkNeedInit = e => {
|
||||
const { ctrlKey, metaKey } = e;
|
||||
|
||||
if (e.target.value === "" && e.keyCode === 8) {
|
||||
if (e.target.value === '' && e.keyCode === 8) {
|
||||
closeTag();
|
||||
}
|
||||
// 手动粘贴
|
||||
if ((ctrlKey || metaKey) && e.key === "v") {
|
||||
emit("readClipboardContent");
|
||||
if ((ctrlKey || metaKey) && e.key === 'v') {
|
||||
emit('readClipboardContent');
|
||||
}
|
||||
};
|
||||
|
||||
const targetSearch = ({ value }) => {
|
||||
if (props.currentPlugin.name) {
|
||||
return ipcRenderer.sendSync("msg-trigger", {
|
||||
type: "sendSubInputChangeEvent",
|
||||
data: { text: value }
|
||||
return ipcRenderer.sendSync('msg-trigger', {
|
||||
type: 'sendSubInputChangeEvent',
|
||||
data: { text: value },
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const closeTag = () => {
|
||||
emit("changeSelect", {});
|
||||
emit("clearClipbord");
|
||||
ipcRenderer.send("msg-trigger", {
|
||||
type: "removePlugin"
|
||||
emit('changeSelect', {});
|
||||
emit('clearClipbord');
|
||||
ipcRenderer.send('msg-trigger', {
|
||||
type: 'removePlugin',
|
||||
});
|
||||
};
|
||||
|
||||
const showSeparate = () => {
|
||||
let pluginMenu: any = [
|
||||
{
|
||||
label: config.value.perf.common.hideOnBlur ? "钉住" : "自动隐藏",
|
||||
click: changeHideOnBlur
|
||||
}
|
||||
label: config.value.perf.common.hideOnBlur ? '钉住' : '自动隐藏',
|
||||
click: changeHideOnBlur,
|
||||
},
|
||||
];
|
||||
if (props.currentPlugin && props.currentPlugin.logo) {
|
||||
pluginMenu = pluginMenu.concat([
|
||||
{
|
||||
label: "开发者工具",
|
||||
label: '开发者工具',
|
||||
click: () => {
|
||||
ipcRenderer.send("msg-trigger", { type: "openPluginDevTools" });
|
||||
ipcRenderer.send('msg-trigger', { type: 'openPluginDevTools' });
|
||||
// todo
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "当前插件信息",
|
||||
label: '当前插件信息',
|
||||
submenu: [
|
||||
{
|
||||
label: "简介"
|
||||
label: '简介',
|
||||
},
|
||||
{
|
||||
label: "功能"
|
||||
}
|
||||
]
|
||||
label: '功能',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "分离窗口",
|
||||
click: newWindow
|
||||
}
|
||||
label: '分离窗口',
|
||||
click: newWindow,
|
||||
},
|
||||
]);
|
||||
}
|
||||
let menu = Menu.buildFromTemplate(pluginMenu);
|
||||
@@ -201,13 +202,13 @@ const changeHideOnBlur = () => {
|
||||
const getIcon = () => {
|
||||
if (props.clipboardFile[0].dataUrl) return props.clipboardFile[0].dataUrl;
|
||||
return props.clipboardFile[0].isFile
|
||||
? require("../assets/file.png")
|
||||
: require("../assets/folder.png");
|
||||
? require('../assets/file.png')
|
||||
: require('../assets/folder.png');
|
||||
};
|
||||
|
||||
const newWindow = () => {
|
||||
ipcRenderer.send("msg-trigger", {
|
||||
type: "detachPlugin"
|
||||
ipcRenderer.send('msg-trigger', {
|
||||
type: 'detachPlugin',
|
||||
});
|
||||
// todo
|
||||
};
|
||||
@@ -218,7 +219,7 @@ window.rubick.hooks.onShow = () => {
|
||||
};
|
||||
|
||||
window.rubick.hooks.onHide = () => {
|
||||
emit("clearSearchValue");
|
||||
emit('clearSearchValue');
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -238,6 +239,7 @@ window.rubick.hooks.onHide = () => {
|
||||
white-space: nowrap;
|
||||
max-width: 200px;
|
||||
}
|
||||
|
||||
.select-tag {
|
||||
white-space: pre;
|
||||
user-select: none;
|
||||
@@ -252,6 +254,7 @@ window.rubick.hooks.onHide = () => {
|
||||
margin-right: 1px;
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.main-input {
|
||||
height: 60px !important;
|
||||
box-sizing: border-box;
|
||||
@@ -259,6 +262,7 @@ window.rubick.hooks.onHide = () => {
|
||||
border: none;
|
||||
outline: none;
|
||||
box-shadow: none !important;
|
||||
|
||||
.ant-select-selection,
|
||||
.ant-input,
|
||||
.ant-select-selection__rendered {
|
||||
@@ -267,6 +271,7 @@ window.rubick.hooks.onHide = () => {
|
||||
border: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
.rubick-logo,
|
||||
.icon-tool {
|
||||
width: 40px;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createApp } from "vue";
|
||||
import { Button, List, Spin, Input, Avatar, Tag } from "ant-design-vue";
|
||||
import App from "./App.vue";
|
||||
import { createApp } from 'vue';
|
||||
import { Button, List, Spin, Input, Avatar, Tag } from 'ant-design-vue';
|
||||
import App from './App.vue';
|
||||
|
||||
createApp(App)
|
||||
.use(Button)
|
||||
@@ -9,4 +9,4 @@ createApp(App)
|
||||
.use(Input)
|
||||
.use(Avatar)
|
||||
.use(Tag)
|
||||
.mount("#app");
|
||||
.mount('#app');
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import getCopyFiles from "@/common/utils/getCopyFiles";
|
||||
import { clipboard, nativeImage, remote, ipcRenderer } from "electron";
|
||||
import path from "path";
|
||||
import pluginClickEvent from "./pluginClickEvent";
|
||||
import { ref } from "vue";
|
||||
import getCopyFiles from '@/common/utils/getCopyFiles';
|
||||
import { clipboard, nativeImage, remote, ipcRenderer } from 'electron';
|
||||
import path from 'path';
|
||||
import pluginClickEvent from './pluginClickEvent';
|
||||
import { ref } from 'vue';
|
||||
|
||||
export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
|
||||
const clipboardFile: any = ref([]);
|
||||
const searchFocus = () => {
|
||||
const config = remote.getGlobal("OP_CONFIG").get();
|
||||
const config = remote.getGlobal('OP_CONFIG').get();
|
||||
// 未开启自动粘贴
|
||||
if (!config.perf.common.autoPast) return;
|
||||
|
||||
@@ -15,18 +15,18 @@ export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
|
||||
const fileList = getCopyFiles();
|
||||
// 拷贝的是文件
|
||||
if (fileList) {
|
||||
window.setSubInputValue({ value: "" });
|
||||
window.setSubInputValue({ value: '' });
|
||||
clipboardFile.value = fileList;
|
||||
const localPlugins = remote.getGlobal("LOCAL_PLUGINS").getLocalPlugins();
|
||||
const localPlugins = remote.getGlobal('LOCAL_PLUGINS').getLocalPlugins();
|
||||
const options: any = [
|
||||
{
|
||||
name: "复制路径",
|
||||
value: "plugin",
|
||||
icon: require("../assets/link.png"),
|
||||
desc: "复制路径到剪切板",
|
||||
name: '复制路径',
|
||||
value: 'plugin',
|
||||
icon: require('../assets/link.png'),
|
||||
desc: '复制路径到剪切板',
|
||||
click: () => {
|
||||
clipboard.writeText(fileList.map((file) => file.path).join(","));
|
||||
ipcRenderer.send("msg-trigger", { type: "hideMainWindow" });
|
||||
clipboard.writeText(fileList.map((file) => file.path).join(','));
|
||||
ipcRenderer.send('msg-trigger', { type: 'hideMainWindow' });
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -50,13 +50,13 @@ export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
|
||||
fe.cmds.forEach((cmd) => {
|
||||
const regImg = /\.(png|jpg|gif|jpeg|webp)$/;
|
||||
if (
|
||||
cmd.type === "img" &&
|
||||
cmd.type === 'img' &&
|
||||
regImg.test(ext) &&
|
||||
fileList.length === 1
|
||||
) {
|
||||
options.push({
|
||||
name: cmd.label,
|
||||
value: "plugin",
|
||||
value: 'plugin',
|
||||
icon: plugin.logo,
|
||||
desc: fe.explain,
|
||||
type: plugin.pluginType,
|
||||
@@ -67,7 +67,7 @@ export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
|
||||
cmd,
|
||||
ext: {
|
||||
code: fe.code,
|
||||
type: cmd.type || "text",
|
||||
type: cmd.type || 'text',
|
||||
payload: nativeImage
|
||||
.createFromPath(fileList[0].path)
|
||||
.toDataURL(),
|
||||
@@ -81,11 +81,11 @@ export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
|
||||
// 如果是文件,且符合文件正则类型
|
||||
if (
|
||||
fileList.length > 1 ||
|
||||
(cmd.type === "file" && new RegExp(cmd.match).test(ext))
|
||||
(cmd.type === 'file' && new RegExp(cmd.match).test(ext))
|
||||
) {
|
||||
options.push({
|
||||
name: cmd,
|
||||
value: "plugin",
|
||||
value: 'plugin',
|
||||
icon: plugin.logo,
|
||||
desc: fe.explain,
|
||||
type: plugin.pluginType,
|
||||
@@ -96,7 +96,7 @@ export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
|
||||
cmd,
|
||||
ext: {
|
||||
code: fe.code,
|
||||
type: cmd.type || "text",
|
||||
type: cmd.type || 'text',
|
||||
payload: fileList,
|
||||
},
|
||||
openPlugin,
|
||||
@@ -115,7 +115,7 @@ export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
|
||||
}
|
||||
const clipboardType = clipboard.availableFormats();
|
||||
if (!clipboardType.length) return;
|
||||
if ("text/plain" === clipboardType[0]) {
|
||||
if ('text/plain' === clipboardType[0]) {
|
||||
const contentText = clipboard.readText();
|
||||
if (contentText.trim()) {
|
||||
clearClipboardFile();
|
||||
@@ -134,7 +134,7 @@ export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
|
||||
// read image
|
||||
const img = clipboard.readImage();
|
||||
const dataUrl = img.toDataURL();
|
||||
if (!dataUrl.replace("data:image/png;base64,", "")) return;
|
||||
if (!dataUrl.replace('data:image/png;base64,', '')) return;
|
||||
clipboardFile.value = [
|
||||
{
|
||||
isFile: true,
|
||||
@@ -143,7 +143,7 @@ export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
|
||||
dataUrl,
|
||||
},
|
||||
];
|
||||
const localPlugins = remote.getGlobal("LOCAL_PLUGINS").getLocalPlugins();
|
||||
const localPlugins = remote.getGlobal('LOCAL_PLUGINS').getLocalPlugins();
|
||||
const options: any = [];
|
||||
// 再正则插件
|
||||
localPlugins.forEach((plugin) => {
|
||||
@@ -152,10 +152,10 @@ export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
|
||||
if (!feature) return;
|
||||
feature.forEach((fe) => {
|
||||
fe.cmds.forEach((cmd) => {
|
||||
if (cmd.type === "img") {
|
||||
if (cmd.type === 'img') {
|
||||
options.push({
|
||||
name: cmd.label,
|
||||
value: "plugin",
|
||||
value: 'plugin',
|
||||
icon: plugin.logo,
|
||||
desc: fe.explain,
|
||||
type: plugin.pluginType,
|
||||
@@ -166,7 +166,7 @@ export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
|
||||
cmd,
|
||||
ext: {
|
||||
code: fe.code,
|
||||
type: cmd.type || "text",
|
||||
type: cmd.type || 'text',
|
||||
payload: dataUrl,
|
||||
},
|
||||
openPlugin,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { reactive, toRefs, ref } from "vue";
|
||||
import { nativeImage, remote, ipcRenderer } from "electron";
|
||||
import appSearch from "@/core/app-search";
|
||||
import { PluginHandler } from "@/core";
|
||||
import path from "path";
|
||||
import commonConst from "@/common/utils/commonConst";
|
||||
import { execSync } from "child_process";
|
||||
import searchManager from "./search";
|
||||
import optionsManager from "./options";
|
||||
import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/renderer";
|
||||
import { reactive, toRefs, ref } from 'vue';
|
||||
import { nativeImage, remote, ipcRenderer } from 'electron';
|
||||
import appSearch from '@/core/app-search';
|
||||
import { PluginHandler } from '@/core';
|
||||
import path from 'path';
|
||||
import commonConst from '@/common/utils/commonConst';
|
||||
import { execSync } from 'child_process';
|
||||
import searchManager from './search';
|
||||
import optionsManager from './options';
|
||||
import { PLUGIN_INSTALL_DIR as baseDir } from '@/common/constans/renderer';
|
||||
|
||||
const createPluginManager = (): any => {
|
||||
const pluginInstance = new PluginHandler({
|
||||
@@ -34,27 +34,27 @@ const createPluginManager = (): any => {
|
||||
};
|
||||
|
||||
const openPlugin = (plugin) => {
|
||||
if (plugin.pluginType === "ui" || plugin.pluginType === "system") {
|
||||
if (plugin.pluginType === 'ui' || plugin.pluginType === 'system') {
|
||||
if (state.currentPlugin && state.currentPlugin.name === plugin.name) {
|
||||
return;
|
||||
}
|
||||
loadPlugin(plugin);
|
||||
ipcRenderer.sendSync("msg-trigger", {
|
||||
type: "openPlugin",
|
||||
ipcRenderer.sendSync('msg-trigger', {
|
||||
type: 'openPlugin',
|
||||
data: JSON.parse(
|
||||
JSON.stringify({
|
||||
...plugin,
|
||||
ext: plugin.ext || {
|
||||
code: plugin.feature.code,
|
||||
type: plugin.cmd.type || "text",
|
||||
type: plugin.cmd.type || 'text',
|
||||
payload: null,
|
||||
},
|
||||
})
|
||||
),
|
||||
});
|
||||
setSearchValue("");
|
||||
setSearchValue('');
|
||||
}
|
||||
if (plugin.pluginType === "app") {
|
||||
if (plugin.pluginType === 'app') {
|
||||
execSync(plugin.action);
|
||||
}
|
||||
};
|
||||
@@ -83,8 +83,8 @@ const createPluginManager = (): any => {
|
||||
...pluginInfo,
|
||||
icon: pluginInfo.logo,
|
||||
indexPath: commonConst.dev()
|
||||
? "http://localhost:8081/#/"
|
||||
: `file://${path.join(pluginPath, "../", pluginInfo.main)}`,
|
||||
? 'http://localhost:8081/#/'
|
||||
: `file://${path.join(pluginPath, '../', pluginInfo.main)}`,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -104,18 +104,18 @@ const createPluginManager = (): any => {
|
||||
|
||||
window.updatePlugin = ({ currentPlugin }: any) => {
|
||||
state.currentPlugin = currentPlugin;
|
||||
remote.getGlobal("LOCAL_PLUGINS").updatePlugin(currentPlugin);
|
||||
remote.getGlobal('LOCAL_PLUGINS').updatePlugin(currentPlugin);
|
||||
};
|
||||
|
||||
window.setCurrentPlugin = ({ currentPlugin }) => {
|
||||
state.currentPlugin = currentPlugin;
|
||||
setSearchValue("");
|
||||
setSearchValue('');
|
||||
};
|
||||
|
||||
window.initRubick = () => {
|
||||
state.currentPlugin = {};
|
||||
setSearchValue("");
|
||||
window.setSubInput({ placeholder: "" });
|
||||
setSearchValue('');
|
||||
window.setSubInput({ placeholder: '' });
|
||||
};
|
||||
|
||||
window.pluginLoaded = () => {
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { ref, watch } from "vue";
|
||||
import throttle from "lodash.throttle";
|
||||
import { remote, ipcRenderer } from "electron";
|
||||
import pluginClickEvent from "./pluginClickEvent";
|
||||
import useFocus from "./clipboardWatch";
|
||||
import { ref, watch } from 'vue';
|
||||
import throttle from 'lodash.throttle';
|
||||
import { remote, ipcRenderer } from 'electron';
|
||||
import pluginClickEvent from './pluginClickEvent';
|
||||
import useFocus from './clipboardWatch';
|
||||
|
||||
function formatReg(regStr) {
|
||||
const flags = regStr.replace(/.*\/([gimy]*)$/, "$1");
|
||||
const pattern = flags.replace(new RegExp("^/(.*?)/" + flags + "$"), "$1");
|
||||
const flags = regStr.replace(/.*\/([gimy]*)$/, '$1');
|
||||
const pattern = flags.replace(new RegExp('^/(.*?)/' + flags + '$'), '$1');
|
||||
return new RegExp(pattern, flags);
|
||||
}
|
||||
|
||||
function searchKeyValues(lists, value, strict = false) {
|
||||
return lists.filter((item) => {
|
||||
if (typeof item === "string") {
|
||||
if (typeof item === 'string') {
|
||||
return item.toLowerCase().indexOf(value.toLowerCase()) >= 0;
|
||||
}
|
||||
if (item.type === "regex" && !strict) {
|
||||
if (item.type === 'regex' && !strict) {
|
||||
return formatReg(item.match).test(value);
|
||||
}
|
||||
return false;
|
||||
@@ -31,13 +31,13 @@ const optionsManager = ({
|
||||
const optionsRef = ref([]);
|
||||
|
||||
// 全局快捷键
|
||||
ipcRenderer.on("global-short-key", (e, msg) => {
|
||||
ipcRenderer.on('global-short-key', (e, msg) => {
|
||||
const options = getOptionsFromSearchValue(msg, true);
|
||||
options[0].click();
|
||||
});
|
||||
|
||||
const getOptionsFromSearchValue = (value, strict = false) => {
|
||||
const localPlugins = remote.getGlobal("LOCAL_PLUGINS").getLocalPlugins();
|
||||
const localPlugins = remote.getGlobal('LOCAL_PLUGINS').getLocalPlugins();
|
||||
let options: any = [];
|
||||
// todo 先搜索 plugin
|
||||
localPlugins.forEach((plugin) => {
|
||||
@@ -50,7 +50,7 @@ const optionsManager = ({
|
||||
...options,
|
||||
...cmds.map((cmd) => ({
|
||||
name: cmd.label || cmd,
|
||||
value: "plugin",
|
||||
value: 'plugin',
|
||||
icon: plugin.logo,
|
||||
desc: fe.explain,
|
||||
type: plugin.pluginType,
|
||||
@@ -63,7 +63,7 @@ const optionsManager = ({
|
||||
ext: cmd.type
|
||||
? {
|
||||
code: fe.code,
|
||||
type: cmd.type || "text",
|
||||
type: cmd.type || 'text',
|
||||
payload: searchValue.value,
|
||||
}
|
||||
: null,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/renderer";
|
||||
import path from "path";
|
||||
import { toRaw } from "vue";
|
||||
import commonConst from "@/common/utils/commonConst";
|
||||
import { PLUGIN_INSTALL_DIR as baseDir } from '@/common/constans/renderer';
|
||||
import path from 'path';
|
||||
import { toRaw } from 'vue';
|
||||
import commonConst from '@/common/utils/commonConst';
|
||||
|
||||
export default function pluginClickEvent({ plugin, fe, cmd, ext, openPlugin }) {
|
||||
const pluginPath = path.resolve(baseDir, "node_modules", plugin.name);
|
||||
const pluginPath = path.resolve(baseDir, 'node_modules', plugin.name);
|
||||
const pluginDist = {
|
||||
...toRaw(plugin),
|
||||
indexPath: `file://${path.join(pluginPath, "./", plugin.main || "")}`,
|
||||
indexPath: `file://${path.join(pluginPath, './', plugin.main || '')}`,
|
||||
cmd: cmd.label || cmd,
|
||||
feature: fe,
|
||||
ext,
|
||||
@@ -15,13 +15,13 @@ export default function pluginClickEvent({ plugin, fe, cmd, ext, openPlugin }) {
|
||||
// 模板文件
|
||||
if (!plugin.main) {
|
||||
pluginDist.tplPath = commonConst.dev()
|
||||
? "http://localhost:8082/#/"
|
||||
? 'http://localhost:8082/#/'
|
||||
: `file://${__static}/tpl/index.html`;
|
||||
}
|
||||
// 插件市场
|
||||
if (plugin.name === "rubick-system-feature") {
|
||||
if (plugin.name === 'rubick-system-feature') {
|
||||
pluginDist.indexPath = commonConst.dev()
|
||||
? "http://localhost:8081/#/"
|
||||
? 'http://localhost:8081/#/'
|
||||
: `file://${__static}/feature/index.html`;
|
||||
}
|
||||
openPlugin(pluginDist);
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { reactive, toRefs } from "vue";
|
||||
import { ipcRenderer, remote } from "electron";
|
||||
import { reactive, toRefs } from 'vue';
|
||||
|
||||
const searchManager = () => {
|
||||
const state = reactive({
|
||||
searchValue: "",
|
||||
placeholder: "",
|
||||
searchValue: '',
|
||||
placeholder: '',
|
||||
});
|
||||
|
||||
// search Input operation
|
||||
@@ -21,7 +20,7 @@ const searchManager = () => {
|
||||
state.placeholder = placeholder;
|
||||
};
|
||||
window.removeSubInput = () => {
|
||||
state.placeholder = "";
|
||||
state.placeholder = '';
|
||||
};
|
||||
window.setSubInputValue = ({ value }: { value: string }) => {
|
||||
state.searchValue = value;
|
||||
|
||||
8
src/renderer/shims-vue.d.ts
vendored
8
src/renderer/shims-vue.d.ts
vendored
@@ -1,17 +1,17 @@
|
||||
/* eslint-disable */
|
||||
declare module "*.vue" {
|
||||
import type { DefineComponent } from "vue";
|
||||
declare module '*.vue' {
|
||||
import type { DefineComponent } from 'vue';
|
||||
const component: DefineComponent<{}, {}, any>;
|
||||
export default component;
|
||||
}
|
||||
|
||||
declare module "main" {
|
||||
declare module 'main' {
|
||||
export function main(): any;
|
||||
}
|
||||
|
||||
declare const __static: string;
|
||||
|
||||
declare module "lodash.throttle";
|
||||
declare module 'lodash.throttle';
|
||||
|
||||
interface Window {
|
||||
rubick: any;
|
||||
|
||||
Reference in New Issue
Block a user