From e7319ccd735d6937c498c4605491128fd37c03f5 Mon Sep 17 00:00:00 2001 From: akashtl Date: Wed, 29 Apr 2020 10:54:27 +0800 Subject: [PATCH 01/13] added update guideline --- lib/desktop_updater.js | 324 ++++++++++++++++++++----------- src/assets/css/desktop-style.css | 7 +- src/template.ejs | 69 ++++++- 3 files changed, 282 insertions(+), 118 deletions(-) diff --git a/lib/desktop_updater.js b/lib/desktop_updater.js index 45d4a6b7f..cc5855376 100644 --- a/lib/desktop_updater.js +++ b/lib/desktop_updater.js @@ -4,6 +4,29 @@ ipcRendererUpdateWeb.on('update', function (event, message) { var msgJSON = JSON.parse(message); console.log(message); // // message = {key:'',text:''}; switch (msgJSON.key) { + case 'update-check-menu': + //Update UI button or text + document.getElementById('update-info').style = (msgJSON.upgrade ? '' : (msgJSON.version !== '' ? 'display: none;' : 'display: none;')); + document.getElementById('update-info').innerHTML = (msgJSON.upgrade ? 'Update Available' : (msgJSON.version !== '' ? '' : '')); + document.getElementById('update_latest_version').innerHTML = (msgJSON.upgrade ? 'A new release is available (' + msgJSON.version + ').' : (msgJSON.version !== '' ? 'You are using latest version of Nynja.' : 'Encountered an error while updating, try again later.')); + document.getElementById('update_current_version').innerHTML = 'version ' + msgJSON.currentVersion; + + document.getElementById('update_version_electron').innerHTML = (msgJSON.electron === undefined ? process.versions.electron : msgJSON.electron); + document.getElementById('update_version_chromium').innerHTML = (msgJSON.chromium === undefined ? process.versions.chrome : msgJSON.chromium); + document.getElementById('update_version_nodejs').innerHTML = (msgJSON.nodejs === undefined ? process.versions.node : msgJSON.chromium); + + document.getElementById('update-desc-box').style = 'display: none;'; + // document.getElementById('update-info').style = 'display: none;'; + document.getElementById('update-conf-box').style = 'display: none;'; + document.getElementById('update-conf-yes').style = 'display: none;'; + document.getElementById('update-notify-box').style = 'display: none;'; + + //Handle event + // // document.getElementById('update-info').removeEventListener('click'); + document.getElementById("update-info").addEventListener("click", function () { updateInfoClick(msgJSON) }, false); + document.getElementById("update_version_notes").addEventListener("click", updateVersionNotesClick) + updateInfoClick(msgJSON); + break; case 'update-check': //Update UI button or text @@ -18,40 +41,115 @@ ipcRendererUpdateWeb.on('update', function (event, message) { document.getElementById('update_version_chromium').innerHTML = (msgJSON.chromium === undefined ? process.versions.chrome : msgJSON.chromium); document.getElementById('update_version_nodejs').innerHTML = (msgJSON.nodejs === undefined ? process.versions.node : msgJSON.chromium); + + document.getElementById('update-desc-box').style = 'display: none;'; + // document.getElementById('update-info').style = 'display: none;'; + document.getElementById('update-conf-box').style = 'display: none;'; + document.getElementById('update-conf-yes').style = 'display: none;'; + document.getElementById('update-notify-box').style = 'display: none;'; + //Handle event // // document.getElementById('update-info').removeEventListener('click'); - document.getElementById("update-info").addEventListener("click", function () {//alert(1); - //show modal popup - document.getElementById('update-desc-box').style = ''; + document.getElementById("update-info").addEventListener("click", function () { updateInfoClick(msgJSON) }, false); + document.getElementById("update_version_notes").addEventListener("click", updateVersionNotesClick) + break; + default: + break; - if (msgJSON.upgrade) { - // document.getElementById('update-install').removeEventListener('click'); - document.getElementById('update_download_install').style = ''; - document.getElementById('update_download_install').addEventListener("click", startDownloading) + } + var request = new XMLHttpRequest(); + request.open('GET', window.location.origin + '/lib/releaseNotes/releaseNotesDesktop.json', true); + request.onload = function () { + console.log(JSON.parse(this.response), 'asd') + var releaseNotes = JSON.parse(this.response); + + document.getElementById('releases_info').innerHTML = ''; + + Object.keys(releaseNotes).map(function (releaseNote, i) { + var SPAN_NODE = document.createElement("SPAN"); + SPAN_NODE.style = "font-size: 16px;font-weight: bold;"; + SPAN_NODE.innerText = "Version: " + releaseNote; + + document.getElementById('releases_info').appendChild(SPAN_NODE); + + var UL_NODE = document.createElement("UL"); + UL_NODE.style = "margin: 5px 0 5px 15px;list-style:none;list-style-type: disc;list-style-position: outside;"; + + releaseNotes[releaseNote].content.map(function (note, j) { + var LI_NODE = document.createElement("LI"); + LI_NODE.innerText = note; + LI_NODE.style = "margin-left: 20px;"; + UL_NODE.appendChild(LI_NODE); + + if ((j + 1) === releaseNotes[releaseNote].content.length) { + + document.getElementById('releases_info').appendChild(UL_NODE) + if ((i + 1) === Object.keys(releaseNotes).length) { + } } }); - break; - default: - + }) } + request.send() + }) +function updateVersionNotesClick() { + document.getElementById('update-desc-release-notes').style = 'z-index: 1001;'; +} +/** + * Update Available click handler + * Show update popup + */ +function updateInfoClick(msgJSON) {//alert(1); + //show modal popup + document.getElementById('update-desc-box').style = ''; + + if (msgJSON.upgrade) { + // // document.getElementById('update-install').removeEventListener('click'); + document.getElementById('update_download_install').style = ''; + document.getElementById('update_download_install').addEventListener("click", updateConfClick) + } +} + +/** + * Footer Update button click handler + * Show confirmation popup + */ +function updateConfClick(msgJSON) {//alert(1); + //show modal popup + document.getElementById('update-conf-box').style = ''; + document.getElementById('update-conf-box').style = 'z-index: 1002'; + + // document.getElementById('update_download_install').style = ''; + // document.getElementById('update_download_install').addEventListener("click", startDownloading) + document.getElementById('update-conf-yes').style = ''; + document.getElementById('update-conf-yes').addEventListener("click", startDownloading) + +} +/** + * Start Download by sending message to main process + */ function startDownloading() { console.log('start-download') //Update confirm and notify main process ipcRendererUpdateWeb.send('update-main', 'update-start'); - document.getElementById('update-info').style = 'display: none;' + document.getElementById('update-info').style = 'display: none;'; document.getElementById('update-desc-box').style = 'display: none;'; + document.getElementById('update-conf-box').style = 'display: none;'; + document.getElementById('update-conf-yes').style = 'display: none;'; + document.getElementById('update-notify-box').style = ''; } + updateFor035(); /*** * Shows a popup for version 0.3.5 and lower to * download new update */ function updateFor035() { - console.log('[DTU]','updateFor035 > for v0.3.5 and lower', process.env.currentVersion); + console.log('[DTU]', 'updateFor035 > for v0.3.5 and lower', process.env.currentVersion); var currentVersion = process.env.currentVersion; // Checks env contains currentVersion for running application // For app v0.3.5 and lower currentVersion is not deined i.e. this check return true @@ -77,126 +175,126 @@ function updateFor035() { */ if (process.env.currentVersion) { -// window.AU_TOKEN = (window.AU_TOKEN || "71927ed58160df81ea3b24e9cf6ace3494fc2575"); -// window.AU_OWNER = (window.AU_OWNER || "NYNJA-MC"); -// window.AU_REPO = (window.AU_REPO || "electron-desktop-app"); -// window.AU_PROVIDER = (window.AU_PROVIDER || "github"); - -var autoUpdaterConfig = { - "DEV": { - "type": "config", "payload": { - "AU_TOKEN": window.AU_TOKEN || "71927ed58160df81ea3b24e9cf6ace3494fc2575", - "AU_OWNER": window.AU_OWNER || "NYNJA-MC", - "AU_REPO": window.AU_REPO || "electron-desktop-app-dev", - "AU_PROVIDER": window.AU_PROVIDER || "github" - } - }, - "STAGING": { - "type": "config", "payload": { - "AU_TOKEN": window.AU_TOKEN || "71927ed58160df81ea3b24e9cf6ace3494fc2575", - "AU_OWNER": window.AU_OWNER || "NYNJA-MC", - "AU_REPO": window.AU_REPO || "electron-desktop-app-staging", - "AU_PROVIDER": window.AU_PROVIDER || "github" + // window.AU_TOKEN = (window.AU_TOKEN || "71927ed58160df81ea3b24e9cf6ace3494fc2575"); + // window.AU_OWNER = (window.AU_OWNER || "NYNJA-MC"); + // window.AU_REPO = (window.AU_REPO || "electron-desktop-app"); + // window.AU_PROVIDER = (window.AU_PROVIDER || "github"); + + var autoUpdaterConfig = { + "DEV": { + "type": "config", "payload": { + "AU_TOKEN": window.AU_TOKEN || "71927ed58160df81ea3b24e9cf6ace3494fc2575", + "AU_OWNER": window.AU_OWNER || "NYNJA-MC", + "AU_REPO": window.AU_REPO || "electron-desktop-app-dev", + "AU_PROVIDER": window.AU_PROVIDER || "github" + } + }, + "STAGING": { + "type": "config", "payload": { + "AU_TOKEN": window.AU_TOKEN || "71927ed58160df81ea3b24e9cf6ace3494fc2575", + "AU_OWNER": window.AU_OWNER || "NYNJA-MC", + "AU_REPO": window.AU_REPO || "electron-desktop-app-staging", + "AU_PROVIDER": window.AU_PROVIDER || "github" + } + }, + "PROD": { + "type": "config", "payload": { + "AU_TOKEN": window.AU_TOKEN || "71927ed58160df81ea3b24e9cf6ace3494fc2575", + "AU_OWNER": window.AU_OWNER || "NYNJA-MC", + "AU_REPO": window.AU_REPO || "electron-desktop-app", + "AU_PROVIDER": window.AU_PROVIDER || "github" + } } - }, - "PROD": { - "type": "config", "payload": { - "AU_TOKEN": window.AU_TOKEN || "71927ed58160df81ea3b24e9cf6ace3494fc2575", - "AU_OWNER": window.AU_OWNER || "NYNJA-MC", - "AU_REPO": window.AU_REPO || "electron-desktop-app", - "AU_PROVIDER": window.AU_PROVIDER || "github" + } + var autoUpdaterAction = { + "type": "action", "payload": { + "AU_ACTION": "check-for-updates", + "AU_AUTO_DOWNLOAD": false, + "AU_AUTO_RESTART": true, } } -} -var autoUpdaterAction = { - "type": "action", "payload": { - "AU_ACTION": "check-for-updates", - "AU_AUTO_DOWNLOAD": false, - "AU_AUTO_RESTART": true, + + + /*** + * Handle autoUpdter for app v0.3.7 and higher + */ + ipcRendererUpdateWeb.on('auto-updater-config-request', function (event, message) { + //message --> DEV, STAGING, PROD + console.log('[DTU] [ipcRendererUpdateWeb] auto-updater-config-request > for v0.3.7+ message : ', message); + + message = (message && (message === 'DEV' || message === 'STAGING' || message === 'PROD') ? message : "PROD"); + + console.log('[DTU] [ipcRendererUpdateWeb] auto-updater-config-request > for v0.3.7+ message : ', message, 'autoUpdaterConfig[message] : ', autoUpdaterConfig[message]); + + ipcRendererUpdateWeb.send('auto-updater-config', JSON.stringify(autoUpdaterConfig[message])); + + console.log('[DTU] [ipcRendererUpdateWeb] auto-updater-config-request > for v0.3.7+ message : ', message, 'autoUpdaterAction : ', autoUpdaterAction); + ipcRendererUpdateWeb.send('auto-updater-config', JSON.stringify(autoUpdaterAction)); + }); + /*** + * Handle autoUpdter for app v0.3.6 + */ + if (process.env.currentVersion && process.env.currentVersion === '0.3.6') { + + var app_env = (window.location.host === 'web.dev.nynja.net' ? "DEV" : (window.location.host === 'web.dev.staging.net' ? "STAGING" : "PROD")); + + console.log('[DTU] [ipcRendererUpdateWeb] auto-updater-config > for v0.3.6 : ', 'app_env : ', app_env); + + ipcRendererUpdateWeb.send('auto-updater-config', JSON.stringify(autoUpdaterConfig[app_env])); + ipcRendererUpdateWeb.send('auto-updater-config', JSON.stringify(autoUpdaterAction)); } -} + //} + /** + * Listerner to receive number of unread messages + * for group and personal + * Send this information to native app to show + * badge on taskbar icon + * {p2p: number, group: boolean} + */ -/*** - * Handle autoUpdter for app v0.3.7 and higher - */ -ipcRendererUpdateWeb.on('auto-updater-config-request', function (event, message) { - //message --> DEV, STAGING, PROD - console.log('[DTU] [ipcRendererUpdateWeb] auto-updater-config-request > for v0.3.7+ message : ', message); - - message = (message && (message === 'DEV' || message === 'STAGING' || message === 'PROD') ? message : "PROD"); - - console.log('[DTU] [ipcRendererUpdateWeb] auto-updater-config-request > for v0.3.7+ message : ', message, 'autoUpdaterConfig[message] : ', autoUpdaterConfig[message]); - - ipcRendererUpdateWeb.send('auto-updater-config', JSON.stringify(autoUpdaterConfig[message])); - - console.log('[DTU] [ipcRendererUpdateWeb] auto-updater-config-request > for v0.3.7+ message : ', message, 'autoUpdaterAction : ', autoUpdaterAction); - ipcRendererUpdateWeb.send('auto-updater-config', JSON.stringify(autoUpdaterAction)); -}); -/*** - * Handle autoUpdter for app v0.3.6 - */ -if(process.env.currentVersion && process.env.currentVersion==='0.3.6'){ - - var app_env = (window.location.host==='web.dev.nynja.net'?"DEV":(window.location.host==='web.dev.staging.net'?"STAGING":"PROD")); - - console.log('[DTU] [ipcRendererUpdateWeb] auto-updater-config > for v0.3.6 : ', 'app_env : ', app_env); - - ipcRendererUpdateWeb.send('auto-updater-config', JSON.stringify(autoUpdaterConfig[app_env])); - ipcRendererUpdateWeb.send('auto-updater-config', JSON.stringify(autoUpdaterAction)); -} -//} + document.addEventListener('electron-notifications', function (e) { + try { -/** - * Listerner to receive number of unread messages - * for group and personal - * Send this information to native app to show - * badge on taskbar icon - * {p2p: number, group: boolean} -*/ + console.log('[DTU]', 'electron-notifications'); + console.log('[DTU]', 'electron-notifications > e.data', e.data); -document.addEventListener('electron-notifications', function (e) { - try { + var electron_notifications_data = e.data; - console.log('[DTU]', 'electron-notifications'); - console.log('[DTU]', 'electron-notifications > e.data', e.data); + if (electron_notifications_data) { - var electron_notifications_data = e.data; + if (navigator.userAgent.indexOf('Win') !== -1) { - if (electron_notifications_data) { + const elecNotifRes = ipcRendererUpdateWeb.sendSync('electron-notifications', JSON.stringify(electron_notifications_data)); + console.log('[DTU]', 'electron-notifications > elecNotifRes', elecNotifRes); + if (elecNotifRes === 'success') { - if (navigator.userAgent.indexOf('Win') !== -1) { + //var count = electron_notifications_data.p2p;//(electron_notifications_data.group?1:electron_notifications_data.p2p); + var count = (electron_notifications_data.group && electron_notifications_data.p2p === 0 ? 1 : electron_notifications_data.p2p); + ipcRendererUpdateWeb.sendSync('update-badge', count); + } else { - const elecNotifRes = ipcRendererUpdateWeb.sendSync('electron-notifications', JSON.stringify(electron_notifications_data)); - console.log('[DTU]', 'electron-notifications > elecNotifRes', elecNotifRes); - if (elecNotifRes === 'success') { - - //var count = electron_notifications_data.p2p;//(electron_notifications_data.group?1:electron_notifications_data.p2p); - var count = (electron_notifications_data.group && electron_notifications_data.p2p===0?1:electron_notifications_data.p2p); - ipcRendererUpdateWeb.sendSync('update-badge', count); - } else { + ipcRendererUpdateWeb.sendSync('update-badge', null); + } + } - ipcRendererUpdateWeb.sendSync('update-badge', null); + if (navigator.userAgent.indexOf('Mac') !== -1) { + const elecNotifRes = ipcRendererUpdateWeb.sendSync('electron-notifications', JSON.stringify(electron_notifications_data)); + console.log('[DTU]', 'electron-notifications > elecNotifRes', elecNotifRes); + // if (elecNotifRes === 'success') { + // } } - } + // ipcRendererUpdateWeb.send('electron-notifications', JSON.stringify(electron_notifications_data)); + } else { - if (navigator.userAgent.indexOf('Mac') !== -1) { - const elecNotifRes = ipcRendererUpdateWeb.sendSync('electron-notifications', JSON.stringify(electron_notifications_data)); - console.log('[DTU]', 'electron-notifications > elecNotifRes', elecNotifRes); - // if (elecNotifRes === 'success') { - // } + console.log('[DTU]', 'electron-notifications', 'electron_notifications_data undefined'); } - // ipcRendererUpdateWeb.send('electron-notifications', JSON.stringify(electron_notifications_data)); - } else { - console.log('[DTU]', 'electron-notifications', 'electron_notifications_data undefined'); - } - - } catch (err) { - console.error('[DTU]', 'electron-notifications', err); + } catch (err) { + console.error('[DTU]', 'electron-notifications', err); - } + } -}); + }); } diff --git a/src/assets/css/desktop-style.css b/src/assets/css/desktop-style.css index c24228c37..3a372e4b3 100644 --- a/src/assets/css/desktop-style.css +++ b/src/assets/css/desktop-style.css @@ -64,8 +64,11 @@ html , body{ color: #fff; border-radius: 10px; overflow: hidden; - min-width: 500px; - padding-left: 0px; + min-width: 550px; + padding-left: 0px; + min-height: 400px; + max-width: 550px; + max-height: 400px; } .modalFooter{ background: #4e4e4e; diff --git a/src/template.ejs b/src/template.ejs index d35a36244..8b2547dab 100644 --- a/src/template.ejs +++ b/src/template.ejs @@ -106,7 +106,30 @@ - + + + + + + +