From 5f2b0de85bfa384c810695d8c7ca5a3ea6ba4d81 Mon Sep 17 00:00:00 2001 From: mattuy Date: Sun, 14 Jun 2020 15:53:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E9=9A=8F=E6=9C=BA=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=94=A4=E9=86=92=E6=97=B6?= =?UTF-8?q?=E5=8D=A1=E9=A1=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/index.js | 5 +++-- src/mini.js | 9 +++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index c58c759..6f598ec 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "google-translate-electron", "author": "mattuy", - "version": "0.1.0", + "version": "0.1.1", "main": "./src/index.js", "description": "Google Translate for Windows Desktop, built with Electron", "scripts": { diff --git a/src/index.js b/src/index.js index 05b68fc..670f5c6 100644 --- a/src/index.js +++ b/src/index.js @@ -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' }); diff --git a/src/mini.js b/src/mini.js index 2df06a0..392f294 100644 --- a/src/mini.js +++ b/src/mini.js @@ -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); } }