增强随机操作,防止唤醒时卡顿
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "google-translate-electron",
|
"name": "google-translate-electron",
|
||||||
"author": "mattuy<mattuylee@outlook.com>",
|
"author": "mattuy<mattuylee@outlook.com>",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"main": "./src/index.js",
|
"main": "./src/index.js",
|
||||||
"description": "Google Translate for Windows Desktop, built with Electron",
|
"description": "Google Translate for Windows Desktop, built with Electron",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+3
-2
@@ -5,6 +5,7 @@ const { createMainWindow, toggleMainWindowVisibility } = require('./main');
|
|||||||
const getMenu = require('./menu');
|
const getMenu = require('./menu');
|
||||||
const { config, flushConfig } = require('./config');
|
const { config, flushConfig } = require('./config');
|
||||||
const toast = require('./notify');
|
const toast = require('./notify');
|
||||||
|
const main = require('./main');
|
||||||
|
|
||||||
//将tray保存到全局变量,防止其被自动回收
|
//将tray保存到全局变量,防止其被自动回收
|
||||||
let tray;
|
let tray;
|
||||||
@@ -74,7 +75,7 @@ function setupTray() {
|
|||||||
tray = new Tray(path.resolve(__dirname, 'assets/icon.ico'));
|
tray = new Tray(path.resolve(__dirname, 'assets/icon.ico'));
|
||||||
const contextMenu = Menu.buildFromTemplate([
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
{ label: "显示主界面", click: () => toggleMainWindowVisibility(mainWindow) },
|
{ label: "显示主界面", click: () => toggleMainWindowVisibility(mainWindow) },
|
||||||
{ label: "显示Mini窗口", click: () => toggleMiniWindowVisibility(miniWindow) },
|
{ label: "显示Mini窗口", click: () => toggleMiniWindowVisibility(miniWindow, mainWindow) },
|
||||||
{
|
{
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
label: "开机启动",
|
label: "开机启动",
|
||||||
@@ -123,7 +124,7 @@ function toggleMiniShortcut(initial) {
|
|||||||
let enabled = initial ? config.miniWindowEnabled : !config.miniWindowEnabled;
|
let enabled = initial ? config.miniWindowEnabled : !config.miniWindowEnabled;
|
||||||
let success = true;
|
let success = true;
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
if (!globalShortcut.register(config.miniShortcut, () => toggleMiniWindowVisibility(miniWindow))) {
|
if (!globalShortcut.register(config.miniShortcut, () => toggleMiniWindowVisibility(miniWindow, mainWindow))) {
|
||||||
toast.show("快捷键注册失败,请检查设置的快捷键是否被其他软件占用。", "错误", {
|
toast.show("快捷键注册失败,请检查设置的快捷键是否被其他软件占用。", "错误", {
|
||||||
type: 'error'
|
type: 'error'
|
||||||
});
|
});
|
||||||
|
|||||||
+7
-2
@@ -105,7 +105,7 @@ function createMiniWindow () {
|
|||||||
miniWindow.webContents.executeJavaScript(`
|
miniWindow.webContents.executeJavaScript(`
|
||||||
var source = document.getElementById('source');
|
var source = document.getElementById('source');
|
||||||
if (source) {
|
if (source) {
|
||||||
source.value = source.value;
|
source.value = source.value ? '' : Math.random();
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ function createMiniWindow () {
|
|||||||
return miniWindow;
|
return miniWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleMiniWindowVisibility(window) {
|
function toggleMiniWindowVisibility(window, mainWindow) {
|
||||||
if (!window) { return; }
|
if (!window) { return; }
|
||||||
miniControl.isMiniWindowVisible = !miniControl.isMiniWindowVisible;
|
miniControl.isMiniWindowVisible = !miniControl.isMiniWindowVisible;
|
||||||
if (miniControl.isMiniWindowVisible) {
|
if (miniControl.isMiniWindowVisible) {
|
||||||
@@ -124,12 +124,17 @@ function toggleMiniWindowVisibility(window) {
|
|||||||
else {
|
else {
|
||||||
window.show();
|
window.show();
|
||||||
}
|
}
|
||||||
|
if (!mainWindow || !mainWindow.isVisible()) {
|
||||||
|
window.setSkipTaskbar(false);
|
||||||
|
}
|
||||||
|
clearInput(window);
|
||||||
focusInput(window);
|
focusInput(window);
|
||||||
window.focus();
|
window.focus();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
miniControl.previousPos = window.getPosition();
|
miniControl.previousPos = window.getPosition();
|
||||||
window.setPosition(-1000, -1000, false);
|
window.setPosition(-1000, -1000, false);
|
||||||
|
window.setSkipTaskbar(true);
|
||||||
clearInput(window);
|
clearInput(window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user