/** * 检查更新模块 */ const LANG = antSword['language']['settings']['update']; const LANG_T = antSword['language']['toastr']; class Update { constructor(sidebar) { sidebar.addItem({ id: 'update', text: ` ${LANG['title']}` }); const cell = sidebar.cells('update'); // 初始化toolbar const toolbar = cell.attachToolbar(); toolbar.loadStruct([ { id: 'check', type: 'button', // 调试或者windows平台不支持更新 disabled: antSword['package']['debug'] || process.platform === 'win32', text: LANG['toolbar']['check'], icon: 'check-square-o' }, { type: 'separator' } ]); // toolbar点击事件 toolbar.attachEvent('onClick', (id) => { switch(id) { case 'check': this.checkUpdate(); break; } }); // 显示当前版本号 cell.attachHTMLString(` ${LANG['current']}: ${antSword['package']['version']} `); this.cell = cell; } /** * 检查更新 * @return {None} [description] */ checkUpdate() { this.cell.progressOn(); toastr.info(LANG['check']['ing'], LANG_T['info']); // 后台检查更新 antSword['ipcRenderer'] .once('update-check', (event, ret) => { this.cell.progressOff(); let info = ret['retVal']; // 木有更新 if (!ret['hasUpdate']) { return typeof info === 'string' ? toastr.error(LANG['check']['fail'](info), LANG_T['error']) : toastr.info(LANG['check']['none'](info['version']), LANG_T['info']); } // 发现更新 toastr.success(LANG['check']['found'](info['version']), LANG_T['success']); // 更新来源html let sources_html = ``; // 提示更新 layer.open({ type: 1, shift: 2, skin: 'ant-update', btn: [LANG['prompt']['btns']['ok'], LANG['prompt']['btns']['no']], closeBtn: 0, title: ` ${LANG['prompt']['title']}[v${info['version']}]`, content: ` ${LANG['prompt']['changelog']}
${LANG['message']['ing']}
`); } /** * 更新失败提示界面 * @param {String} tip 失败信息 * @return {[type]} [description] */ updateFail(tip) { $('.layui-layer-content').html(`${LANG['message']['fail'](tip)}
${LANG['message']['success']}