Commit f11085a3 authored by Medicean's avatar Medicean

(New: LoaderUpdate) 新增检查 Loader 更新功能

parent 93472514
...@@ -17,9 +17,39 @@ class Update { ...@@ -17,9 +17,39 @@ class Update {
this.logger = new electron.Logger('Update'); this.logger = new electron.Logger('Update');
electron.ipcMain electron.ipcMain
.on('check-update', this.checkUpdate.bind(this)) .on('check-update', this.checkUpdate.bind(this))
.on('check-loader-update', this.checkLoaderUpdate.bind(this))
.on('update-download', this.onDownlaod.bind(this)); .on('update-download', this.onDownlaod.bind(this));
} }
/**
* 检查 loader 是否需要更新
* @param {[type]} event
*/
checkLoaderUpdate(event) {
this.logger.debug('checkLoaderUpdate..')
superagent
.get('https://api.github.com/repos/antswordproject/antSword-Loader/releases/latest')
.end((err, ret) => {
try {
let lastInfo = JSON.parse(ret.text);
let newVersion = lastInfo['tag_name'];
let curVersion = process.env.AS_LOADER_VER || '2.0.1';
// 比对版本
if (this.CompVersion(curVersion, newVersion)) {
this.logger.info('Found a new loader version', newVersion);
event.sender.send('notification-loader-update', {
ver: newVersion,
url: lastInfo['html_url']
});
} else {
this.logger.warn('No new loader version.', newVersion, curVersion);
}
} catch(e) {
this.logger.fatal('ERR', e);
}
});
}
/** /**
* 检查更新 * 检查更新
* 如果有更新,则以通知的方式提示用户手动更新,用户点击跳转到更新页面 * 如果有更新,则以通知的方式提示用户手动更新,用户点击跳转到更新页面
......
...@@ -256,6 +256,28 @@ ipcRenderer ...@@ -256,6 +256,28 @@ ipcRenderer
antSword.modules.shellmanager.category.cell.setWidth(222); antSword.modules.shellmanager.category.cell.setWidth(222);
}, 555); }, 555);
}) })
/**
* 通知提示 Loader 更新
* @param {[type]} 'notification-loader-update' [description]
* @param {[type]} (e, opt [description]
* @return {[type]} [description]
*/
.on('notification-loader-update', (e, opt) => {
const LANG = antSword["language"]["settings"]["update"];
let n = new Notification(antSword['language']['update']['title'], {
body: antSword['language']['update']['body'](opt['ver'])
});
n.addEventListener('click', () => {
antSword.shell.openExternal(opt['url']);
});
layer.confirm(LANG['prompt']['loader_body'](opt['ver']), {
icon: 3, shift: 6,
title: LANG['prompt']['title']
}, (_) => {
antSword.shell.openExternal(opt['url']);
antSword.remote.app.quit();
});
})
/** /**
* 通知提示更新 * 通知提示更新
* @param {[type]} 'notification-update' [description] * @param {[type]} 'notification-update' [description]
...@@ -387,13 +409,16 @@ ipcRenderer ...@@ -387,13 +409,16 @@ ipcRenderer
antSword.reloadPlug(); antSword.reloadPlug();
antSword['menubar'].reg('check-update', ()=>{ antSword['menubar'].reg('check-update', ()=>{
antSword.ipcRenderer.send('check-update'); antSword.ipcRenderer.send('check-update');
antSword.ipcRenderer.send('check-loader-update');
}); });
if(new Date() - new Date(antSword['storage']('lastautocheck', false, "0")) >= 86400000) { if(new Date() - new Date(antSword['storage']('lastautocheck', false, "0")) >= 86400000) {
// 检查更新 // 检查更新
antSword['storage']('lastautocheck', new Date().getTime()); antSword['storage']('lastautocheck', new Date().getTime());
setTimeout( setTimeout(() => {
antSword.ipcRenderer.send.bind(antSword.ipcRenderer, 'check-update'), antSword.ipcRenderer.send.bind(antSword.ipcRenderer, 'check-update');
antSword.ipcRenderer.send.bind(antSword.ipcRenderer, 'check-loader-update');
},
1000 * 60 1000 * 60
); );
} }
\ No newline at end of file
...@@ -606,6 +606,7 @@ Hot Keys: ...@@ -606,6 +606,7 @@ Hot Keys:
no: 'Cancel' no: 'Cancel'
}, },
body: (ver) => `Found new version v${ver}, update now?`, body: (ver) => `Found new version v${ver}, update now?`,
loader_body: (ver) => `The new version of the Loader v${ver} has been released, the currently used loader will not be available, will you quit the program and go to download the latest version of the Loader?`,
title: 'Update to version', title: 'Update to version',
changelog: 'Change Logs: ', changelog: 'Change Logs: ',
sources: 'Download source: ', sources: 'Download source: ',
......
...@@ -607,6 +607,7 @@ module.exports = { ...@@ -607,6 +607,7 @@ module.exports = {
no: '下次再说' no: '下次再说'
}, },
body: (ver) => `发现新版本 v${ver}, 是否更新?`, body: (ver) => `发现新版本 v${ver}, 是否更新?`,
loader_body: (ver) => `加载器新版本 v${ver} 已经发布,当前使用的加载器即将不能使用, 是否退出程序并前往下载最新版加载器?`,
title: '版本更新', title: '版本更新',
changelog: '更新日志:', changelog: '更新日志:',
sources: '更新来源:', sources: '更新来源:',
......
...@@ -607,6 +607,7 @@ module.exports = { ...@@ -607,6 +607,7 @@ module.exports = {
no: '下次再説' no: '下次再説'
}, },
body: (ver) => `發現新版本 v${ver}, 是否更新?`, body: (ver) => `發現新版本 v${ver}, 是否更新?`,
loader_body: (ver) => `加載器新版本 v${ver} 已經發布,當前使用的加載器即將不能使用, 是否退出程序並前往下載最新版加載器?`,
title: '版本更新', title: '版本更新',
changelog: '更新日誌:', changelog: '更新日誌:',
sources: '更新來源:', sources: '更新來源:',
......
...@@ -607,6 +607,7 @@ module.exports = { ...@@ -607,6 +607,7 @@ module.exports = {
no: '下次再說' no: '下次再說'
}, },
body: (ver) => `發現新版本 v${ver}, 是否更新?`, body: (ver) => `發現新版本 v${ver}, 是否更新?`,
loader_body: (ver) => `加載器新版本 v${ver} 已經發布,當前使用的加載器即將不能使用, 是否退出程序並前往下載最新版加載器?`,
title: '版本更新', title: '版本更新',
changelog: '更新日誌:', changelog: '更新日誌:',
sources: '更新來源:', sources: '更新來源:',
......
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