From acb8e5966004d81cc15445308de6481782c8d44a Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sat, 22 Feb 2020 19:17:11 -0600 Subject: [PATCH] Refactoring --- public/electron.js | 37 +++++++++++++++++++++---------- src/renderer/ipc/AppIPC.js | 4 ++-- src/renderer/ipc/ConfigIPC.js | 4 ++-- src/renderer/ipc/DaemonIPC.js | 4 ++-- src/renderer/ipc/DependencyIPC.js | 2 +- src/renderer/ipc/DownloadIPC.js | 4 ++-- src/renderer/ipc/FilesystemIPC.js | 4 ++-- src/renderer/ipc/MountsIPC.js | 2 +- src/renderer/ipc/PlatformIPC.js | 4 ++-- src/renderer/ipc/ReleaseIPC.js | 2 +- src/renderer/ipc/SystemIPC.js | 4 ++-- src/renderer/ipc/UpgradeIPC.js | 4 ++-- src/utils.js | 25 ++++++++++++++++----- 13 files changed, 64 insertions(+), 36 deletions(-) diff --git a/public/electron.js b/public/electron.js index c65de22..e01a3cb 100644 --- a/public/electron.js +++ b/public/electron.js @@ -308,16 +308,29 @@ if (!instanceLock) { configurePrimaryApp(); } +const AppFunctions = { + closeApplication, + detectScript, + dialog, + getCleanupReleases: () => cleanupReleases, + getMainWindow, + saveUiSettings, + setIsInstalling, + setTrayImage, + setWindowVisibility, + standardIPCReply, + unmountAllDrives: MountsIPC.unmountAllDrives, +}; -AppIPC.addListeners(ipcMain, closeApplication, setWindowVisibility); -ConfigIPC.addListeners(ipcMain, standardIPCReply); -DaemonIPC.addListeners(ipcMain, standardIPCReply); -DependencyIPC.addListeners(ipcMain, standardIPCReply); -DownloadIPC.addListeners(ipcMain, standardIPCReply); -FilesystemIPC.addListeners(ipcMain, getMainWindow, dialog); -MountsIPC.addListeners(ipcMain, setTrayImage, standardIPCReply); -PlatformIPC.addListeners(ipcMain, detectScript, saveUiSettings); -ReleaseIPC.addListeners(ipcMain, () => cleanupReleases, standardIPCReply); -StateIPC.addListeners(ipcMain); -SystemIPC.addListeners(ipcMain, closeApplication); -UpgradeIPC.addListeners(ipcMain, setIsInstalling, MountsIPC.unmountAllDrives, standardIPCReply); +AppIPC.addListeners(ipcMain, AppFunctions); +ConfigIPC.addListeners(ipcMain, AppFunctions); +DaemonIPC.addListeners(ipcMain, AppFunctions); +DependencyIPC.addListeners(ipcMain, AppFunctions); +DownloadIPC.addListeners(ipcMain, AppFunctions); +FilesystemIPC.addListeners(ipcMain, AppFunctions); +MountsIPC.addListeners(ipcMain, AppFunctions); +PlatformIPC.addListeners(ipcMain, AppFunctions); +ReleaseIPC.addListeners(ipcMain, AppFunctions); +StateIPC.addListeners(ipcMain, AppFunctions); +SystemIPC.addListeners(ipcMain, AppFunctions); +UpgradeIPC.addListeners(ipcMain, AppFunctions); diff --git a/src/renderer/ipc/AppIPC.js b/src/renderer/ipc/AppIPC.js index 4fdd3da..9473440 100644 --- a/src/renderer/ipc/AppIPC.js +++ b/src/renderer/ipc/AppIPC.js @@ -1,6 +1,6 @@ const Constants = require('../../constants'); -const addListeners = (ipcMain, closeApplication, setWindowVisibility) => { +const addListeners = (ipcMain, {closeApplication, setWindowVisibility}) => { ipcMain.on(Constants.IPC_Shutdown, () => { closeApplication(); }); @@ -17,4 +17,4 @@ const addListeners = (ipcMain, closeApplication, setWindowVisibility) => { module.exports = { addListeners -}; \ No newline at end of file +}; diff --git a/src/renderer/ipc/ConfigIPC.js b/src/renderer/ipc/ConfigIPC.js index 76bba25..a609eda 100644 --- a/src/renderer/ipc/ConfigIPC.js +++ b/src/renderer/ipc/ConfigIPC.js @@ -1,7 +1,7 @@ const Constants = require('../../constants'); const helpers = require('../../helpers'); -const addListeners = (ipcMain, standardIPCReply) => { +const addListeners = (ipcMain, {standardIPCReply}) => { ipcMain.on(Constants.IPC_Get_Config, (event, data) => { helpers .getConfig(data.Version, data.Provider, data.Remote) @@ -53,4 +53,4 @@ const addListeners = (ipcMain, standardIPCReply) => { module.exports = { addListeners -}; \ No newline at end of file +}; diff --git a/src/renderer/ipc/DaemonIPC.js b/src/renderer/ipc/DaemonIPC.js index c563c1c..6e4ec62 100644 --- a/src/renderer/ipc/DaemonIPC.js +++ b/src/renderer/ipc/DaemonIPC.js @@ -1,7 +1,7 @@ const Constants = require('../../constants'); const helpers = require('../../helpers'); -const addListeners = (ipcMain, standardIPCReply) => { +const addListeners = (ipcMain, {standardIPCReply}) => { ipcMain.on(Constants.IPC_Check_Daemon_Version, (event, data) => { helpers .checkDaemonVersion(data.Version, data.Provider) @@ -44,4 +44,4 @@ const addListeners = (ipcMain, standardIPCReply) => { module.exports = { addListeners -}; \ No newline at end of file +}; diff --git a/src/renderer/ipc/DependencyIPC.js b/src/renderer/ipc/DependencyIPC.js index ffb9907..f6945e0 100644 --- a/src/renderer/ipc/DependencyIPC.js +++ b/src/renderer/ipc/DependencyIPC.js @@ -2,7 +2,7 @@ const Constants = require('../../constants'); const fs = require('fs'); const helpers = require('../../helpers'); -const addListeners = (ipcMain, standardIPCReply) => { +const addListeners = (ipcMain, {standardIPCReply}) => { ipcMain.on(Constants.IPC_Check_Dependency_Installed, (event, data) => { try { const exists = fs.lstatSync(data.File).isFile(); diff --git a/src/renderer/ipc/DownloadIPC.js b/src/renderer/ipc/DownloadIPC.js index 1492ea9..366d72e 100644 --- a/src/renderer/ipc/DownloadIPC.js +++ b/src/renderer/ipc/DownloadIPC.js @@ -2,7 +2,7 @@ const Constants = require('../../constants'); const helpers = require('../../helpers'); const path = require('path'); -const addListeners = (ipcMain, standardIPCReply) => { +const addListeners = (ipcMain, {standardIPCReply}) => { ipcMain.on(Constants.IPC_Download_File, (event, data) => { const destination = path.join(helpers.getDataDirectory(), data.Filename); helpers.downloadFile(data.URL, destination, (progress) => { @@ -22,4 +22,4 @@ const addListeners = (ipcMain, standardIPCReply) => { module.exports = { addListeners -}; \ No newline at end of file +}; diff --git a/src/renderer/ipc/FilesystemIPC.js b/src/renderer/ipc/FilesystemIPC.js index 1294e76..cb71d62 100644 --- a/src/renderer/ipc/FilesystemIPC.js +++ b/src/renderer/ipc/FilesystemIPC.js @@ -1,7 +1,7 @@ const Constants = require('../../constants'); const fs = require('fs'); -const addListeners = (ipcMain, getMainWindow, dialog) => { +const addListeners = (ipcMain, {getMainWindow, dialog}) => { ipcMain.on(Constants.IPC_Browse_Directory + '_sync', (event, data) => { dialog.showOpenDialog(getMainWindow(), { defaultPath: data.Location, @@ -28,4 +28,4 @@ const addListeners = (ipcMain, getMainWindow, dialog) => { module.exports = { addListeners -}; \ No newline at end of file +}; diff --git a/src/renderer/ipc/MountsIPC.js b/src/renderer/ipc/MountsIPC.js index 4b6cfe8..8cd5b37 100644 --- a/src/renderer/ipc/MountsIPC.js +++ b/src/renderer/ipc/MountsIPC.js @@ -62,7 +62,7 @@ const unmountAllDrives = () => { mountedData = {}; }; -const addListeners = (ipcMain, setTrayImage, standardIPCReply) => { +const addListeners = (ipcMain, {setTrayImage, standardIPCReply}) => { ipcMain.on(Constants.IPC_Check_Mount_Location + '_sync', (event, data) => { let response = { Success: true, diff --git a/src/renderer/ipc/PlatformIPC.js b/src/renderer/ipc/PlatformIPC.js index f55a35c..16ec438 100644 --- a/src/renderer/ipc/PlatformIPC.js +++ b/src/renderer/ipc/PlatformIPC.js @@ -14,7 +14,7 @@ const setPlatformOverride = platformOverride => { _platformOverride = platformOverride; }; -const addListeners = (ipcMain, detectScript, saveUiSettings) => { +const addListeners = (ipcMain, {detectScript, saveUiSettings}) => { ipcMain.on(Constants.IPC_Get_Platform, (event) => { const sendResponse = (appPlatform, platform) => { event.sender.send(Constants.IPC_Get_Platform_Reply, { @@ -76,4 +76,4 @@ module.exports = { getPlatformOverride, setPlatformOverride, addListeners -}; \ No newline at end of file +}; diff --git a/src/renderer/ipc/ReleaseIPC.js b/src/renderer/ipc/ReleaseIPC.js index f76fcf8..f2d7a77 100644 --- a/src/renderer/ipc/ReleaseIPC.js +++ b/src/renderer/ipc/ReleaseIPC.js @@ -5,7 +5,7 @@ const os = require('os'); const path = require('path'); const unzip = require('unzipper'); -const addListeners = (ipcMain, getCleanupReleases, standardIPCReply) => { +const addListeners = (ipcMain, {getCleanupReleases, standardIPCReply}) => { ipcMain.on(Constants.IPC_Check_Installed, (event, data) => { const destination = path.join(helpers.getDataDirectory(), data.Version); helpers diff --git a/src/renderer/ipc/SystemIPC.js b/src/renderer/ipc/SystemIPC.js index 52ebb2f..a6298c5 100644 --- a/src/renderer/ipc/SystemIPC.js +++ b/src/renderer/ipc/SystemIPC.js @@ -2,7 +2,7 @@ const Constants = require('../../constants'); const os = require('os'); const helpers = require('../../helpers'); -const addListeners = (ipcMain, closeApplication) => { +const addListeners = (ipcMain, {closeApplication}) => { ipcMain.on(Constants.IPC_Reboot_System, () => { if (os.platform() === 'win32') { helpers.executeAsync('shutdown.exe', ['/r', '/t', '30']); @@ -13,4 +13,4 @@ const addListeners = (ipcMain, closeApplication) => { module.exports = { addListeners -}; \ No newline at end of file +}; diff --git a/src/renderer/ipc/UpgradeIPC.js b/src/renderer/ipc/UpgradeIPC.js index 7bdc24c..b717ab8 100644 --- a/src/renderer/ipc/UpgradeIPC.js +++ b/src/renderer/ipc/UpgradeIPC.js @@ -3,7 +3,7 @@ const fs = require('fs'); const helpers = require('../../helpers'); const os = require('os'); -const addListeners = (ipcMain, setIsInstalling, unmountAllDrives, standardIPCReply) => { +const addListeners = (ipcMain, {setIsInstalling, unmountAllDrives, standardIPCReply}) => { ipcMain.on(Constants.IPC_Install_Upgrade, (event, data) => { let allowSkipVerification = true; @@ -113,4 +113,4 @@ const addListeners = (ipcMain, setIsInstalling, unmountAllDrives, standardIPCRep module.exports = { addListeners -}; \ No newline at end of file +}; diff --git a/src/utils.js b/src/utils.js index 2448039..ab8f565 100644 --- a/src/utils.js +++ b/src/utils.js @@ -7,6 +7,21 @@ const ipcRenderer = (!process.versions.hasOwnProperty('electron') && window && w window.require('electron').ipcRenderer : null; +export const checkNewReleases = () => { + let previousReleases = localStorage.getItem('previous_releases'); + if (previousReleases) { + previousReleases = JSON.parse(previousReleases).VersionLookup; + + let currentReleases = localStorage.getItem('releases'); + if (currentReleases) { + currentReleases = JSON.parse(currentReleases).VersionLookup; + return getNewReleases(previousReleases, currentReleases); + } + } + + return []; +}; + export const createModalConditionally = (condition, jsx, critical, disableFocusTrap) => { const modalProps = {critical: critical, disableFocusTrap: disableFocusTrap}; return condition ? ({jsx}) : null; @@ -62,7 +77,7 @@ export const getIPCRenderer = () => { return ipcRenderer; }; -export const getNewReleases = (existingReleases, newReleases) => { +export const getNewReleases = (existingLocations, newLocations) => { const ret = []; /*existingReleases = Constants.RELEASE_TYPES.reduce((map, release) => { @@ -70,15 +85,15 @@ export const getNewReleases = (existingReleases, newReleases) => { return map; }, {});*/ - if (existingReleases && newReleases) { + if (existingLocations && newLocations) { Constants.RELEASE_TYPES.forEach(release => { - newReleases[release] - .filter(version => !existingReleases[release].includes(version) && (version !== 'unavailable')) + newLocations[release] + .filter(version => !existingLocations[release].includes(version) && (version !== 'unavailable')) .forEach(version => { ret.splice(0, 0, { Display: version, Release: Constants.RELEASE_TYPES.indexOf(release), - Version: newReleases[release].indexOf(version), + Version: newLocations[release].indexOf(version), VersionString: version, }); });