增强随机操作,防止唤醒时卡顿

This commit is contained in:
2020-06-14 15:53:42 +08:00
parent dc054e40db
commit 5f2b0de85b
3 changed files with 11 additions and 5 deletions
+3 -2
View File
@@ -5,6 +5,7 @@ const { createMainWindow, toggleMainWindowVisibility } = require('./main');
const getMenu = require('./menu');
const { config, flushConfig } = require('./config');
const toast = require('./notify');
const main = require('./main');
//将tray保存到全局变量,防止其被自动回收
let tray;
@@ -74,7 +75,7 @@ function setupTray() {
tray = new Tray(path.resolve(__dirname, 'assets/icon.ico'));
const contextMenu = Menu.buildFromTemplate([
{ label: "显示主界面", click: () => toggleMainWindowVisibility(mainWindow) },
{ label: "显示Mini窗口", click: () => toggleMiniWindowVisibility(miniWindow) },
{ label: "显示Mini窗口", click: () => toggleMiniWindowVisibility(miniWindow, mainWindow) },
{
type: 'checkbox',
label: "开机启动",
@@ -123,7 +124,7 @@ function toggleMiniShortcut(initial) {
let enabled = initial ? config.miniWindowEnabled : !config.miniWindowEnabled;
let success = true;
if (enabled) {
if (!globalShortcut.register(config.miniShortcut, () => toggleMiniWindowVisibility(miniWindow))) {
if (!globalShortcut.register(config.miniShortcut, () => toggleMiniWindowVisibility(miniWindow, mainWindow))) {
toast.show("快捷键注册失败,请检查设置的快捷键是否被其他软件占用。", "错误", {
type: 'error'
});
+7 -2
View File
@@ -105,7 +105,7 @@ function createMiniWindow () {
miniWindow.webContents.executeJavaScript(`
var source = document.getElementById('source');
if (source) {
source.value = source.value;
source.value = source.value ? '' : Math.random();
}
`);
}
@@ -114,7 +114,7 @@ function createMiniWindow () {
return miniWindow;
}
function toggleMiniWindowVisibility(window) {
function toggleMiniWindowVisibility(window, mainWindow) {
if (!window) { return; }
miniControl.isMiniWindowVisible = !miniControl.isMiniWindowVisible;
if (miniControl.isMiniWindowVisible) {
@@ -124,12 +124,17 @@ function toggleMiniWindowVisibility(window) {
else {
window.show();
}
if (!mainWindow || !mainWindow.isVisible()) {
window.setSkipTaskbar(false);
}
clearInput(window);
focusInput(window);
window.focus();
}
else {
miniControl.previousPos = window.getPosition();
window.setPosition(-1000, -1000, false);
window.setSkipTaskbar(true);
clearInput(window);
}
}