From 6da9e2fe9c7c0b39ac8b965e7dfa5505b9f5801d Mon Sep 17 00:00:00 2001
From: muwoo <2424880409@qq.com>
Date: Mon, 23 Oct 2023 15:30:15 +0800
Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=8F=92=E4=BB=B6=E9=80=82?=
=?UTF-8?q?=E9=85=8D=E7=AA=97=E5=8F=A3=E7=BC=A9=E6=94=BE=EF=BC=9B=E4=BF=AE?=
=?UTF-8?q?=E5=A4=8D=E7=AA=97=E5=8F=A3=E5=B0=BA=E5=AF=B8=E8=B0=83=E6=95=B4?=
=?UTF-8?q?=E7=9A=84bug=EF=BC=9B=E6=96=B0=E5=A2=9E=20createBrowserWindow?=
=?UTF-8?q?=E3=80=81getCursorScreenPoint=E3=80=81getDisplayNearestPoint?=
=?UTF-8?q?=E3=80=81outPlugin=20API?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 2 +-
public/preload.js | 61 ++++++++++++++++++++++++-
public/tpl/index.html | 2 +-
public/tpl/js/app.71511ff3.js | 1 +
public/tpl/js/app.bdf36c39.js | 1 -
src/core/screen-capture/index.ts | 1 -
src/main/browsers/detach.ts | 1 +
src/main/browsers/main.ts | 6 ++-
src/main/browsers/runner.ts | 4 +-
src/renderer/App.vue | 7 ++-
src/renderer/plugins-manager/index.ts | 2 +
src/renderer/plugins-manager/options.ts | 1 +
tpl/src/App.vue | 4 ++
13 files changed, 83 insertions(+), 10 deletions(-)
create mode 100644 public/tpl/js/app.71511ff3.js
delete mode 100644 public/tpl/js/app.bdf36c39.js
diff --git a/package.json b/package.json
index d871816..a698d8d 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "rubick",
- "version": "4.0.9",
+ "version": "4.0.10",
"author": "muwoo <2424880409@qq.com>",
"private": true,
"scripts": {
diff --git a/public/preload.js b/public/preload.js
index 438ffdb..f6847ed 100644
--- a/public/preload.js
+++ b/public/preload.js
@@ -1,5 +1,11 @@
const { ipcRenderer, shell } = require('electron');
+const { BrowserWindow, nativeTheme, screen, app } = require('@electron/remote');
const os = require('os');
+const path = require('path');
+
+const appPath = app.getPath('userData');
+
+const baseDir = path.join(appPath, './rubick-plugins');
const ipcSendSync = (type, data) => {
const returnValue = ipcRenderer.sendSync('msg-trigger', {
@@ -19,9 +25,9 @@ const ipcSend = (type, data) => {
window.rubick = {
hooks: {},
+ __event__: {},
// 事件
onPluginEnter(cb) {
- console.log(window.rubick.hooks);
typeof cb === 'function' && (window.rubick.hooks.onPluginEnter = cb);
},
onPluginReady(cb) {
@@ -178,4 +184,57 @@ window.rubick = {
simulateKeyboardTap: (key, ...modifier) => {
ipcSend('simulateKeyboardTap', { key, modifier });
},
+
+ getCursorScreenPoint: () => {
+ return screen.getCursorScreenPoint();
+ },
+
+ getDisplayNearestPoint: (point) => {
+ return screen.getDisplayNearestPoint(point);
+ },
+
+ outPlugin: () => {
+ return ipcSend('removePlugin');
+ },
+
+ createBrowserWindow: (url, options, callback) => {
+ const winUrl = path.resolve(baseDir, 'node_modules', options.name);
+ const winIndex = `file://${path.join(winUrl, './', url || '')}`;
+ const preloadPath = path.join(
+ winUrl,
+ './',
+ options.webPreferences.preload || ''
+ );
+ let win = new BrowserWindow({
+ useContentSize: true,
+ resizable: true,
+ title: '拉比克',
+ show: false,
+ backgroundColor: nativeTheme.shouldUseDarkColors ? '#1c1c28' : '#fff',
+ ...options,
+ webPreferences: {
+ webSecurity: false,
+ backgroundThrottling: false,
+ contextIsolation: false,
+ webviewTag: true,
+ nodeIntegration: true,
+ spellcheck: false,
+ partition: null,
+ ...(options.webPreferences || {}),
+ preload: preloadPath,
+ },
+ });
+ win.loadURL(winIndex);
+
+ win.on('closed', () => {
+ win = undefined;
+ });
+ win.once('ready-to-show', () => {
+ win.show();
+ });
+ win.webContents.on('dom-ready', () => {
+ callback && callback();
+ });
+ return win;
+ },
};
diff --git a/public/tpl/index.html b/public/tpl/index.html
index 92602ba..88ad0ff 100644
--- a/public/tpl/index.html
+++ b/public/tpl/index.html
@@ -1 +1 @@
-
tpl
\ No newline at end of file
+tpl
\ No newline at end of file
diff --git a/public/tpl/js/app.71511ff3.js b/public/tpl/js/app.71511ff3.js
new file mode 100644
index 0000000..011e63b
--- /dev/null
+++ b/public/tpl/js/app.71511ff3.js
@@ -0,0 +1 @@
+(function(e){function t(t){for(var r,a,s=t[0],u=t[1],i=t[2],p=0,d=[];p{const o=window.exports[e];"none"!==o.mode?t.push({name:o.mode,params:{code:e,type:n,payload:r}}):o.args.enter&&o.args.enter({code:e,type:n,payload:r})}),(e,t)=>{const n=Object(r["w"])("router-view");return Object(r["r"])(),Object(r["d"])(n)}}};n("0378");const a=c;var s=a;const u={class:"list-container"},i={class:"options"},l=["onClick"],p=["src"],d={class:"content"},b={class:"title"},v={class:"desc"};var f=Object(r["h"])({__name:"List",setup(e){const{ipcRenderer:t}=window.require("electron"),n=Object(o["c"])(),c=60,a=10,s=60,{code:f,type:O,payload:j}=n.params,y=window.exports[f];window.rubick.setExpendHeight(s);const w=Object(r["u"])([]);Object(r["B"])([w],()=>{const e=w.value.length>a?a*c:c*w.value.length;window.rubick.setExpendHeight(s+e)}),y.args.enter&&y.args.enter({code:f,type:O,payload:j},e=>{w.value=e});const g=Object(r["u"])(0);t.on("changeCurrent",(e,t)=>{g.value+t>w.value.length-1||w.value+t<0||(g.value=g.value+t)}),window.rubick.setSubInput(({text:e})=>{y.args.search&&y.args.search({code:f,type:"",payload:[]},e,e=>{w.value=e||[]})},"搜索");const h=e=>{y.args.select&&y.args.select({code:f,type:"",payload:[]},e)},m=e=>{if("Enter"===e.code)return h(w.value[g.value]);let t=0;"ArrowDown"===e.code&&(t=1),"ArrowUp"===e.code&&(t=-1),w.value.length&&(g.value+t>w.value.length-1||g.value+t<0||(g.value=g.value+t))};return window.addEventListener("keydown",m),Object(r["o"])(()=>{window.removeEventListener("keydown",m)}),(e,t)=>(Object(r["r"])(),Object(r["f"])("div",u,[Object(r["C"])(Object(r["g"])("div",i,[(Object(r["r"])(!0),Object(r["f"])(r["a"],null,Object(r["v"])(w.value,(e,t)=>(Object(r["r"])(),Object(r["f"])("div",{key:t,class:Object(r["m"])(g.value===t?"active op-item":"op-item"),onClick:t=>h(e)},[e.icon?(Object(r["r"])(),Object(r["f"])("img",{key:0,class:"icon",src:e.icon},null,8,p)):Object(r["e"])("",!0),Object(r["g"])("div",d,[Object(r["g"])("div",b,Object(r["y"])(e.title),1),Object(r["g"])("div",v,Object(r["y"])(decodeURIComponent(e.description)),1)])],10,l))),128))],512),[[r["A"],!!(w.value||[]).length]])]))}});n("3809");const O=f;var j=O;const y={class:"home"};function w(e,t){return Object(r["r"])(),Object(r["f"])("div",y)}var g=n("41ec"),h=n.n(g);const m={},k=h()(m,[["render",w]]);var x=k;const _=[{path:"/list",name:"list",component:j},{path:"/doc",name:"doc",component:x}],P=Object(o["a"])({history:Object(o["b"])(),routes:_});var E=P,S=n("b082"),C=Object(S["a"])({state:{},mutations:{},actions:{},modules:{}});Object(r["c"])(s).use(C).use(E).mount("#app")}});
\ No newline at end of file
diff --git a/public/tpl/js/app.bdf36c39.js b/public/tpl/js/app.bdf36c39.js
deleted file mode 100644
index 6f023b7..0000000
--- a/public/tpl/js/app.bdf36c39.js
+++ /dev/null
@@ -1 +0,0 @@
-(function(e){function t(t){for(var r,a,u=t[0],s=t[1],i=t[2],p=0,d=[];p{const o=window.exports[e];t.push({name:o.mode,params:{code:e,type:n,payload:r}})}),(e,t)=>{const n=Object(r["w"])("router-view");return Object(r["r"])(),Object(r["d"])(n)}}};n("da18");const a=c;var u=a;const s={class:"list-container"},i={class:"options"},l=["onClick"],p=["src"],d={class:"content"},b={class:"title"},v={class:"desc"};var f=Object(r["h"])({__name:"List",setup(e){const{ipcRenderer:t}=window.require("electron"),n=Object(o["c"])(),c=60,a=10,u=60,{code:f,type:O,payload:j}=n.params,y=window.exports[f];window.rubick.setExpendHeight(u);const w=Object(r["u"])([]);Object(r["B"])([w],()=>{const e=w.value.length>a?a*c:c*w.value.length;window.rubick.setExpendHeight(u+e)}),y.args.enter&&y.args.enter({code:f,type:O,payload:j},e=>{w.value=e});const h=Object(r["u"])(0);t.on("changeCurrent",(e,t)=>{h.value+t>w.value.length-1||w.value+t<0||(h.value=h.value+t)}),window.rubick.setSubInput(({text:e})=>{y.args.search&&y.args.search({code:f,type:"",payload:[]},e,e=>{w.value=e||[]})},"搜索");const g=e=>{y.args.select&&y.args.select({code:f,type:"",payload:[]},e)},m=e=>{if("Enter"===e.code)return g(w.value[h.value]);let t=0;"ArrowDown"===e.code&&(t=1),"ArrowUp"===e.code&&(t=-1),w.value.length&&(h.value+t>w.value.length-1||h.value+t<0||(h.value=h.value+t))};return window.addEventListener("keydown",m),Object(r["o"])(()=>{window.removeEventListener("keydown",m)}),(e,t)=>(Object(r["r"])(),Object(r["f"])("div",s,[Object(r["C"])(Object(r["g"])("div",i,[(Object(r["r"])(!0),Object(r["f"])(r["a"],null,Object(r["v"])(w.value,(e,t)=>(Object(r["r"])(),Object(r["f"])("div",{key:t,class:Object(r["m"])(h.value===t?"active op-item":"op-item"),onClick:t=>g(e)},[e.icon?(Object(r["r"])(),Object(r["f"])("img",{key:0,class:"icon",src:e.icon},null,8,p)):Object(r["e"])("",!0),Object(r["g"])("div",d,[Object(r["g"])("div",b,Object(r["y"])(e.title),1),Object(r["g"])("div",v,Object(r["y"])(decodeURIComponent(e.description)),1)])],10,l))),128))],512),[[r["A"],!!(w.value||[]).length]])]))}});n("3809");const O=f;var j=O;const y={class:"home"};function w(e,t){return Object(r["r"])(),Object(r["f"])("div",y)}var h=n("41ec"),g=n.n(h);const m={},k=g()(m,[["render",w]]);var x=k;const _=[{path:"/list",name:"list",component:j},{path:"/doc",name:"doc",component:x}],P=Object(o["a"])({history:Object(o["b"])(),routes:_});var E=P,S=n("b082"),C=Object(S["a"])({state:{},mutations:{},actions:{},modules:{}});Object(r["c"])(u).use(C).use(E).mount("#app")},da18:function(e,t,n){"use strict";n("4b1f")}});
\ No newline at end of file
diff --git a/src/core/screen-capture/index.ts b/src/core/screen-capture/index.ts
index 913d2e7..b72f14a 100644
--- a/src/core/screen-capture/index.ts
+++ b/src/core/screen-capture/index.ts
@@ -25,7 +25,6 @@ export const handleScreenShots = (cb) => {
export default (mainWindow, cb) => {
// 接收到截图后的执行程序
- mainWindow.hide();
clipboard.writeText('');
if (platform.macOS()) {
handleScreenShots(cb);
diff --git a/src/main/browsers/detach.ts b/src/main/browsers/detach.ts
index c90a187..9ec0224 100644
--- a/src/main/browsers/detach.ts
+++ b/src/main/browsers/detach.ts
@@ -64,6 +64,7 @@ export default () => {
createWin.webContents.executeJavaScript(
`document.body.classList.add("dark");window.rubick.theme="dark"`
);
+ view.setAutoResize({ width: true, height: true });
createWin.setBrowserView(view);
createWin.webContents.executeJavaScript(
`window.initDetach(${JSON.stringify(pluginInfo)})`
diff --git a/src/main/browsers/main.ts b/src/main/browsers/main.ts
index 8912515..35b94db 100644
--- a/src/main/browsers/main.ts
+++ b/src/main/browsers/main.ts
@@ -3,7 +3,11 @@ import path from 'path';
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib';
// import versonHandler from '../common/versionHandler';
import localConfig from '@/main/common/initLocalConfig';
-import { WINDOW_HEIGHT, WINDOW_MIN_HEIGHT, WINDOW_WIDTH } from '@/common/constans/common';
+import {
+ WINDOW_HEIGHT,
+ WINDOW_MIN_HEIGHT,
+ WINDOW_WIDTH,
+} from '@/common/constans/common';
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('@electron/remote/main').initialize();
diff --git a/src/main/browsers/runner.ts b/src/main/browsers/runner.ts
index 2299018..1460c75 100644
--- a/src/main/browsers/runner.ts
+++ b/src/main/browsers/runner.ts
@@ -59,7 +59,7 @@ export default () => {
const height = pluginSetting && pluginSetting.height;
window.setSize(800, height || 600);
view.setBounds({ x: 0, y: 60, width: 800, height: height || 540 });
- view.setAutoResize({ width: true });
+ view.setAutoResize({ width: true, height: true });
executeHooks('PluginEnter', ext);
executeHooks('PluginReady', ext);
const config = await localConfig.getConfig();
@@ -166,7 +166,7 @@ export default () => {
const removeView = (window: BrowserWindow) => {
if (!view) return;
window.removeBrowserView(view);
- window.setSize(800, 60);
+ // window.setSize(800, 60);
executeHooks('PluginOut', null);
window.webContents?.executeJavaScript(`window.initRubick()`);
view = undefined;
diff --git a/src/renderer/App.vue b/src/renderer/App.vue
index c7c5110..14be488 100644
--- a/src/renderer/App.vue
+++ b/src/renderer/App.vue
@@ -76,13 +76,16 @@ getPluginInfo({
remote.getGlobal('LOCAL_PLUGINS').addPlugin(res);
});
-watch([options, pluginHistory], () => {
+watch([options, pluginHistory, currentPlugin], () => {
currentSelect.value = 0;
if (currentPlugin.value.name) return;
nextTick(() => {
ipcRenderer.sendSync('msg-trigger', {
type: 'setExpendHeight',
- data: getWindowHeight(options.value, pluginHistory.value),
+ data: getWindowHeight(
+ options.value,
+ pluginLoading.value ? [] : pluginHistory.value
+ ),
});
});
});
diff --git a/src/renderer/plugins-manager/index.ts b/src/renderer/plugins-manager/index.ts
index eb94cf9..57f5052 100644
--- a/src/renderer/plugins-manager/index.ts
+++ b/src/renderer/plugins-manager/index.ts
@@ -121,6 +121,7 @@ const createPluginManager = (): any => {
const {
options,
searchFocus,
+ setOptionsRef,
clipboardFile,
clearClipboardFile,
readClipboardContent,
@@ -172,6 +173,7 @@ const createPluginManager = (): any => {
window.initRubick = () => {
state.currentPlugin = {};
setSearchValue('');
+ setOptionsRef([]);
window.setSubInput({ placeholder: '' });
};
diff --git a/src/renderer/plugins-manager/options.ts b/src/renderer/plugins-manager/options.ts
index 1c6dceb..10f6a9c 100644
--- a/src/renderer/plugins-manager/options.ts
+++ b/src/renderer/plugins-manager/options.ts
@@ -157,6 +157,7 @@ const optionsManager = ({
});
return {
+ setOptionsRef,
options: optionsRef,
searchFocus,
clipboardFile,
diff --git a/tpl/src/App.vue b/tpl/src/App.vue
index d855b9b..5611df0 100644
--- a/tpl/src/App.vue
+++ b/tpl/src/App.vue
@@ -8,6 +8,10 @@ import { useRouter } from "vue-router";
const router = useRouter();
window.rubick.onPluginEnter(({ code, type, payload }) => {
const current = window.exports[code];
+ if (current.mode === 'none') {
+ current.args.enter && current.args.enter({ code: code, type, payload });
+ return;
+ }
router.push({
name: current.mode,
params: {