🐛 #77, 修复偏好设置不生效问题

This commit is contained in:
muwoo
2021-12-28 14:20:18 +08:00
parent f94c52f490
commit 56faae0e35
15 changed files with 687 additions and 363 deletions

View File

@@ -39,14 +39,6 @@ export default () => {
const url = req.url.substr(8);
callback(decodeURI(url));
});
win.once("ready-to-show", () => {
win.show();
// 非隐藏式启动需要显示主窗口
if (!app.getLoginItemSettings().wasOpenedAsHidden) {
win.show();
}
});
win.on("closed", () => {
win = undefined;
});

View File

@@ -1,45 +1,62 @@
import { globalShortcut, BrowserWindow, screen } from "electron";
import { globalShortcut, BrowserWindow, screen, ipcMain, app} 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);
const registerHotKey = (mainWindow: BrowserWindow): void => {
// 设置开机启动
const setAutoLogin = () => {
const config = global.OP_CONFIG.get();
app.setLoginItemSettings({
openAtLogin: config.perf.common.start,
openAsHidden: true,
});
}
const init = () => {
setAutoLogin();
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);
});
});
}
init();
ipcMain.on("re-register", () => {
init();
});
};
export default registerHotKey;