- 激活应用窗口
+ 激活/隐藏应用窗口
- 清除
-
-
-
- 隐藏应用窗口
-
清除
@@ -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',