Commit ea00b9d2 authored by antoor's avatar antoor

Program upgrades

程序升级功能
parent 0ba1db98
......@@ -6,11 +6,12 @@
*/
const config = require('./config');
const superagent = require('superagent');
class Update {
constructor(electron) {
this.logger = new electron.Logger('Update');
setTimeout(this.checkUpdate.bind(this), 1000 * 60);
electron.ipcMain.on('check-update', this.checkUpdate.bind(this));
}
/**
......@@ -18,8 +19,29 @@ class Update {
* 如果有更新,则以通知的方式提示用户手动更新,用户点击跳转到更新页面
* @return {[type]} [description]
*/
checkUpdate() {
checkUpdate(event) {
this.logger.debug('checkUpdate..');
superagent
.get('https://api.github.com/repos/antoor/antSword/releases/latest')
.end((err, ret) => {
try {
let lastInfo = JSON.parse(ret.text);
let newVersion = lastInfo['tag_name'];
let curVersion = config['package'].version;
// 比对版本
if (curVersion !== newVersion) {
this.logger.info('Found a new version', newVersion);
event.sender.send('notification-update', {
ver: newVersion,
url: lastInfo['html_url']
});
} else {
this.logger.warn('No new version.');
}
} catch(e) {
this.logger.fatal('ERR', e);
}
});
}
}
......
......@@ -196,6 +196,20 @@ ipcRenderer
antSword.modules.shellmanager.category.cell.setWidth(222);
}, 555);
})
/**
* 通知提示更新
* @param {[type]} 'notification-update' [description]
* @param {[type]} (e, opt [description]
* @return {[type]} [description]
*/
.on('notification-update', (e, opt) => {
let n = new Notification('发现更新', {
body: '新版本:' + opt['ver']
});
n.addEventListener('click', () => {
antSword.shell.openExternal(opt['url']);
});
})
/**
* 重新加载本地插件
* @param {[type]} 'reloadPlug' [description]
......@@ -222,3 +236,8 @@ ipcRenderer
});
antSword.reloadPlug();
// 检查更新
setTimeout(
antSword.ipcRenderer.send.bind(antSword.ipcRenderer, 'check-update'),
1000 * 60
);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment