Skip to content

Commit

Permalink
Merge pull request #45 from rishiqing/beta
Browse files Browse the repository at this point in the history
beta
  • Loading branch information
qinyang912 authored Dec 3, 2018
2 parents ad4de30 + 3eb3045 commit 7569a65
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 35 deletions.
23 changes: 5 additions & 18 deletions fe/preference/hotkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,12 @@ const template = `
<div class="title">快捷键</div>
<div class="content">
<div class="item">
<span class="name">激活应用窗口</span>
<span class="name">激活/隐藏应用窗口</span>
<r-input
v-model="inside.active"
v-model="inside.toggle"
:hotkey-mode="true"
placeholder="无"
@appendClick="onClearClick('active')"
>
<template slot="append">清除</template>
</r-input>
</div>
<div class="item">
<span class="name">隐藏应用窗口</span>
<r-input
v-model="inside.hide"
:hotkey-mode="true"
placeholder="无"
@appendClick="onClearClick('hide')"
@appendClick="onClearClick('toggle')"
>
<template slot="append">清除</template>
</r-input>
Expand All @@ -40,8 +29,7 @@ Vue.component('r-hotkey', {
data() {
return {
inside: {
active: this.config.active,
hide: this.config.hide,
toggle: this.config.toggle,
}
};
},
Expand All @@ -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 })
}
Expand Down
14 changes: 4 additions & 10 deletions native/hotkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

// 有部分快捷键在不同的操作系统注册不一样
Expand Down
24 changes: 19 additions & 5 deletions native/mainDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ 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 = {
server: 1,
windowSize: 1,
proxy: 1,
download: 1,
hotkey: 1
hotkey: 1,
status: 1
}

// 重新格式化一下server-config的配置数据
Expand Down Expand Up @@ -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 });
}
Expand All @@ -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 = [
Expand Down
10 changes: 9 additions & 1 deletion native/menu/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions native/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,6 +59,15 @@ class Util {
});
}

// 隐藏/显示窗口
toggleWindow() {
if (this.isShow()) {
this.hideWindow();
} else {
this.showWindow();
}
}

clearCache() {
dialog.showMessageBox({
type: 'warning',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rishiqing-electron",
"version": "3.1.11",
"version": "3.1.12",
"author": "北京创仕科锐信息技术有限责任公司",
"electronVersion": "3.0.10",
"main": "main.js",
Expand Down

0 comments on commit 7569a65

Please sign in to comment.