Refactoring

This commit is contained in:
2020-02-22 19:17:11 -06:00
parent 12ad878618
commit acb8e59660
13 changed files with 64 additions and 36 deletions

View File

@@ -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
};
};

View File

@@ -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
};
};

View File

@@ -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
};
};

View File

@@ -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();

View File

@@ -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
};
};

View File

@@ -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
};
};

View File

@@ -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,

View File

@@ -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
};
};

View File

@@ -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

View File

@@ -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
};
};

View File

@@ -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
};
};

View File

@@ -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 ? (<Modal {...modalProps}>{jsx}</Modal>) : 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,
});
});