Compare commits

...

5 Commits

Author SHA1 Message Date
layyback
dbe671f5cc 🚀 build feature & release 2022-04-20 10:26:37 +08:00
layyback
e0a2da9fcd 🚀 build feature & release 2022-04-20 10:26:10 +08:00
璃白
2a6a576186 🚀 update version & retry release 2022-04-20 00:37:29 +08:00
璃白
c685dbcd30 Merge pull request #104 from rubickCenter/feature/runbyclick
 run plugin with tags
2022-04-19 22:07:24 +08:00
layyback
39eeda55ff run plugin with tags 2022-04-19 22:04:27 +08:00
19 changed files with 450 additions and 365 deletions

View File

@@ -1,7 +1,11 @@
<template> <template>
<div class="installed"> <div class="installed">
<div v-if="!localPlugins.length"> <div v-if="!localPlugins.length">
<a-result status="404" title="暂无任何插件" sub-title="去插件市场选择安装合适的插件吧" /> <a-result
status="404"
title="暂无任何插件"
sub-title="去插件市场选择安装合适的插件吧"
/>
</div> </div>
<div class="container" v-else> <div class="container" v-else>
<div class="installed-list"> <div class="installed-list">
@@ -44,8 +48,7 @@
@click="deletePlugin(pluginDetail)" @click="deletePlugin(pluginDetail)"
> >
移除 移除
</a-button </a-button>
>
</div> </div>
</div> </div>
<a-tabs default-active-key="1"> <a-tabs default-active-key="1">
@@ -61,6 +64,14 @@
:key="cmd" :key="cmd"
v-for="cmd in item.cmds" v-for="cmd in item.cmds"
@close="removeFeature(cmd)" @close="removeFeature(cmd)"
@click="
!cmd.label &&
openPlugin({
code: item.code,
cmd
})
"
:class="{ executable: !cmd.label }"
:color="!cmd.label && '#87d068'" :color="!cmd.label && '#87d068'"
> >
{{ cmd.label || cmd }} {{ cmd.label || cmd }}
@@ -74,7 +85,6 @@
</a-tabs> </a-tabs>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
@@ -83,6 +93,7 @@ import { useStore } from "vuex";
import { computed, ref } from "vue"; import { computed, ref } from "vue";
import path from "path"; import path from "path";
import MarkdownIt from "markdown-it"; import MarkdownIt from "markdown-it";
const { ipcRenderer } = window.require("electron");
const { remote } = window.require("electron"); const { remote } = window.require("electron");
const fs = window.require("fs"); const fs = window.require("fs");
@@ -94,11 +105,11 @@ const baseDir = path.join(appPath, "./rubick-plugins");
const store = useStore(); const store = useStore();
const localPlugins = computed(() => const localPlugins = computed(() =>
store.state.localPlugins.filter( store.state.localPlugins.filter(
(plugin) => plugin.name !== "rubick-system-feature" plugin => plugin.name !== "rubick-system-feature"
) )
); );
const updateLocalPlugin = () => store.dispatch("updateLocalPlugin"); const updateLocalPlugin = () => store.dispatch("updateLocalPlugin");
const startUnDownload = (name) => store.dispatch("startUnDownload", name); const startUnDownload = name => store.dispatch("startUnDownload", name);
const currentSelect = ref([0]); const currentSelect = ref([0]);
@@ -106,6 +117,23 @@ const pluginDetail = computed(() => {
return localPlugins.value[currentSelect.value] || {}; return localPlugins.value[currentSelect.value] || {};
}); });
const openPlugin = ({ cmd, code }) => {
console.log(pluginDetail.value);
window.rubick.openPlugin(
JSON.parse(
JSON.stringify({
...pluginDetail.value,
cmd,
ext: {
code,
type: "text",
payload: null
}
})
)
);
};
const readme = computed(() => { const readme = computed(() => {
if (!pluginDetail.value.name) return ""; if (!pluginDetail.value.name) return "";
const readmePath = path.resolve( const readmePath = path.resolve(
@@ -121,7 +149,7 @@ const readme = computed(() => {
return ""; return "";
}); });
const deletePlugin = async (plugin) => { const deletePlugin = async plugin => {
startUnDownload(plugin.name); startUnDownload(plugin.name);
await window.market.deletePlugin(plugin); await window.market.deletePlugin(plugin);
updateLocalPlugin(); updateLocalPlugin();
@@ -198,6 +226,15 @@ const deletePlugin = async (plugin) => {
.desc-item { .desc-item {
border-bottom: 1px solid #ddd; border-bottom: 1px solid #ddd;
padding: 10px 0; padding: 10px 0;
.ant-tag {
margin-top: 6px;
&.executable {
cursor: pointer;
&:hover {
transform: translateY(-2px);
}
}
}
.desc-title { .desc-title {
display: flex; display: flex;
align-items: center; align-items: center;

View File

@@ -333,6 +333,10 @@ const { shortCut, common, local, global } = toRefs(state);
font-weight: lighter; font-weight: lighter;
margin-top: 10px; margin-top: 10px;
position: relative; position: relative;
:deep(.ant-input) {
color: #6c9fe2;
font-weight: lighter;
}
&.ant-input-affix-wrapper { &.ant-input-affix-wrapper {
display: flex; display: flex;
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "rubick", "name": "rubick",
"version": "2.0.3-beta.1", "version": "2.0.3-beta.3",
"author": "muwoo <2424880409@qq.com>", "author": "muwoo <2424880409@qq.com>",
"private": true, "private": true,
"scripts": { "scripts": {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1 +1 @@
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="favicon.ico"><title>feature</title><link href="css/app.efef6e76.css" rel="preload" as="style"><link href="js/app.b6f0fed9.js" rel="preload" as="script"><link href="js/chunk-vendors.335eb4e0.js" rel="preload" as="script"><link href="css/app.efef6e76.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but feature doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.335eb4e0.js"></script><script src="js/app.b6f0fed9.js"></script></body></html> <!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="favicon.ico"><title>feature</title><link href="css/app.08793469.css" rel="preload" as="style"><link href="js/app.186e487c.js" rel="preload" as="script"><link href="js/chunk-vendors.68ebee8c.js" rel="preload" as="script"><link href="css/app.08793469.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but feature doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.68ebee8c.js"></script><script src="js/app.186e487c.js"></script></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -4,7 +4,7 @@ const os = require("os");
const ipcSendSync = (type, data) => { const ipcSendSync = (type, data) => {
const returnValue = ipcRenderer.sendSync("msg-trigger", { const returnValue = ipcRenderer.sendSync("msg-trigger", {
type, type,
data, data
}); });
if (returnValue instanceof Error) throw returnValue; if (returnValue instanceof Error) throw returnValue;
return returnValue; return returnValue;
@@ -13,7 +13,7 @@ const ipcSendSync = (type, data) => {
const ipcSend = (type, data) => { const ipcSend = (type, data) => {
ipcRenderer.send("msg-trigger", { ipcRenderer.send("msg-trigger", {
type, type,
data, data
}); });
}; };
@@ -30,7 +30,9 @@ window.rubick = {
onPluginOut(cb) { onPluginOut(cb) {
typeof cb === "function" && (window.rubick.hooks.onPluginOut = cb); typeof cb === "function" && (window.rubick.hooks.onPluginOut = cb);
}, },
openPlugin(plugin) {
ipcSendSync("loadPlugin", plugin);
},
// 窗口交互 // 窗口交互
hideMainWindow() { hideMainWindow() {
ipcSendSync("hideMainWindow"); ipcSendSync("hideMainWindow");
@@ -49,7 +51,7 @@ window.rubick = {
(window.rubick.hooks.onSubInputChange = onChange); (window.rubick.hooks.onSubInputChange = onChange);
ipcSendSync("setSubInput", { ipcSendSync("setSubInput", {
placeholder, placeholder,
isFocus, isFocus
}); });
}, },
removeSubInput() { removeSubInput() {
@@ -74,15 +76,15 @@ window.rubick = {
copyText(text) { copyText(text) {
return ipcSendSync("copyText", { text }); return ipcSendSync("copyText", { text });
}, },
copyFile: (file) => { copyFile: file => {
return ipcSendSync("copyFile", { file }) return ipcSendSync("copyFile", { file });
}, },
db: { db: {
put: (data) => ipcSendSync("dbPut", { data }), put: data => ipcSendSync("dbPut", { data }),
get: (id) => ipcSendSync("dbGet", { id }), get: id => ipcSendSync("dbGet", { id }),
remove: (doc) => ipcSendSync("dbRemove", { doc }), remove: doc => ipcSendSync("dbRemove", { doc }),
bulkDocs: (docs) => ipcSendSync("dbBulkDocs", { docs }), bulkDocs: docs => ipcSendSync("dbBulkDocs", { docs }),
allDocs: (key) => ipcSendSync("dbAllDocs", { key }), allDocs: key => ipcSendSync("dbAllDocs", { key })
}, },
dbStorage: { dbStorage: {
setItem: (key, value) => { setItem: (key, value) => {
@@ -93,14 +95,14 @@ window.rubick = {
const res = ipcSendSync("dbPut", { data: target }); const res = ipcSendSync("dbPut", { data: target });
if (res.error) throw new Error(res.message); if (res.error) throw new Error(res.message);
}, },
getItem: (key) => { getItem: key => {
const res = ipcSendSync("dbGet", { id: key }); const res = ipcSendSync("dbGet", { id: key });
return res && "value" in res ? res.value : null; return res && "value" in res ? res.value : null;
}, },
removeItem: (key) => { removeItem: key => {
const res = ipcSendSync("dbGet", { id: key }); const res = ipcSendSync("dbGet", { id: key });
res && ipcSendSync("dbRemove", { doc: res }); res && ipcSendSync("dbRemove", { doc: res });
}, }
}, },
isDarkColors() { isDarkColors() {
return false; return false;
@@ -144,5 +146,5 @@ window.rubick = {
shellShowItemInFolder: path => { shellShowItemInFolder: path => {
ipcSend("shellShowItemInFolder", { path }); ipcSend("shellShowItemInFolder", { path });
}, }
}; };

View File

@@ -3,9 +3,11 @@ import path from "path";
import commonConst from "../../common/utils/commonConst"; import commonConst from "../../common/utils/commonConst";
import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/main"; import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/main";
const getRelativePath = (indexPath) => { const getRelativePath = indexPath => {
return commonConst.windows() ? indexPath.replace("file://", "") : indexPath.replace("file:", ""); return commonConst.windows()
} ? indexPath.replace("file://", "")
: indexPath.replace("file:", "");
};
const getPreloadPath = (plugin, pluginIndexPath) => { const getPreloadPath = (plugin, pluginIndexPath) => {
const { name, preload, tplPath, indexPath } = plugin; const { name, preload, tplPath, indexPath } = plugin;
@@ -54,8 +56,8 @@ export default () => {
devTools: true, devTools: true,
webviewTag: true, webviewTag: true,
preload, preload,
session: ses, session: ses
}, }
}); });
window.setBrowserView(view); window.setBrowserView(view);
view.webContents.loadURL(pluginIndexPath); view.webContents.loadURL(pluginIndexPath);
@@ -67,6 +69,25 @@ export default () => {
executeHooks("PluginReady", plugin.ext); executeHooks("PluginReady", plugin.ext);
window.webContents.executeJavaScript(`window.pluginLoaded()`); window.webContents.executeJavaScript(`window.pluginLoaded()`);
}); });
// 修复请求跨域问题
view.webContents.session.webRequest.onBeforeSendHeaders(
(details, callback) => {
callback({
requestHeaders: { referer: "*", ...details.requestHeaders }
});
}
);
view.webContents.session.webRequest.onHeadersReceived(
(details, callback) => {
callback({
responseHeaders: {
"Access-Control-Allow-Origin": ["*"],
...details.responseHeaders
}
});
}
);
}; };
const removeView = (window: BrowserWindow) => { const removeView = (window: BrowserWindow) => {
@@ -95,6 +116,6 @@ export default () => {
init, init,
getView, getView,
removeView, removeView,
executeHooks, executeHooks
}; };
}; };

View File

@@ -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";
@@ -37,7 +37,15 @@ export const API: any = {
return; return;
} }
}, },
openPlugin({ plugin }, window) {
loadPlugin({ data: plugin }, window) {
window.webContents.executeJavaScript(
`window.loadPlugin(${JSON.stringify(plugin)})`
);
API.openPlugin({ data: plugin }, window);
},
openPlugin({ data: plugin }, window) {
if (API.currentPlugin && API.currentPlugin.name === plugin.name) return; if (API.currentPlugin && API.currentPlugin.name === plugin.name) return;
window.setSize(window.getSize()[0], 60); window.setSize(window.getSize()[0], 60);
runnerInstance.removeView(window); runnerInstance.removeView(window);
@@ -45,7 +53,7 @@ export const API: any = {
API.currentPlugin = plugin; API.currentPlugin = plugin;
window.webContents.executeJavaScript( window.webContents.executeJavaScript(
`window.setCurrentPlugin(${JSON.stringify({ `window.setCurrentPlugin(${JSON.stringify({
currentPlugin: API.currentPlugin, currentPlugin: API.currentPlugin
})})` })})`
); );
window.show(); window.show();
@@ -86,7 +94,7 @@ export const API: any = {
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
})})` })})`
); );
}, },
@@ -106,7 +114,7 @@ export const API: any = {
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
})})` })})`
); );
}, },
@@ -121,7 +129,7 @@ export const API: any = {
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();
}, },
@@ -166,7 +174,7 @@ export const API: any = {
...API.currentPlugin, ...API.currentPlugin,
features: (() => { features: (() => {
let has = false; let has = false;
API.currentPlugin.features.some((feature) => { API.currentPlugin.features.some(feature => {
has = feature.code === data.feature.code; has = feature.code === data.feature.code;
return has; return has;
}); });
@@ -174,11 +182,11 @@ export const API: any = {
return [...API.currentPlugin.features, data.feature]; return [...API.currentPlugin.features, data.feature];
} }
return API.currentPlugin.features; return API.currentPlugin.features;
})(), })()
}; };
window.webContents.executeJavaScript( window.webContents.executeJavaScript(
`window.updatePlugin(${JSON.stringify({ `window.updatePlugin(${JSON.stringify({
currentPlugin: API.currentPlugin, currentPlugin: API.currentPlugin
})})` })})`
); );
return true; return true;
@@ -186,16 +194,16 @@ export const API: any = {
removeFeature({ data }, window) { removeFeature({ data }, window) {
API.currentPlugin = { API.currentPlugin = {
...API.currentPlugin, ...API.currentPlugin,
features: API.currentPlugin.features.filter((feature) => { features: API.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: API.currentPlugin
})})` })})`
); );
return true; return true;
@@ -207,12 +215,12 @@ export const API: any = {
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
}); });
} }
}, },
@@ -223,11 +231,11 @@ export const API: any = {
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, ...API.currentPlugin,
subInput: res, subInput: res
}, },
window.getBounds(), window.getBounds(),
view view
@@ -248,7 +256,7 @@ export const API: any = {
shellShowItemInFolder({ data }) { shellShowItemInFolder({ data }) {
shell.showItemInFolder(data.path); shell.showItemInFolder(data.path);
return true; return true;
}, }
}; };
export default (mainWindow: BrowserWindow) => { export default (mainWindow: BrowserWindow) => {

View File

@@ -11,7 +11,7 @@ import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/renderer";
const createPluginManager = (): any => { const createPluginManager = (): any => {
const pluginInstance = new PluginHandler({ const pluginInstance = new PluginHandler({
baseDir, baseDir
}); });
const state: any = reactive({ const state: any = reactive({
@@ -19,7 +19,7 @@ const createPluginManager = (): any => {
plugins: [], plugins: [],
localPlugins: [], localPlugins: [],
currentPlugin: {}, currentPlugin: {},
pluginLoading: false, pluginLoading: false
}); });
const appList = ref([]); const appList = ref([]);
@@ -28,25 +28,29 @@ const createPluginManager = (): any => {
appList.value = await appSearch(nativeImage); appList.value = await appSearch(nativeImage);
}; };
const openPlugin = (plugin) => { const loadPlugin = plugin => {
state.pluginLoading = true;
state.currentPlugin = plugin;
};
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) { if (state.currentPlugin && state.currentPlugin.name === plugin.name) {
return; return;
} }
state.pluginLoading = true; loadPlugin(plugin);
state.currentPlugin = plugin;
ipcRenderer.sendSync("msg-trigger", { ipcRenderer.sendSync("msg-trigger", {
type: "openPlugin", type: "openPlugin",
plugin: JSON.parse( data: JSON.parse(
JSON.stringify({ JSON.stringify({
...plugin, ...plugin,
ext: plugin.ext || { ext: plugin.ext || {
code: plugin.feature.code, code: plugin.feature.code,
type: plugin.cmd.type || "text", type: plugin.cmd.type || "text",
payload: null, payload: null
}, }
}) })
), )
}); });
setSearchValue(""); setSearchValue("");
} }
@@ -57,12 +61,17 @@ const createPluginManager = (): any => {
const { searchValue, onSearch, setSearchValue, placeholder } = const { searchValue, onSearch, setSearchValue, placeholder } =
searchManager(); searchManager();
const { options, searchFocus, clipboardFile, clearClipboardFile, readClipboardContent } = const {
optionsManager({ options,
searchFocus,
clipboardFile,
clearClipboardFile,
readClipboardContent
} = optionsManager({
searchValue, searchValue,
appList, appList,
openPlugin, openPlugin,
currentPlugin: toRefs(state).currentPlugin, currentPlugin: toRefs(state).currentPlugin
}); });
// plugin operation // plugin operation
const getPluginInfo = async ({ pluginName, pluginPath }) => { const getPluginInfo = async ({ pluginName, pluginPath }) => {
@@ -75,11 +84,11 @@ const createPluginManager = (): any => {
icon: pluginInfo.logo, icon: pluginInfo.logo,
indexPath: commonConst.dev() indexPath: commonConst.dev()
? "http://localhost:8081/#/" ? "http://localhost:8081/#/"
: `file://${path.join(pluginPath, "../", pluginInfo.main)}`, : `file://${path.join(pluginPath, "../", pluginInfo.main)}`
}; };
}; };
const changeSelect = (select) => { const changeSelect = select => {
state.currentPlugin = select; state.currentPlugin = select;
}; };
@@ -90,6 +99,9 @@ const createPluginManager = (): any => {
const removePlugin = (plugin: any) => { const removePlugin = (plugin: any) => {
// todo // todo
}; };
window.loadPlugin = plugin => loadPlugin(plugin);
window.updatePlugin = ({ currentPlugin }: any) => { window.updatePlugin = ({ currentPlugin }: any) => {
state.currentPlugin = currentPlugin; state.currentPlugin = currentPlugin;
remote.getGlobal("LOCAL_PLUGINS").updatePlugin(currentPlugin); remote.getGlobal("LOCAL_PLUGINS").updatePlugin(currentPlugin);
@@ -125,7 +137,7 @@ const createPluginManager = (): any => {
searchFocus, searchFocus,
clipboardFile, clipboardFile,
clearClipboardFile, clearClipboardFile,
readClipboardContent, readClipboardContent
}; };
}; };

View File

@@ -1,22 +1,23 @@
/* eslint-disable */ /* eslint-disable */
declare module '*.vue' { declare module "*.vue" {
import type { DefineComponent } from 'vue' import type { DefineComponent } from "vue";
const component: DefineComponent<{}, {}, any> const component: DefineComponent<{}, {}, any>;
export default component export default component;
} }
declare module 'main' { declare module "main" {
export function main (): any export function main(): any;
} }
declare const __static: string declare const __static: string;
declare module 'lodash.throttle' declare module "lodash.throttle";
interface Window { interface Window {
setSubInput: ({ placeholder }: { placeholder: string }) => void; setSubInput: ({ placeholder }: { placeholder: string }) => void;
setSubInputValue: ({ value }: { value: string }) => void; setSubInputValue: ({ value }: { value: string }) => void;
removeSubInput: () => void; removeSubInput: () => void;
loadPlugin: (plugin: any) => void;
updatePlugin: (plugin: any) => void; updatePlugin: (plugin: any) => void;
initRubick: () => void; initRubick: () => void;
setCurrentPlugin: (plugin: any) => void; setCurrentPlugin: (plugin: any) => void;