Skip to content

Commit

Permalink
✨ 插件适配窗口缩放;修复窗口尺寸调整的bug;新增 createBrowserWindow、getCursorScreenPoint、g…
Browse files Browse the repository at this point in the history
…etDisplayNearestPoint、outPlugin API
  • Loading branch information
muwoo committed Oct 23, 2023
1 parent c00963f commit 6da9e2f
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rubick",
"version": "4.0.9",
"version": "4.0.10",
"author": "muwoo <2424880409@qq.com>",
"private": true,
"scripts": {
Expand Down
61 changes: 60 additions & 1 deletion public/preload.js
Original file line number Diff line number Diff line change
@@ -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', {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
},
};
2 changes: 1 addition & 1 deletion public/tpl/index.html
Original file line number Diff line number Diff line change
@@ -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>tpl</title><link href="css/app.f5fd5a5f.css" rel="preload" as="style"><link href="js/app.bdf36c39.js" rel="preload" as="script"><link href="js/chunk-vendors.6a327047.js" rel="preload" as="script"><link href="css/app.f5fd5a5f.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but tpl doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.6a327047.js"></script><script src="js/app.bdf36c39.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>tpl</title><link href="css/app.f5fd5a5f.css" rel="preload" as="style"><link href="js/app.71511ff3.js" rel="preload" as="script"><link href="js/chunk-vendors.6a327047.js" rel="preload" as="script"><link href="css/app.f5fd5a5f.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but tpl doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.6a327047.js"></script><script src="js/app.71511ff3.js"></script></body></html>
1 change: 1 addition & 0 deletions public/tpl/js/app.71511ff3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion public/tpl/js/app.bdf36c39.js

This file was deleted.

1 change: 0 additions & 1 deletion src/core/screen-capture/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const handleScreenShots = (cb) => {

export default (mainWindow, cb) => {
// 接收到截图后的执行程序
mainWindow.hide();
clipboard.writeText('');
if (platform.macOS()) {
handleScreenShots(cb);
Expand Down
1 change: 1 addition & 0 deletions src/main/browsers/detach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)})`
Expand Down
6 changes: 5 additions & 1 deletion src/main/browsers/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/main/browsers/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/renderer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
});
});
});
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/plugins-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const createPluginManager = (): any => {
const {
options,
searchFocus,
setOptionsRef,
clipboardFile,
clearClipboardFile,
readClipboardContent,
Expand Down Expand Up @@ -172,6 +173,7 @@ const createPluginManager = (): any => {
window.initRubick = () => {
state.currentPlugin = {};
setSearchValue('');
setOptionsRef([]);
window.setSubInput({ placeholder: '' });
};

Expand Down
1 change: 1 addition & 0 deletions src/renderer/plugins-manager/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const optionsManager = ({
});

return {
setOptionsRef,
options: optionsRef,
searchFocus,
clipboardFile,
Expand Down
4 changes: 4 additions & 0 deletions tpl/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 6da9e2f

Please sign in to comment.