mirror of
https://github.com/rubickCenter/rubick
synced 2026-01-12 15:28:32 +08:00
🔨 cherry pick
This commit is contained in:
@@ -3,9 +3,11 @@ import path from "path";
|
||||
import commonConst from "../../common/utils/commonConst";
|
||||
import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/main";
|
||||
|
||||
const getRelativePath = (indexPath) => {
|
||||
return commonConst.windows() ? indexPath.replace("file://", "") : indexPath.replace("file:", "");
|
||||
}
|
||||
const getRelativePath = indexPath => {
|
||||
return commonConst.windows()
|
||||
? indexPath.replace("file://", "")
|
||||
: indexPath.replace("file:", "");
|
||||
};
|
||||
|
||||
const getPreloadPath = (plugin, pluginIndexPath) => {
|
||||
const { name, preload, tplPath, indexPath } = plugin;
|
||||
@@ -54,8 +56,8 @@ export default () => {
|
||||
devTools: true,
|
||||
webviewTag: true,
|
||||
preload,
|
||||
session: ses,
|
||||
},
|
||||
session: ses
|
||||
}
|
||||
});
|
||||
window.setBrowserView(view);
|
||||
view.webContents.loadURL(pluginIndexPath);
|
||||
@@ -67,6 +69,25 @@ export default () => {
|
||||
executeHooks("PluginReady", plugin.ext);
|
||||
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) => {
|
||||
@@ -95,6 +116,6 @@ export default () => {
|
||||
init,
|
||||
getView,
|
||||
removeView,
|
||||
executeHooks,
|
||||
executeHooks
|
||||
};
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
Notification,
|
||||
nativeImage,
|
||||
clipboard,
|
||||
shell,
|
||||
shell
|
||||
} from "electron";
|
||||
import { runner, detach } from "../browsers";
|
||||
import fs from "fs";
|
||||
@@ -37,7 +37,15 @@ export const API: any = {
|
||||
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;
|
||||
window.setSize(window.getSize()[0], 60);
|
||||
runnerInstance.removeView(window);
|
||||
@@ -45,7 +53,7 @@ export const API: any = {
|
||||
API.currentPlugin = plugin;
|
||||
window.webContents.executeJavaScript(
|
||||
`window.setCurrentPlugin(${JSON.stringify({
|
||||
currentPlugin: API.currentPlugin,
|
||||
currentPlugin: API.currentPlugin
|
||||
})})`
|
||||
);
|
||||
window.show();
|
||||
@@ -86,7 +94,7 @@ export const API: any = {
|
||||
if (!originWindow) return;
|
||||
originWindow.webContents.executeJavaScript(
|
||||
`window.setSubInput(${JSON.stringify({
|
||||
placeholder: data.placeholder,
|
||||
placeholder: data.placeholder
|
||||
})})`
|
||||
);
|
||||
},
|
||||
@@ -106,7 +114,7 @@ export const API: any = {
|
||||
if (!originWindow) return;
|
||||
originWindow.webContents.executeJavaScript(
|
||||
`window.setSubInputValue(${JSON.stringify({
|
||||
value: data.text,
|
||||
value: data.text
|
||||
})})`
|
||||
);
|
||||
},
|
||||
@@ -121,7 +129,7 @@ export const API: any = {
|
||||
const notify = new Notification({
|
||||
title: plugin.pluginName,
|
||||
body,
|
||||
icon: plugin.logo,
|
||||
icon: plugin.logo
|
||||
});
|
||||
notify.show();
|
||||
},
|
||||
@@ -166,7 +174,7 @@ export const API: any = {
|
||||
...API.currentPlugin,
|
||||
features: (() => {
|
||||
let has = false;
|
||||
API.currentPlugin.features.some((feature) => {
|
||||
API.currentPlugin.features.some(feature => {
|
||||
has = feature.code === data.feature.code;
|
||||
return has;
|
||||
});
|
||||
@@ -174,11 +182,11 @@ export const API: any = {
|
||||
return [...API.currentPlugin.features, data.feature];
|
||||
}
|
||||
return API.currentPlugin.features;
|
||||
})(),
|
||||
})()
|
||||
};
|
||||
window.webContents.executeJavaScript(
|
||||
`window.updatePlugin(${JSON.stringify({
|
||||
currentPlugin: API.currentPlugin,
|
||||
currentPlugin: API.currentPlugin
|
||||
})})`
|
||||
);
|
||||
return true;
|
||||
@@ -186,16 +194,16 @@ export const API: any = {
|
||||
removeFeature({ data }, window) {
|
||||
API.currentPlugin = {
|
||||
...API.currentPlugin,
|
||||
features: API.currentPlugin.features.filter((feature) => {
|
||||
features: API.currentPlugin.features.filter(feature => {
|
||||
if (data.code.type) {
|
||||
return feature.code.type !== data.code.type;
|
||||
}
|
||||
return feature.code !== data.code;
|
||||
}),
|
||||
})
|
||||
};
|
||||
window.webContents.executeJavaScript(
|
||||
`window.updatePlugin(${JSON.stringify({
|
||||
currentPlugin: API.currentPlugin,
|
||||
currentPlugin: API.currentPlugin
|
||||
})})`
|
||||
);
|
||||
return true;
|
||||
@@ -207,12 +215,12 @@ export const API: any = {
|
||||
runnerInstance.getView().webContents.sendInputEvent({
|
||||
type: "keyDown",
|
||||
modifiers,
|
||||
keyCode: code,
|
||||
keyCode: code
|
||||
});
|
||||
} else {
|
||||
runnerInstance.getView().webContents.sendInputEvent({
|
||||
type: "keyDown",
|
||||
keyCode: code,
|
||||
keyCode: code
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -223,11 +231,11 @@ export const API: any = {
|
||||
window.setBrowserView(null);
|
||||
window.webContents
|
||||
.executeJavaScript(`window.getMainInputInfo()`)
|
||||
.then((res) => {
|
||||
.then(res => {
|
||||
detachInstance.init(
|
||||
{
|
||||
...API.currentPlugin,
|
||||
subInput: res,
|
||||
subInput: res
|
||||
},
|
||||
window.getBounds(),
|
||||
view
|
||||
|
||||
@@ -11,7 +11,7 @@ import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/renderer";
|
||||
|
||||
const createPluginManager = (): any => {
|
||||
const pluginInstance = new PluginHandler({
|
||||
baseDir,
|
||||
baseDir
|
||||
});
|
||||
|
||||
const state: any = reactive({
|
||||
@@ -19,7 +19,7 @@ const createPluginManager = (): any => {
|
||||
plugins: [],
|
||||
localPlugins: [],
|
||||
currentPlugin: {},
|
||||
pluginLoading: false,
|
||||
pluginLoading: false
|
||||
});
|
||||
|
||||
const appList = ref([]);
|
||||
@@ -28,25 +28,29 @@ const createPluginManager = (): any => {
|
||||
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 (state.currentPlugin && state.currentPlugin.name === plugin.name) {
|
||||
return;
|
||||
}
|
||||
state.pluginLoading = true;
|
||||
state.currentPlugin = plugin;
|
||||
loadPlugin(plugin);
|
||||
ipcRenderer.sendSync("msg-trigger", {
|
||||
type: "openPlugin",
|
||||
plugin: JSON.parse(
|
||||
data: JSON.parse(
|
||||
JSON.stringify({
|
||||
...plugin,
|
||||
ext: plugin.ext || {
|
||||
code: plugin.feature.code,
|
||||
type: plugin.cmd.type || "text",
|
||||
payload: null,
|
||||
},
|
||||
payload: null
|
||||
}
|
||||
})
|
||||
),
|
||||
)
|
||||
});
|
||||
setSearchValue("");
|
||||
}
|
||||
@@ -57,13 +61,18 @@ const createPluginManager = (): any => {
|
||||
|
||||
const { searchValue, onSearch, setSearchValue, placeholder } =
|
||||
searchManager();
|
||||
const { options, searchFocus, clipboardFile, clearClipboardFile, readClipboardContent } =
|
||||
optionsManager({
|
||||
searchValue,
|
||||
appList,
|
||||
openPlugin,
|
||||
currentPlugin: toRefs(state).currentPlugin,
|
||||
});
|
||||
const {
|
||||
options,
|
||||
searchFocus,
|
||||
clipboardFile,
|
||||
clearClipboardFile,
|
||||
readClipboardContent
|
||||
} = optionsManager({
|
||||
searchValue,
|
||||
appList,
|
||||
openPlugin,
|
||||
currentPlugin: toRefs(state).currentPlugin
|
||||
});
|
||||
// plugin operation
|
||||
const getPluginInfo = async ({ pluginName, pluginPath }) => {
|
||||
const pluginInfo = await pluginInstance.getAdapterInfo(
|
||||
@@ -75,11 +84,11 @@ const createPluginManager = (): any => {
|
||||
icon: pluginInfo.logo,
|
||||
indexPath: commonConst.dev()
|
||||
? "http://localhost:8081/#/"
|
||||
: `file://${path.join(pluginPath, "../", pluginInfo.main)}`,
|
||||
: `file://${path.join(pluginPath, "../", pluginInfo.main)}`
|
||||
};
|
||||
};
|
||||
|
||||
const changeSelect = (select) => {
|
||||
const changeSelect = select => {
|
||||
state.currentPlugin = select;
|
||||
};
|
||||
|
||||
@@ -90,6 +99,9 @@ const createPluginManager = (): any => {
|
||||
const removePlugin = (plugin: any) => {
|
||||
// todo
|
||||
};
|
||||
|
||||
window.loadPlugin = plugin => loadPlugin(plugin);
|
||||
|
||||
window.updatePlugin = ({ currentPlugin }: any) => {
|
||||
state.currentPlugin = currentPlugin;
|
||||
remote.getGlobal("LOCAL_PLUGINS").updatePlugin(currentPlugin);
|
||||
@@ -125,7 +137,7 @@ const createPluginManager = (): any => {
|
||||
searchFocus,
|
||||
clipboardFile,
|
||||
clearClipboardFile,
|
||||
readClipboardContent,
|
||||
readClipboardContent
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
17
src/renderer/shims-vue.d.ts
vendored
17
src/renderer/shims-vue.d.ts
vendored
@@ -1,22 +1,23 @@
|
||||
/* eslint-disable */
|
||||
declare module '*.vue' {
|
||||
import type { DefineComponent } from 'vue'
|
||||
const component: DefineComponent<{}, {}, any>
|
||||
export default component
|
||||
declare module "*.vue" {
|
||||
import type { DefineComponent } from "vue";
|
||||
const component: DefineComponent<{}, {}, any>;
|
||||
export default component;
|
||||
}
|
||||
|
||||
declare module 'main' {
|
||||
export function main (): any
|
||||
declare module "main" {
|
||||
export function main(): any;
|
||||
}
|
||||
|
||||
declare const __static: string
|
||||
declare const __static: string;
|
||||
|
||||
declare module 'lodash.throttle'
|
||||
declare module "lodash.throttle";
|
||||
|
||||
interface Window {
|
||||
setSubInput: ({ placeholder }: { placeholder: string }) => void;
|
||||
setSubInputValue: ({ value }: { value: string }) => void;
|
||||
removeSubInput: () => void;
|
||||
loadPlugin: (plugin: any) => void;
|
||||
updatePlugin: (plugin: any) => void;
|
||||
initRubick: () => void;
|
||||
setCurrentPlugin: (plugin: any) => void;
|
||||
|
||||
Reference in New Issue
Block a user