From 7d3630b6909c4cf93b12ad4d072690e1b68f6bb2 Mon Sep 17 00:00:00 2001 From: qinyang Date: Fri, 30 Nov 2018 20:54:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E5=BF=AB=E6=8D=B7=E9=94=AE=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E4=B8=BA=E4=B8=80=E4=B8=AA=E6=BF=80=E6=B4=BB/?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E5=BA=94=E7=94=A8=E7=AA=97=E5=8F=A3;=20?= =?UTF-8?q?=E8=B0=83=E6=95=B4windows=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=B8=85?= =?UTF-8?q?=E7=90=86=E6=97=A7=E7=9A=84=E8=87=AA=E5=90=AF=E5=8A=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=9A=84=E6=96=B9=E6=A1=88=EF=BC=8C=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E6=9F=90=E4=BA=9B=E6=B2=A1=E6=9C=89=E8=AE=BF=E9=97=AE=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E8=A1=A8=E6=9D=83=E9=99=90=E7=9A=84=E6=9C=BA=E5=AD=90?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=90=AF=E5=8A=A8app=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#43)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fe/preference/hotkey.js | 23 +++++------------------ native/hotkey.js | 14 ++++---------- native/mainDb.js | 24 +++++++++++++++++++----- native/menu/tray.js | 10 +++++++++- native/util.js | 25 +++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 34 deletions(-) diff --git a/fe/preference/hotkey.js b/fe/preference/hotkey.js index 5f14a88..b547e21 100644 --- a/fe/preference/hotkey.js +++ b/fe/preference/hotkey.js @@ -5,23 +5,12 @@ const template = `
快捷键
- 激活应用窗口 + 激活/隐藏应用窗口 - - -
-
- 隐藏应用窗口 - @@ -40,8 +29,7 @@ Vue.component('r-hotkey', { data() { return { inside: { - active: this.config.active, - hide: this.config.hide, + toggle: this.config.toggle, } }; }, @@ -58,8 +46,7 @@ Vue.component('r-hotkey', { }, { deep: true }); this.$watch('config', function(newVal) { this.inside = { - active: newVal.active, - hide: newVal.hide + toggle: newVal.toggle, }; }, { deep: true }) } diff --git a/native/hotkey.js b/native/hotkey.js index a85055b..1c28f45 100644 --- a/native/hotkey.js +++ b/native/hotkey.js @@ -3,20 +3,14 @@ const mainDb = require('./mainDb'); const util = require('./util'); const env = require('../common/env'); -// 激活应用 -async function activeApp() { - util.showWindow(); -} - -// 隐藏应用 -async function hideApp() { - util.hideWindow(); +// 激活/隐藏应用 +async function toggleApp() { + util.toggleWindow(); } // 热键和方法的映射 const HotKeyFunctionMap = { - active: activeApp, - hide: hideApp, + toggle: toggleApp, } // 有部分快捷键在不同的操作系统注册不一样 diff --git a/native/mainDb.js b/native/mainDb.js index 2dbce78..8c0f382 100644 --- a/native/mainDb.js +++ b/native/mainDb.js @@ -12,15 +12,18 @@ const ServerConfigOfficiel = { const HotKey = { mac: { - active: 'Command+Option+X', - hide: 'Command+H' + toggle: 'Command+Option+X', }, win: { - active: 'Ctrl+Alt+X', - hide: 'Ctrl+Alt+S' + toggle: 'Ctrl+Alt+X', } } +// 标记一些状态 +const Status = { + clearOldStartConfig: false, // 是否清理过旧的自启动配置,用在windows系统 +} + // 配置数据的版本号,记录一个版本号,如果以后需要重新调整配置数据的格式 // 可以通过版本号来区别处理 const VERSION = { @@ -28,7 +31,8 @@ const VERSION = { windowSize: 1, proxy: 1, download: 1, - hotkey: 1 + hotkey: 1, + status: 1 } // 重新格式化一下server-config的配置数据 @@ -113,6 +117,11 @@ class MainDb { return Object.assign({}, HotKey[env.platform], config) } + async getStatus () { + const config = await this.db.findOne({ type: 'status-config' }); + return Object.assign({}, Status, config); + } + updateWindowSize (data) { // { width, height } this.db.update({ type: 'main-window-size' }, { $set: Object.assign({ version: VERSION.windowSize }, data) }, { upsert: true }); } @@ -136,6 +145,11 @@ class MainDb { this.event.emit(this.EVENTS.HotkeyConfigChange); } + // 标记一下旧的启动配置已经清理过, + setAsClearOldStartConfig() { + this.db.update({ type: 'status-config' }, { $set: Object.assign({ version: VERSION.status }, { clearOldStartConfig: true }) }, { upsert: true }) + } + // 恢复默认数据 restore() { const typeList = [ diff --git a/native/menu/tray.js b/native/menu/tray.js index d3a5881..f626d12 100644 --- a/native/menu/tray.js +++ b/native/menu/tray.js @@ -7,6 +7,8 @@ const EVENTS = require('../../common/notification_event'); const env = require('../../common/env'); const Icon = require('./icon'); const autoLaunch = require('../autoLaunch'); +const mainDb = require('../mainDb'); + const { Tray, app, @@ -76,8 +78,14 @@ class TrayClass { } } // 清理windows旧版本的的开机启动配置 - clearOldStartConfig() { + async clearOldStartConfig() { if (env.platform !== 'win') return; + const status = await mainDb.getStatus(); + // 如果状态里记录的已经清理过旧的自启动配置 + // 则直接返回 + // 防止部分机子由于没有读取注册表权限的问题,而导致app崩溃 + if (status.clearOldStartConfig) return; + mainDb.setAsClearOldStartConfig(); const startOnBoot = require("./startOnBoot"); const old_key_1 = 'rishiqing_startOnBoot'; // 之前版本保存自动启动地址的key const old_key_2 = 'rishiqing_V3'; // 新版的自启动key diff --git a/native/util.js b/native/util.js index 694b436..3f01d9e 100644 --- a/native/util.js +++ b/native/util.js @@ -15,6 +15,22 @@ class Util { return BrowserWindow.fromId(1); } + isShow() { + let show = true; + const mainWindow = this.mainWindow; + if (!mainWindow) return false; + if (!mainWindow.isVisible()) { + show = false + } + if (mainWindow.isMinimized()) { + show = false + } + if (show && !mainWindow.isFocused()) { + show = false + } + return show + } + showWindow() { let show = false; const mainWindow = this.mainWindow; @@ -43,6 +59,15 @@ class Util { }); } + // 隐藏/显示窗口 + toggleWindow() { + if (this.isShow()) { + this.hideWindow(); + } else { + this.showWindow(); + } + } + clearCache() { dialog.showMessageBox({ type: 'warning', From 3eb3045fbe321f62597afbaa2c81e60644a4c772 Mon Sep 17 00:00:00 2001 From: qinyang Date: Fri, 30 Nov 2018 20:55:50 +0800 Subject: [PATCH 2/2] Update package.json (#44) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f53ca3e..c7d8f00 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rishiqing-electron", - "version": "3.1.11", + "version": "3.1.12", "author": "北京创仕科锐信息技术有限责任公司", "electronVersion": "3.0.10", "main": "main.js",