mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-28 08:22:48 +08:00
✨ 支持 setSubInput API
This commit is contained in:
parent
1353c440aa
commit
a9827c6db1
@ -52,9 +52,9 @@ const store = useStore();
|
||||
const init = () => store.dispatch("init");
|
||||
init();
|
||||
|
||||
(window as any).rubick.onPluginEnter((res) => {
|
||||
console.log(res);
|
||||
})
|
||||
window.rubick.setSubInput((data: any) => {
|
||||
console.log(data);
|
||||
}, "插件市场");
|
||||
</script>
|
||||
<style lang="less">
|
||||
* {
|
||||
|
4
feature/src/shims-vue.d.ts
vendored
4
feature/src/shims-vue.d.ts
vendored
@ -6,3 +6,7 @@ declare module '*.vue' {
|
||||
}
|
||||
|
||||
declare module 'axios'
|
||||
|
||||
interface Window {
|
||||
rubick: any
|
||||
}
|
||||
|
@ -37,7 +37,8 @@ window.rubick = {
|
||||
ipcSendSync("setExpendHeight", height);
|
||||
},
|
||||
setSubInput(onChange, placeholder = "", isFocus) {
|
||||
typeof cb === "function" && (window.rubick.hooks.onSubInputChange = onChange);
|
||||
typeof onChange === "function" &&
|
||||
(window.rubick.hooks.onSubInputChange = onChange);
|
||||
ipcSendSync("setSubInput", {
|
||||
placeholder,
|
||||
isFocus,
|
||||
|
@ -38,8 +38,8 @@ export default () => {
|
||||
view.setAutoResize({ width: true });
|
||||
window.setSize(800, 660);
|
||||
view.webContents.openDevTools();
|
||||
executeHooks(plugin.ext, "PluginEnter");
|
||||
executeHooks(plugin.ext, "PluginReady");
|
||||
executeHooks("PluginEnter", plugin.ext);
|
||||
executeHooks("PluginReady", plugin.ext);
|
||||
});
|
||||
};
|
||||
|
||||
@ -67,5 +67,6 @@ export default () => {
|
||||
init,
|
||||
getView,
|
||||
removeView,
|
||||
executeHooks,
|
||||
};
|
||||
};
|
||||
|
@ -1,8 +1,16 @@
|
||||
import { BrowserWindow, ipcMain, dialog } from "electron";
|
||||
import { BrowserWindow, ipcMain, dialog, webContents } from "electron";
|
||||
import { runner } from "../browsers";
|
||||
|
||||
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 = {
|
||||
openPlugin({ plugin }, window) {
|
||||
runnerInstance.removeView(window);
|
||||
@ -24,8 +32,15 @@ const API: any = {
|
||||
const targetHeight = height;
|
||||
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) => {
|
||||
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.sender.send(`msg-back-${arg.type}`, data);
|
||||
});
|
||||
|
@ -8,6 +8,7 @@
|
||||
@openMenu="openMenu"
|
||||
@changeSelect="changeSelect"
|
||||
:searchValue="searchValue"
|
||||
:placeholder="placeholder"
|
||||
/>
|
||||
</div>
|
||||
<Result
|
||||
@ -36,6 +37,7 @@ const {
|
||||
changeSelect,
|
||||
openPlugin,
|
||||
currentPlugin,
|
||||
placeholder,
|
||||
} = createPluginManager();
|
||||
|
||||
initPlugins();
|
||||
@ -89,5 +91,4 @@ const openMenu = () => {
|
||||
width: 0;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
@ -4,12 +4,12 @@
|
||||
<a-input
|
||||
id="search"
|
||||
class="main-input"
|
||||
placeholder="Hi, Rubick2"
|
||||
@input="(e) => changeValue(e)"
|
||||
@keydown.down="() => emit('changeCurrent', 1)"
|
||||
@keydown.up="() => emit('changeCurrent', -1)"
|
||||
@keydown="checkNeedInit"
|
||||
:value="searchValue"
|
||||
:placeholder="placeholder || 'Hi, Rubick2'"
|
||||
>
|
||||
<template #suffix>
|
||||
<div @click="() => emit('openMenu')" class="suffix-tool" >
|
||||
@ -31,6 +31,10 @@ const props = defineProps({
|
||||
type: [String, Number],
|
||||
default: "",
|
||||
},
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
currentPlugin: {},
|
||||
});
|
||||
|
||||
|
@ -47,10 +47,11 @@ const createPluginManager = (): any => {
|
||||
// @ts-ignore
|
||||
// document.getElementById("search").value = "";
|
||||
// state.searchValue = "";
|
||||
setSearchValue("");
|
||||
}
|
||||
};
|
||||
|
||||
const { searchValue, onSearch } = searchManager();
|
||||
const { searchValue, onSearch, setSearchValue, placeholder } = searchManager();
|
||||
const { options } = optionsManager({
|
||||
searchValue,
|
||||
baseDir,
|
||||
@ -91,6 +92,7 @@ const createPluginManager = (): any => {
|
||||
changeSelect,
|
||||
options,
|
||||
searchValue,
|
||||
placeholder,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -1,19 +1,34 @@
|
||||
import { reactive, toRefs } from "vue";
|
||||
import {ipcRenderer} from "electron";
|
||||
|
||||
const searchManager = () => {
|
||||
const state = reactive({
|
||||
searchValue: "",
|
||||
placeholder: "",
|
||||
});
|
||||
|
||||
// search Input operation
|
||||
const onSearch = (e) => {
|
||||
const value = e.target.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 {
|
||||
...toRefs(state),
|
||||
onSearch,
|
||||
setSearchValue,
|
||||
};
|
||||
};
|
||||
|
||||
|
4
src/renderer/shims-vue.d.ts
vendored
4
src/renderer/shims-vue.d.ts
vendored
@ -12,3 +12,7 @@ declare module 'main' {
|
||||
declare const __static: string
|
||||
|
||||
declare module 'lodash.throttle'
|
||||
|
||||
interface Window {
|
||||
setSubInput: ({ placeholder }: { placeholder: string }) => void;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user