支持 setSubInput API

This commit is contained in:
muwoo 2021-12-07 11:19:08 +08:00
parent 1353c440aa
commit a9827c6db1
10 changed files with 60 additions and 13 deletions

View File

@ -52,9 +52,9 @@ const store = useStore();
const init = () => store.dispatch("init"); const init = () => store.dispatch("init");
init(); init();
(window as any).rubick.onPluginEnter((res) => { window.rubick.setSubInput((data: any) => {
console.log(res); console.log(data);
}) }, "插件市场");
</script> </script>
<style lang="less"> <style lang="less">
* { * {

View File

@ -6,3 +6,7 @@ declare module '*.vue' {
} }
declare module 'axios' declare module 'axios'
interface Window {
rubick: any
}

View File

@ -37,7 +37,8 @@ window.rubick = {
ipcSendSync("setExpendHeight", height); ipcSendSync("setExpendHeight", height);
}, },
setSubInput(onChange, placeholder = "", isFocus) { setSubInput(onChange, placeholder = "", isFocus) {
typeof cb === "function" && (window.rubick.hooks.onSubInputChange = onChange); typeof onChange === "function" &&
(window.rubick.hooks.onSubInputChange = onChange);
ipcSendSync("setSubInput", { ipcSendSync("setSubInput", {
placeholder, placeholder,
isFocus, isFocus,

View File

@ -38,8 +38,8 @@ export default () => {
view.setAutoResize({ width: true }); view.setAutoResize({ width: true });
window.setSize(800, 660); window.setSize(800, 660);
view.webContents.openDevTools(); view.webContents.openDevTools();
executeHooks(plugin.ext, "PluginEnter"); executeHooks("PluginEnter", plugin.ext);
executeHooks(plugin.ext, "PluginReady"); executeHooks("PluginReady", plugin.ext);
}); });
}; };
@ -67,5 +67,6 @@ export default () => {
init, init,
getView, getView,
removeView, removeView,
executeHooks,
}; };
}; };

View File

@ -1,8 +1,16 @@
import { BrowserWindow, ipcMain, dialog } from "electron"; import { BrowserWindow, ipcMain, dialog, webContents } from "electron";
import { runner } from "../browsers"; import { runner } from "../browsers";
const runnerInstance = runner(); const runnerInstance = runner();
function getWorkWebContentsBySender(sender, mainWindow) {
const window = BrowserWindow.fromWebContents(sender);
console.log(window);
if (!window) return null;
return window.webContents;
}
const API: any = { const API: any = {
openPlugin({ plugin }, window) { openPlugin({ plugin }, window) {
runnerInstance.removeView(window); runnerInstance.removeView(window);
@ -24,8 +32,15 @@ const API: any = {
const targetHeight = height; const targetHeight = height;
window.setSize(window.getSize()[0], targetHeight); window.setSize(window.getSize()[0], targetHeight);
}, },
setSubInput() { setSubInput({ data }, window) {
window.webContents.executeJavaScript(
`window.setSubInput(${JSON.stringify({
placeholder: data.placeholder,
})})`
);
},
sendSubInputChangeEvent({ data }) {
runnerInstance.executeHooks("SubInputChange", data);
}, },
}; };
@ -34,7 +49,7 @@ export default (mainWindow: BrowserWindow) => {
ipcMain.on("msg-trigger", async (event, arg) => { ipcMain.on("msg-trigger", async (event, arg) => {
const window = arg.winId ? BrowserWindow.fromId(arg.winId) : mainWindow; const window = arg.winId ? BrowserWindow.fromId(arg.winId) : mainWindow;
const data = await API[arg.type](arg, window); const data = await API[arg.type](arg, window, event);
event.returnValue = data; event.returnValue = data;
// event.sender.send(`msg-back-${arg.type}`, data); // event.sender.send(`msg-back-${arg.type}`, data);
}); });

View File

@ -8,6 +8,7 @@
@openMenu="openMenu" @openMenu="openMenu"
@changeSelect="changeSelect" @changeSelect="changeSelect"
:searchValue="searchValue" :searchValue="searchValue"
:placeholder="placeholder"
/> />
</div> </div>
<Result <Result
@ -36,6 +37,7 @@ const {
changeSelect, changeSelect,
openPlugin, openPlugin,
currentPlugin, currentPlugin,
placeholder,
} = createPluginManager(); } = createPluginManager();
initPlugins(); initPlugins();
@ -89,5 +91,4 @@ const openMenu = () => {
width: 0; width: 0;
} }
} }
</style> </style>

View File

@ -4,12 +4,12 @@
<a-input <a-input
id="search" id="search"
class="main-input" class="main-input"
placeholder="Hi, Rubick2"
@input="(e) => changeValue(e)" @input="(e) => changeValue(e)"
@keydown.down="() => emit('changeCurrent', 1)" @keydown.down="() => emit('changeCurrent', 1)"
@keydown.up="() => emit('changeCurrent', -1)" @keydown.up="() => emit('changeCurrent', -1)"
@keydown="checkNeedInit" @keydown="checkNeedInit"
:value="searchValue" :value="searchValue"
:placeholder="placeholder || 'Hi, Rubick2'"
> >
<template #suffix> <template #suffix>
<div @click="() => emit('openMenu')" class="suffix-tool" > <div @click="() => emit('openMenu')" class="suffix-tool" >
@ -31,6 +31,10 @@ const props = defineProps({
type: [String, Number], type: [String, Number],
default: "", default: "",
}, },
placeholder: {
type: String,
default: "",
},
currentPlugin: {}, currentPlugin: {},
}); });

View File

@ -47,10 +47,11 @@ const createPluginManager = (): any => {
// @ts-ignore // @ts-ignore
// document.getElementById("search").value = ""; // document.getElementById("search").value = "";
// state.searchValue = ""; // state.searchValue = "";
setSearchValue("");
} }
}; };
const { searchValue, onSearch } = searchManager(); const { searchValue, onSearch, setSearchValue, placeholder } = searchManager();
const { options } = optionsManager({ const { options } = optionsManager({
searchValue, searchValue,
baseDir, baseDir,
@ -91,6 +92,7 @@ const createPluginManager = (): any => {
changeSelect, changeSelect,
options, options,
searchValue, searchValue,
placeholder,
}; };
}; };

View File

@ -1,19 +1,34 @@
import { reactive, toRefs } from "vue"; import { reactive, toRefs } from "vue";
import {ipcRenderer} from "electron";
const searchManager = () => { const searchManager = () => {
const state = reactive({ const state = reactive({
searchValue: "", searchValue: "",
placeholder: "",
}); });
// search Input operation // search Input operation
const onSearch = (e) => { const onSearch = (e) => {
const value = e.target.value; const value = e.target.value;
state.searchValue = value; state.searchValue = value;
ipcRenderer.sendSync("msg-trigger", {
type: "sendSubInputChangeEvent",
data: value,
});
};
const setSearchValue = (value: string) => {
state.searchValue = value;
};
window.setSubInput = ({ placeholder }: { placeholder: string }) => {
state.placeholder = placeholder;
}; };
return { return {
...toRefs(state), ...toRefs(state),
onSearch, onSearch,
setSearchValue,
}; };
}; };

View File

@ -12,3 +12,7 @@ declare module 'main' {
declare const __static: string declare const __static: string
declare module 'lodash.throttle' declare module 'lodash.throttle'
interface Window {
setSubInput: ({ placeholder }: { placeholder: string }) => void;
}