mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-26 04:19:27 +08:00
♻️ search 框输入交互优化
This commit is contained in:
@@ -49,6 +49,7 @@ export default () => {
|
||||
window.removeBrowserView(view);
|
||||
window.setSize(800, 60);
|
||||
executeHooks("PluginOut", null);
|
||||
window.webContents.executeJavaScript(`window.initRubick()`);
|
||||
view = undefined;
|
||||
};
|
||||
|
||||
|
||||
45
src/main/common/registerHotKey.ts
Normal file
45
src/main/common/registerHotKey.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { globalShortcut, BrowserWindow, screen } from "electron";
|
||||
|
||||
export default (mainWindow: BrowserWindow): void => {
|
||||
const config = global.OP_CONFIG.get();
|
||||
globalShortcut.unregisterAll();
|
||||
// 注册偏好快捷键
|
||||
globalShortcut.register(config.perf.shortCut.showAndHidden, () => {
|
||||
const { x, y } = screen.getCursorScreenPoint();
|
||||
const currentDisplay = screen.getDisplayNearestPoint({ x, y });
|
||||
const wx = parseInt(
|
||||
String(
|
||||
currentDisplay.workArea.x + currentDisplay.workArea.width / 2 - 400
|
||||
)
|
||||
);
|
||||
const wy = parseInt(
|
||||
String(
|
||||
currentDisplay.workArea.y + currentDisplay.workArea.height / 2 - 200
|
||||
)
|
||||
);
|
||||
|
||||
mainWindow.setAlwaysOnTop(true);
|
||||
mainWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
|
||||
mainWindow.focus();
|
||||
mainWindow.setVisibleOnAllWorkspaces(false, { visibleOnFullScreen: true });
|
||||
mainWindow.setPosition(wx, wy);
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
globalShortcut.register(config.perf.shortCut.separate, () => {
|
||||
// todo
|
||||
});
|
||||
|
||||
globalShortcut.register(config.perf.shortCut.quit, () => {
|
||||
// mainWindow.webContents.send('init-rubick');
|
||||
// mainWindow.show();
|
||||
});
|
||||
|
||||
// 注册自定义全局快捷键
|
||||
config.global.forEach((sc) => {
|
||||
if (!sc.key || !sc.value) return;
|
||||
globalShortcut.register(sc.key, () => {
|
||||
mainWindow.webContents.send("global-short-key", sc.value);
|
||||
});
|
||||
});
|
||||
};
|
||||
75
src/main/common/tray.ts
Normal file
75
src/main/common/tray.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { dialog, Menu, Tray, app, shell, BrowserWindow } from "electron";
|
||||
import path from "path";
|
||||
import pkg from "../../../package.json";
|
||||
import os from "os";
|
||||
import commonConst from "@/common/utils/commonConst";
|
||||
|
||||
function createTray(window: BrowserWindow): Promise<Tray> {
|
||||
return new Promise((resolve) => {
|
||||
let icon;
|
||||
if (commonConst.macOS()) {
|
||||
icon = "./icon@3x.png";
|
||||
} else if (commonConst.windows()) {
|
||||
icon = parseInt(os.release()) < 10 ? "./icon@2x.png" : "./icon.ico";
|
||||
} else {
|
||||
icon = "icon@2x.png";
|
||||
}
|
||||
const appIcon = new Tray(path.join(__static, icon));
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: "帮助文档",
|
||||
click: () => {
|
||||
process.nextTick(() => {
|
||||
shell.openExternal("https://github.com/clouDr-f2e/rubick");
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "意见反馈",
|
||||
click: () => {
|
||||
process.nextTick(() => {
|
||||
shell.openExternal("https://github.com/clouDr-f2e/rubick/issues");
|
||||
});
|
||||
},
|
||||
},
|
||||
{ type: "separator" },
|
||||
{
|
||||
label: "显示窗口",
|
||||
accelerator: "Alt+R",
|
||||
click() {
|
||||
window.show();
|
||||
},
|
||||
},
|
||||
{
|
||||
role: "quit",
|
||||
label: "退出",
|
||||
},
|
||||
{
|
||||
label: "重启",
|
||||
click() {
|
||||
app.relaunch();
|
||||
app.quit();
|
||||
},
|
||||
},
|
||||
{ type: "separator" },
|
||||
{
|
||||
label: "关于",
|
||||
click() {
|
||||
dialog.showMessageBox({
|
||||
title: "拉比克",
|
||||
message: "极简、插件化的现代桌面软件",
|
||||
detail: `Version: ${pkg.version}\nAuthor: muwoo`,
|
||||
});
|
||||
},
|
||||
},
|
||||
]);
|
||||
appIcon.on("click", () => {
|
||||
appIcon.popUpContextMenu(contextMenu);
|
||||
});
|
||||
appIcon.setContextMenu(contextMenu);
|
||||
|
||||
resolve(appIcon);
|
||||
});
|
||||
}
|
||||
|
||||
export default createTray;
|
||||
@@ -5,7 +5,11 @@ import commonConst from "../common/utils/commonConst";
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
import API from "./common/api";
|
||||
import createTray from "./common/tray";
|
||||
import registerHotKey from "./common/registerHotKey";
|
||||
|
||||
import "../common/utils/localPlugin";
|
||||
import "../common/utils/localConfig";
|
||||
|
||||
class App {
|
||||
private windowCreator: { init: () => void; getWindow: () => BrowserWindow };
|
||||
@@ -48,8 +52,8 @@ class App {
|
||||
this.createWindow();
|
||||
API(this.windowCreator.getWindow());
|
||||
// this.init()
|
||||
// createTray(this.windowCreator.getWindow())
|
||||
// autoUpdate()
|
||||
createTray(this.windowCreator.getWindow());
|
||||
registerHotKey(this.windowCreator.getWindow());
|
||||
};
|
||||
if (!app.isReady()) {
|
||||
app.on("ready", readyFunction);
|
||||
|
||||
Reference in New Issue
Block a user