diff --git a/index.html b/index.html index 00a26bdc..f3180e1f 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,7 @@ + diff --git a/mixly-sw/mixly-modules/common/config.js b/mixly-sw/mixly-modules/common/config.js index c09c0857..aaa3bdd6 100644 --- a/mixly-sw/mixly-modules/common/config.js +++ b/mixly-sw/mixly-modules/common/config.js @@ -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, diff --git a/mixly-sw/mixly-modules/common/setting.js b/mixly-sw/mixly-modules/common/setting.js index 549b0dfe..67d5f700 100644 --- a/mixly-sw/mixly-modules/common/setting.js +++ b/mixly-sw/mixly-modules/common/setting.js @@ -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) => { diff --git a/mixly-sw/mixly-modules/common/xml.js b/mixly-sw/mixly-modules/common/xml.js index cb763206..b8d0a061 100644 --- a/mixly-sw/mixly-modules/common/xml.js +++ b/mixly-sw/mixly-modules/common/xml.js @@ -21,6 +21,9 @@ if (Env.hasSocketServer) { if (env === 'electron' && !goog.isElectron) { env = 'web'; } +if (typeof nw === 'object') { + env = 'nw'; +} XML.TEMPLATE_CONFIG = [ { diff --git a/mixly-sw/mixly-modules/deps.json b/mixly-sw/mixly-modules/deps.json index 0020e66a..25060855 100644 --- a/mixly-sw/mixly-modules/deps.json +++ b/mixly-sw/mixly-modules/deps.json @@ -89,6 +89,7 @@ "layui", "store", "$.select2", + "$.fomanticUI", "Mixly.XML", "Mixly.LayerExt", "Mixly.Msg", diff --git a/mixly-sw/templete/setting-div.html b/mixly-sw/templete/setting-div.html index 6f3582c2..eb78a915 100644 --- a/mixly-sw/templete/setting-div.html +++ b/mixly-sw/templete/setting-div.html @@ -167,22 +167,52 @@ #setting-menu-update .layui-panel { margin: 5px; } + + #setting-menu-update .latest, + #setting-menu-update .obsolete { + display: none; + } + + #setting-menu-update-server .mixly-progress { + display: none; + margin-bottom: 0px; + } + + #setting-menu-update-server .bar { + height: 20px; + } + + #setting-menu-update-server .bar > .progress { + /*display: none;*/ + height: 20px; + margin-bottom: 10px; + overflow: hidden; + border-radius: 1px; + -webkit-box-shadow: unset; + box-shadow: unset; + background-color: unset; + }