Refactoring
This commit is contained in:
@@ -308,16 +308,29 @@ if (!instanceLock) {
|
|||||||
configurePrimaryApp();
|
configurePrimaryApp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AppFunctions = {
|
||||||
|
closeApplication,
|
||||||
|
detectScript,
|
||||||
|
dialog,
|
||||||
|
getCleanupReleases: () => cleanupReleases,
|
||||||
|
getMainWindow,
|
||||||
|
saveUiSettings,
|
||||||
|
setIsInstalling,
|
||||||
|
setTrayImage,
|
||||||
|
setWindowVisibility,
|
||||||
|
standardIPCReply,
|
||||||
|
unmountAllDrives: MountsIPC.unmountAllDrives,
|
||||||
|
};
|
||||||
|
|
||||||
AppIPC.addListeners(ipcMain, closeApplication, setWindowVisibility);
|
AppIPC.addListeners(ipcMain, AppFunctions);
|
||||||
ConfigIPC.addListeners(ipcMain, standardIPCReply);
|
ConfigIPC.addListeners(ipcMain, AppFunctions);
|
||||||
DaemonIPC.addListeners(ipcMain, standardIPCReply);
|
DaemonIPC.addListeners(ipcMain, AppFunctions);
|
||||||
DependencyIPC.addListeners(ipcMain, standardIPCReply);
|
DependencyIPC.addListeners(ipcMain, AppFunctions);
|
||||||
DownloadIPC.addListeners(ipcMain, standardIPCReply);
|
DownloadIPC.addListeners(ipcMain, AppFunctions);
|
||||||
FilesystemIPC.addListeners(ipcMain, getMainWindow, dialog);
|
FilesystemIPC.addListeners(ipcMain, AppFunctions);
|
||||||
MountsIPC.addListeners(ipcMain, setTrayImage, standardIPCReply);
|
MountsIPC.addListeners(ipcMain, AppFunctions);
|
||||||
PlatformIPC.addListeners(ipcMain, detectScript, saveUiSettings);
|
PlatformIPC.addListeners(ipcMain, AppFunctions);
|
||||||
ReleaseIPC.addListeners(ipcMain, () => cleanupReleases, standardIPCReply);
|
ReleaseIPC.addListeners(ipcMain, AppFunctions);
|
||||||
StateIPC.addListeners(ipcMain);
|
StateIPC.addListeners(ipcMain, AppFunctions);
|
||||||
SystemIPC.addListeners(ipcMain, closeApplication);
|
SystemIPC.addListeners(ipcMain, AppFunctions);
|
||||||
UpgradeIPC.addListeners(ipcMain, setIsInstalling, MountsIPC.unmountAllDrives, standardIPCReply);
|
UpgradeIPC.addListeners(ipcMain, AppFunctions);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const Constants = require('../../constants');
|
const Constants = require('../../constants');
|
||||||
|
|
||||||
const addListeners = (ipcMain, closeApplication, setWindowVisibility) => {
|
const addListeners = (ipcMain, {closeApplication, setWindowVisibility}) => {
|
||||||
ipcMain.on(Constants.IPC_Shutdown, () => {
|
ipcMain.on(Constants.IPC_Shutdown, () => {
|
||||||
closeApplication();
|
closeApplication();
|
||||||
});
|
});
|
||||||
@@ -17,4 +17,4 @@ const addListeners = (ipcMain, closeApplication, setWindowVisibility) => {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addListeners
|
addListeners
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const Constants = require('../../constants');
|
const Constants = require('../../constants');
|
||||||
const helpers = require('../../helpers');
|
const helpers = require('../../helpers');
|
||||||
|
|
||||||
const addListeners = (ipcMain, standardIPCReply) => {
|
const addListeners = (ipcMain, {standardIPCReply}) => {
|
||||||
ipcMain.on(Constants.IPC_Get_Config, (event, data) => {
|
ipcMain.on(Constants.IPC_Get_Config, (event, data) => {
|
||||||
helpers
|
helpers
|
||||||
.getConfig(data.Version, data.Provider, data.Remote)
|
.getConfig(data.Version, data.Provider, data.Remote)
|
||||||
@@ -53,4 +53,4 @@ const addListeners = (ipcMain, standardIPCReply) => {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addListeners
|
addListeners
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const Constants = require('../../constants');
|
const Constants = require('../../constants');
|
||||||
const helpers = require('../../helpers');
|
const helpers = require('../../helpers');
|
||||||
|
|
||||||
const addListeners = (ipcMain, standardIPCReply) => {
|
const addListeners = (ipcMain, {standardIPCReply}) => {
|
||||||
ipcMain.on(Constants.IPC_Check_Daemon_Version, (event, data) => {
|
ipcMain.on(Constants.IPC_Check_Daemon_Version, (event, data) => {
|
||||||
helpers
|
helpers
|
||||||
.checkDaemonVersion(data.Version, data.Provider)
|
.checkDaemonVersion(data.Version, data.Provider)
|
||||||
@@ -44,4 +44,4 @@ const addListeners = (ipcMain, standardIPCReply) => {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addListeners
|
addListeners
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const Constants = require('../../constants');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const helpers = require('../../helpers');
|
const helpers = require('../../helpers');
|
||||||
|
|
||||||
const addListeners = (ipcMain, standardIPCReply) => {
|
const addListeners = (ipcMain, {standardIPCReply}) => {
|
||||||
ipcMain.on(Constants.IPC_Check_Dependency_Installed, (event, data) => {
|
ipcMain.on(Constants.IPC_Check_Dependency_Installed, (event, data) => {
|
||||||
try {
|
try {
|
||||||
const exists = fs.lstatSync(data.File).isFile();
|
const exists = fs.lstatSync(data.File).isFile();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const Constants = require('../../constants');
|
|||||||
const helpers = require('../../helpers');
|
const helpers = require('../../helpers');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const addListeners = (ipcMain, standardIPCReply) => {
|
const addListeners = (ipcMain, {standardIPCReply}) => {
|
||||||
ipcMain.on(Constants.IPC_Download_File, (event, data) => {
|
ipcMain.on(Constants.IPC_Download_File, (event, data) => {
|
||||||
const destination = path.join(helpers.getDataDirectory(), data.Filename);
|
const destination = path.join(helpers.getDataDirectory(), data.Filename);
|
||||||
helpers.downloadFile(data.URL, destination, (progress) => {
|
helpers.downloadFile(data.URL, destination, (progress) => {
|
||||||
@@ -22,4 +22,4 @@ const addListeners = (ipcMain, standardIPCReply) => {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addListeners
|
addListeners
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const Constants = require('../../constants');
|
const Constants = require('../../constants');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const addListeners = (ipcMain, getMainWindow, dialog) => {
|
const addListeners = (ipcMain, {getMainWindow, dialog}) => {
|
||||||
ipcMain.on(Constants.IPC_Browse_Directory + '_sync', (event, data) => {
|
ipcMain.on(Constants.IPC_Browse_Directory + '_sync', (event, data) => {
|
||||||
dialog.showOpenDialog(getMainWindow(), {
|
dialog.showOpenDialog(getMainWindow(), {
|
||||||
defaultPath: data.Location,
|
defaultPath: data.Location,
|
||||||
@@ -28,4 +28,4 @@ const addListeners = (ipcMain, getMainWindow, dialog) => {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addListeners
|
addListeners
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ const unmountAllDrives = () => {
|
|||||||
mountedData = {};
|
mountedData = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
const addListeners = (ipcMain, setTrayImage, standardIPCReply) => {
|
const addListeners = (ipcMain, {setTrayImage, standardIPCReply}) => {
|
||||||
ipcMain.on(Constants.IPC_Check_Mount_Location + '_sync', (event, data) => {
|
ipcMain.on(Constants.IPC_Check_Mount_Location + '_sync', (event, data) => {
|
||||||
let response = {
|
let response = {
|
||||||
Success: true,
|
Success: true,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const setPlatformOverride = platformOverride => {
|
|||||||
_platformOverride = platformOverride;
|
_platformOverride = platformOverride;
|
||||||
};
|
};
|
||||||
|
|
||||||
const addListeners = (ipcMain, detectScript, saveUiSettings) => {
|
const addListeners = (ipcMain, {detectScript, saveUiSettings}) => {
|
||||||
ipcMain.on(Constants.IPC_Get_Platform, (event) => {
|
ipcMain.on(Constants.IPC_Get_Platform, (event) => {
|
||||||
const sendResponse = (appPlatform, platform) => {
|
const sendResponse = (appPlatform, platform) => {
|
||||||
event.sender.send(Constants.IPC_Get_Platform_Reply, {
|
event.sender.send(Constants.IPC_Get_Platform_Reply, {
|
||||||
@@ -76,4 +76,4 @@ module.exports = {
|
|||||||
getPlatformOverride,
|
getPlatformOverride,
|
||||||
setPlatformOverride,
|
setPlatformOverride,
|
||||||
addListeners
|
addListeners
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const os = require('os');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const unzip = require('unzipper');
|
const unzip = require('unzipper');
|
||||||
|
|
||||||
const addListeners = (ipcMain, getCleanupReleases, standardIPCReply) => {
|
const addListeners = (ipcMain, {getCleanupReleases, standardIPCReply}) => {
|
||||||
ipcMain.on(Constants.IPC_Check_Installed, (event, data) => {
|
ipcMain.on(Constants.IPC_Check_Installed, (event, data) => {
|
||||||
const destination = path.join(helpers.getDataDirectory(), data.Version);
|
const destination = path.join(helpers.getDataDirectory(), data.Version);
|
||||||
helpers
|
helpers
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const Constants = require('../../constants');
|
|||||||
const os = require('os');
|
const os = require('os');
|
||||||
const helpers = require('../../helpers');
|
const helpers = require('../../helpers');
|
||||||
|
|
||||||
const addListeners = (ipcMain, closeApplication) => {
|
const addListeners = (ipcMain, {closeApplication}) => {
|
||||||
ipcMain.on(Constants.IPC_Reboot_System, () => {
|
ipcMain.on(Constants.IPC_Reboot_System, () => {
|
||||||
if (os.platform() === 'win32') {
|
if (os.platform() === 'win32') {
|
||||||
helpers.executeAsync('shutdown.exe', ['/r', '/t', '30']);
|
helpers.executeAsync('shutdown.exe', ['/r', '/t', '30']);
|
||||||
@@ -13,4 +13,4 @@ const addListeners = (ipcMain, closeApplication) => {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addListeners
|
addListeners
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const fs = require('fs');
|
|||||||
const helpers = require('../../helpers');
|
const helpers = require('../../helpers');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
|
|
||||||
const addListeners = (ipcMain, setIsInstalling, unmountAllDrives, standardIPCReply) => {
|
const addListeners = (ipcMain, {setIsInstalling, unmountAllDrives, standardIPCReply}) => {
|
||||||
ipcMain.on(Constants.IPC_Install_Upgrade, (event, data) => {
|
ipcMain.on(Constants.IPC_Install_Upgrade, (event, data) => {
|
||||||
let allowSkipVerification = true;
|
let allowSkipVerification = true;
|
||||||
|
|
||||||
@@ -113,4 +113,4 @@ const addListeners = (ipcMain, setIsInstalling, unmountAllDrives, standardIPCRep
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addListeners
|
addListeners
|
||||||
};
|
};
|
||||||
|
|||||||
25
src/utils.js
25
src/utils.js
@@ -7,6 +7,21 @@ const ipcRenderer = (!process.versions.hasOwnProperty('electron') && window && w
|
|||||||
window.require('electron').ipcRenderer :
|
window.require('electron').ipcRenderer :
|
||||||
null;
|
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) => {
|
export const createModalConditionally = (condition, jsx, critical, disableFocusTrap) => {
|
||||||
const modalProps = {critical: critical, disableFocusTrap: disableFocusTrap};
|
const modalProps = {critical: critical, disableFocusTrap: disableFocusTrap};
|
||||||
return condition ? (<Modal {...modalProps}>{jsx}</Modal>) : null;
|
return condition ? (<Modal {...modalProps}>{jsx}</Modal>) : null;
|
||||||
@@ -62,7 +77,7 @@ export const getIPCRenderer = () => {
|
|||||||
return ipcRenderer;
|
return ipcRenderer;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getNewReleases = (existingReleases, newReleases) => {
|
export const getNewReleases = (existingLocations, newLocations) => {
|
||||||
const ret = [];
|
const ret = [];
|
||||||
|
|
||||||
/*existingReleases = Constants.RELEASE_TYPES.reduce((map, release) => {
|
/*existingReleases = Constants.RELEASE_TYPES.reduce((map, release) => {
|
||||||
@@ -70,15 +85,15 @@ export const getNewReleases = (existingReleases, newReleases) => {
|
|||||||
return map;
|
return map;
|
||||||
}, {});*/
|
}, {});*/
|
||||||
|
|
||||||
if (existingReleases && newReleases) {
|
if (existingLocations && newLocations) {
|
||||||
Constants.RELEASE_TYPES.forEach(release => {
|
Constants.RELEASE_TYPES.forEach(release => {
|
||||||
newReleases[release]
|
newLocations[release]
|
||||||
.filter(version => !existingReleases[release].includes(version) && (version !== 'unavailable'))
|
.filter(version => !existingLocations[release].includes(version) && (version !== 'unavailable'))
|
||||||
.forEach(version => {
|
.forEach(version => {
|
||||||
ret.splice(0, 0, {
|
ret.splice(0, 0, {
|
||||||
Display: version,
|
Display: version,
|
||||||
Release: Constants.RELEASE_TYPES.indexOf(release),
|
Release: Constants.RELEASE_TYPES.indexOf(release),
|
||||||
Version: newReleases[release].indexOf(version),
|
Version: newLocations[release].indexOf(version),
|
||||||
VersionString: version,
|
VersionString: version,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user