feat(core): nwjs下添加对 手动更新 的支持
This commit is contained in:
@@ -31,7 +31,7 @@ Config.init = () => {
|
||||
const boardPageConfig = Url.getConfig();
|
||||
Config.BOARD_PAGE = boardPageConfig ?? {};
|
||||
console.log('Config.BOARD_PAGE:', Config.BOARD_PAGE);
|
||||
document.title = Config.SOFTWARE.version ?? 'Mixly 2.0';
|
||||
document.title = Config.SOFTWARE.version ?? 'Mixly 3.0';
|
||||
|
||||
Config.USER = {
|
||||
...Config.USER,
|
||||
|
||||
@@ -5,6 +5,7 @@ goog.require('ace.ExtLanguageTools');
|
||||
goog.require('layui');
|
||||
goog.require('store');
|
||||
goog.require('$.select2');
|
||||
goog.require('$.fomanticUI');
|
||||
goog.require('Mixly.XML');
|
||||
goog.require('Mixly.LayerExt');
|
||||
goog.require('Mixly.Msg');
|
||||
@@ -167,13 +168,14 @@ Setting.onclick = () => {
|
||||
Setting.addOnchangeOptionListener = () => {
|
||||
element.on('tab(setting-menu-filter)', function(data) {
|
||||
const { index } = data;
|
||||
if (index === 1) {
|
||||
const type = $(data.elem.prevObject).data('type');
|
||||
if (type === 'import-board') {
|
||||
if (data.index !== Setting.nowIndex) {
|
||||
goog.isElectron && BoardManager.onclickImportBoards();
|
||||
} else {
|
||||
layui.table.resize('cloud-boards-table');
|
||||
}
|
||||
} else if (index === 2) {
|
||||
} else if (type === 'ws-update') {
|
||||
if (data.index !== Setting.nowIndex) {
|
||||
$('#setting-menu-update').loading({
|
||||
background: USER.theme === 'dark' ? '#807b7b' : '#fff',
|
||||
@@ -189,6 +191,26 @@ Setting.addOnchangeOptionListener = () => {
|
||||
args: [ SOFTWARE.configUrl ]
|
||||
});
|
||||
}
|
||||
} else if (type === 'nw-update') {
|
||||
fetch('/api/check-update', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((result) => {
|
||||
const {
|
||||
localVersion,
|
||||
cloudVersion,
|
||||
needsUpdate,
|
||||
cloudFile
|
||||
} = result;
|
||||
Setting.refreshUpdateMenuStatus(localVersion, cloudVersion, needsUpdate, cloudFile);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error)
|
||||
});
|
||||
}
|
||||
Setting.nowIndex = index;
|
||||
});
|
||||
@@ -229,58 +251,60 @@ Setting.configMenuGetValue = (obj) => {
|
||||
return config;
|
||||
}
|
||||
|
||||
Setting.refreshUpdateMenuStatus = (config) => {
|
||||
console.log(config);
|
||||
const {
|
||||
serverVersion
|
||||
} = config;
|
||||
let $serverDiv = $('#setting-menu-update-server');
|
||||
let $btnDiv = $('#setting-menu-update > div:nth-child(2)');
|
||||
Setting.refreshUpdateMenuStatus = (localVersion, cloudVersion, needsUpdate, url) => {
|
||||
const $serverDiv = $('#setting-menu-update-server');
|
||||
const $btnDiv = $('#setting-menu-update > div:nth-child(2)');
|
||||
const $mixlyProgress = $serverDiv.find('.mixly-progress');
|
||||
$serverDiv.find('span').css('display', 'none');
|
||||
let needUpdateServer = false;
|
||||
if (serverVersion && serverVersion !== SOFTWARE.serverVersion) {
|
||||
$serverDiv.find('span[value="obsolete"]').css('display', 'inline-block');
|
||||
needUpdateServer = true;
|
||||
$serverDiv.find('text').text(`${SOFTWARE.serverVersion} → ${serverVersion}`);
|
||||
$mixlyProgress.hide();
|
||||
$mixlyProgress.find('.progress').show();
|
||||
$mixlyProgress.removeClass('swinging indeterminate');
|
||||
if (needsUpdate) {
|
||||
$serverDiv.find('span.obsolete').css('display', 'inline-block');
|
||||
$serverDiv.find('text').text(`${localVersion} → ${cloudVersion}`);
|
||||
|
||||
} else {
|
||||
$serverDiv.find('span[value="latest"]').css('display', 'inline-block');
|
||||
$serverDiv.find('text').text(SOFTWARE.serverVersion);
|
||||
$serverDiv.find('span.latest').css('display', 'inline-block');
|
||||
$serverDiv.find('text').text(localVersion);
|
||||
}
|
||||
if (needUpdateServer) {
|
||||
if (needsUpdate) {
|
||||
$btnDiv.css('display', 'flex');
|
||||
$btnDiv.children('button').off().click((event) => {
|
||||
LayerExt.open({
|
||||
title: Msg.getLang('PROGRESS'),
|
||||
id: 'setting-menu-update-layer',
|
||||
shade: LayerExt.SHADE_ALL,
|
||||
area: ['40%', '60%'],
|
||||
max: ['800px', '300px'],
|
||||
min: ['500px', '100px'],
|
||||
success: (layero, index) => {
|
||||
$('#setting-menu-update-layer').css('overflow', 'hidden');
|
||||
layero.find('.layui-layer-setwin').css('display', 'none');
|
||||
Setting.ace = Setting.createAceEditor('setting-menu-update-layer');
|
||||
Setting.ace.resize();
|
||||
const { Socket } = Mixly.WebSocket;
|
||||
Socket.sendCommand({
|
||||
obj: 'Socket',
|
||||
func: 'updateSW',
|
||||
args: []
|
||||
$btnDiv.children('button').off().one('click', (event) => {
|
||||
const eventSource = new EventSource(`/api/download?url=${encodeURIComponent(url)}&cloudVersion=${cloudVersion}`);
|
||||
$mixlyProgress.show();
|
||||
eventSource.onmessage = function(event) {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.type === 'progress') {
|
||||
$mixlyProgress.progress({
|
||||
percent: data.progress
|
||||
});
|
||||
},
|
||||
resizing: (layero) => {
|
||||
Setting.ace.resize();
|
||||
},
|
||||
end: () => {
|
||||
} else if (data.type === 'unzip') {
|
||||
$mixlyProgress.addClass('swinging indeterminate');
|
||||
$mixlyProgress.progress({
|
||||
percent: 100
|
||||
});
|
||||
$mixlyProgress.find('.progress').hide();
|
||||
layer.msg('解压中...', { time: 1000 });
|
||||
} else if (data.type === 'complete') {
|
||||
$mixlyProgress.removeClass('swinging indeterminate');
|
||||
layer.msg('更新完成!5秒后自动刷新...', { time: 1000 });
|
||||
eventSource.close();
|
||||
setTimeout(function(){
|
||||
window.location.reload();
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
};
|
||||
eventSource.onerror = function(error) {
|
||||
layer.msg('下载失败!5秒后自动刷新...', { time: 1000 });
|
||||
setTimeout(function(){
|
||||
window.location.reload();
|
||||
}, 5000);
|
||||
eventSource.close();
|
||||
};
|
||||
});
|
||||
} else {
|
||||
$btnDiv.css('display', 'none');
|
||||
}
|
||||
setTimeout(() => {
|
||||
$('#setting-menu-update').loading('destroy');
|
||||
}, 500);
|
||||
}
|
||||
|
||||
Setting.showUpdateMessage = (data) => {
|
||||
|
||||
@@ -21,6 +21,9 @@ if (Env.hasSocketServer) {
|
||||
if (env === 'electron' && !goog.isElectron) {
|
||||
env = 'web';
|
||||
}
|
||||
if (typeof nw === 'object') {
|
||||
env = 'nw';
|
||||
}
|
||||
|
||||
XML.TEMPLATE_CONFIG = [
|
||||
{
|
||||
|
||||
@@ -89,6 +89,7 @@
|
||||
"layui",
|
||||
"store",
|
||||
"$.select2",
|
||||
"$.fomanticUI",
|
||||
"Mixly.XML",
|
||||
"Mixly.LayerExt",
|
||||
"Mixly.Msg",
|
||||
|
||||
Reference in New Issue
Block a user