diff --git a/electron.js b/electron.js index a5cfec8..428e275 100644 --- a/electron.js +++ b/electron.js @@ -26,6 +26,7 @@ function createWindow() { width: 425, height: height, resizable: false, + title: 'Repertory UI', webPreferences: { webSecurity: !process.env.ELECTRON_START_URL } @@ -138,6 +139,16 @@ if (!instanceLock) { }); } +const standardIPCReply = (event, channel, data, error) => { + event.sender.send(channel, { + data: { + ...data, + Error: error, + Success: !error, + } + }); +}; + ipcMain.on(Constants.IPC_Check_Installed, (event, data) => { const dataDirectory = helpers.resolvePath(data.Directory); const destination = path.join(dataDirectory, data.Version); @@ -149,23 +160,16 @@ ipcMain.on(Constants.IPC_Check_Installed, (event, data) => { exists = fs.existsSync(destination) && fs.lstatSync(destination).isDirectory(); } catch (e) { } - event.sender.send(Constants.IPC_Check_Installed_Reply, { - data: { - Dependencies: dependencies, - Exists: exists, - Success: true, - Version: data.Version, - } - }); - }).catch((e) => { - event.sender.send(Constants.IPC_Check_Installed_Reply, { - data: { - Dependencies: [], - Error: e, - Success: false, - Version: data.Version, - } + standardIPCReply(event, Constants.IPC_Check_Installed_Reply, { + Dependencies: dependencies, + Exists: exists, + Version: data.Version, }); + }).catch(error => { + standardIPCReply(event, Constants.IPC_Check_Installed_Reply, { + Dependencies: [], + Version: data.Version, + }, error); }); }); @@ -226,31 +230,23 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => { siaLocation = siaLocation.toUpperCase(); grabDriveLetters(hsLocation, siaLocation); } - event.sender.send(Constants.IPC_Detect_Mounts_Reply, { - data: { - DriveLetters: driveLetters, - Locations: { - Hyperspace: hsLocation, - Sia: siaLocation, - }, - Success: true, - PIDS: { - Hyperspace: results.Hyperspace.PID, - Sia: results.Sia.PID, - } + standardIPCReply(event, Constants.IPC_Detect_Mounts_Reply, { + DriveLetters: driveLetters, + Locations: { + Hyperspace: hsLocation, + Sia: siaLocation, + }, + PIDS: { + Hyperspace: results.Hyperspace.PID, + Sia: results.Sia.PID, } }); }) - .catch((err) => { + .catch(error => { grabDriveLetters('', ''); - - event.sender.send(Constants.IPC_Detect_Mounts_Reply, { - data: { - DriveLetters: driveLetters, - Error: err, - Success: false, - } - }); + standardIPCReply(event, Constants.IPC_Detect_Mounts_Reply, { + DriveLetters: driveLetters, + }, error); }); }); @@ -258,22 +254,16 @@ ipcMain.on(Constants.IPC_Download_File, (event, data) => { const dataDirectory = helpers.resolvePath(data.Directory); const destination = path.join(dataDirectory, data.Filename); helpers.downloadFile(data.URL, destination, (progress) => { - event.sender.send(Constants.IPC_Download_File_Progress, { - data: { - Destination: destination, - Progress: progress, - URL: data.URL, - } - }); - }, (success, err) => { - event.sender.send(Constants.IPC_Download_File_Complete, { - data: { - Destination: destination, - Error: err, - Success: success, - URL: data.URL, - } + standardIPCReply(event, Constants.IPC_Download_File_Progress, { + Destination: destination, + Progress: progress, + URL: data.URL, }); + }, error => { + standardIPCReply(event, Constants.IPC_Download_File_Complete, { + Destination: destination, + URL: data.URL, + }, error); }); }); @@ -285,27 +275,20 @@ ipcMain.on(Constants.IPC_Extract_Release, (event, data) => { const stream = fs.createReadStream(data.Source); stream .pipe(unzip.Extract({ path: destination })) - .on('error', (e) => { + .on('error', error => { try { helpers.removeDirectoryRecursively(destination); } catch (e) { } stream.close(); - event.sender.send(Constants.IPC_Extract_Release_Complete, { - data: { - Error: e, - Source: data.Source, - Success: false, - } - }); + standardIPCReply(event, Constants.IPC_Extract_Release_Complete, { + Source: data.Source, + }, error); }) .on('finish', () => { stream.close(); - event.sender.send(Constants.IPC_Extract_Release_Complete, { - data: { - Source: data.Source, - Success: true, - } + standardIPCReply(event, Constants.IPC_Extract_Release_Complete, { + Source: data.Source, }); }); }); @@ -316,28 +299,15 @@ ipcMain.on(Constants.IPC_Get_Config, (event, data) => { .getConfig(dataDirectory, data.Version, data.StorageType) .then((data) => { if (data.Code === 0) { - event.sender.send(Constants.IPC_Get_Config_Reply, { - data: { - Success: true, - Config: data.Data, - } + standardIPCReply(event, Constants.IPC_Get_Config_Reply, { + Config: data.Data, }); } else { - event.sender.send(Constants.IPC_Get_Config_Reply, { - data: { - Error: data.Code, - Success: false, - } - }); + standardIPCReply(event, Constants.IPC_Get_Config_Reply, {}, data.Code); } }) - .catch((e)=> { - event.sender.send(Constants.IPC_Get_Config_Reply, { - data: { - Error: e, - Success: false, - } - }); + .catch(error => { + standardIPCReply(event, Constants.IPC_Get_Config_Reply, {}, error); }); }); @@ -346,20 +316,12 @@ ipcMain.on(Constants.IPC_Get_Config_Template, (event, data) => { helpers .getConfigTemplate(dataDirectory, data.Version, data.StorageType) .then((data) => { - event.sender.send(Constants.IPC_Get_Config_Template_Reply, { - data: { - Success: true, - Template: data, - } + standardIPCReply(event, Constants.IPC_Get_Config_Template_Reply, { + Template: data, }); }) - .catch((e)=> { - event.sender.send(Constants.IPC_Get_Config_Template_Reply, { - data: { - Error: e, - Success: false, - } - }); + .catch(error => { + standardIPCReply(event, Constants.IPC_Get_Config_Template_Reply, {}, error); }); }); @@ -385,32 +347,25 @@ ipcMain.on(Constants.IPC_Get_State, (event, data) => { }); ipcMain.on(Constants.IPC_Grab_Releases, (event) => { - event.sender.send(Constants.IPC_Grab_Releases_Reply); + standardIPCReply(event, Constants.IPC_Grab_Releases_Reply); }); ipcMain.on(Constants.IPC_Grab_UI_Releases, (event) => { - event.sender.send(Constants.IPC_Grab_UI_Releases_Reply); + standardIPCReply(event, Constants.IPC_Grab_UI_Releases_Reply); }); ipcMain.on(Constants.IPC_Install_Dependency, (event, data) => { helpers .executeAndWait(data.Source) .then(()=> { - event.sender.send(Constants.IPC_Install_Dependency_Reply, { - data: { - Source: data.Source, - Success: true, - } + standardIPCReply(event, Constants.IPC_Install_Dependency_Reply, { + Source: data.Source, }); }) - .catch((e)=> { - event.sender.send(Constants.IPC_Install_Dependency_Reply, { - data: { - Error: e, - Source: data.Source, - Success: false, - } - }); + .catch(error => { + standardIPCReply(event, Constants.IPC_Install_Dependency_Reply, { + Source: data.Source, + }, error); }); }); @@ -420,46 +375,36 @@ ipcMain.on(Constants.IPC_Install_Upgrade, (event, data) => { .then(()=> { mainWindow.close(); }) - .catch((e)=> { - event.sender.send(Constants.IPC_Install_Upgrade_Reply, { - data: { - Error: e, - Source: data.Source, - Success: false, - } - }); + .catch(error => { + standardIPCReply(event, Constants.IPC_Install_Upgrade_Reply, { + Source: data.Source, + }, error); }); }); ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => { const dataDirectory = helpers.resolvePath(data.Directory); - const errorHandler = (pid) => { + const errorHandler = (pid, error) => { mountedPIDs.splice(mountedPIDs.indexOf(pid), 1); - event.sender.send(Constants.IPC_Unmount_Drive_Reply, { - data: { - PID: -1, - StorageType: data.StorageType, - Success: false, - } - }); + standardIPCReply(event, Constants.IPC_Unmount_Drive_Reply, { + PID: -1, + StorageType: data.StorageType, + }, error || Error(data.StorageType + ' Unmounted')); }; - helpers.executeMount(dataDirectory, data.Version, data.StorageType, data.Location, (_, pid)=> { - errorHandler(pid); + helpers.executeMount(dataDirectory, data.Version, data.StorageType, data.Location, (error, pid) => { + errorHandler(pid, error); }) - .then(pid=> { + .then(pid => { if (pid !== -1) { mountedPIDs.push(pid); } - event.sender.send(Constants.IPC_Mount_Drive_Reply, { - data: { - PID: pid, - StorageType: data.StorageType, - Success: true, - } + standardIPCReply(event, Constants.IPC_Mount_Drive_Reply, { + PID: pid, + StorageType: data.StorageType, }); }) - .catch((_, pid) => { - errorHandler(pid); + .catch(error => { + errorHandler(-1, error); }); }); @@ -483,7 +428,7 @@ ipcMain.on(Constants.IPC_Set_Config_Values, (event, data) => { setConfigValue(++i); }); } else { - event.sender.send(Constants.IPC_Set_Config_Values_Reply, {}); + standardIPCReply(event, Constants.IPC_Set_Config_Values_Reply, {}); } }; setConfigValue(0); diff --git a/helpers.js b/helpers.js index 7564a12..c88b27e 100644 --- a/helpers.js +++ b/helpers.js @@ -80,18 +80,18 @@ module.exports.downloadFile = (url, destination, progressCallback, completeCallb response.data.on('end', () => { stream.end(() => { - completeCallback(true); + completeCallback(); }); }); response.data.on('error', (e) => { stream.end(() => { - completeCallback(false, e); + completeCallback(e); }); }); }) .catch((e)=> { - completeCallback(false, e); + completeCallback(e); }); }; diff --git a/releases.json b/releases.json index f1be4a9..e8f7485 100644 --- a/releases.json +++ b/releases.json @@ -1,6 +1,10 @@ { "Locations": { "win32": { + "1.0.1": { + "hash": "", + "urls": [] + }, "1.0.0": { "hash": "", "urls": [ @@ -11,6 +15,7 @@ }, "Versions": { "win32": [ + "1.0.1", "1.0.0" ] } diff --git a/src/App.js b/src/App.js index 277f2cb..e776027 100644 --- a/src/App.js +++ b/src/App.js @@ -48,6 +48,9 @@ class App extends Component { AllowDownload: false, AutoMountChecked: false, ConfigStorageType: null, + DisplayError: false, + Error: null, + ErrorAction: null, DownloadActive: false, DownloadProgress: 0.0, DownloadingDependency: false, @@ -280,27 +283,35 @@ class App extends Component { notifyMountsBusy = (busy) => { this.setState({MountsBusy: busy}) }; - + onCheckInstalledReply = (event, arg) => { - const repertoryVersion = arg.data.Success && arg.data.Exists ? arg.data.Version : 'none'; - let versionAvailable = false; + const action = () => { + const repertoryVersion = arg.data.Success && arg.data.Exists ? arg.data.Version : 'none'; + let versionAvailable = false; - if (repertoryVersion !== 'none') { - const latestVersion = this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]].length - 1; - let version = this.state.Version; - if (version === -1) { - version = latestVersion; + if (repertoryVersion !== 'none') { + const latestVersion = this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]].length - 1; + let version = this.state.Version; + if (version === -1) { + version = latestVersion; + } + versionAvailable = version !== latestVersion; } - versionAvailable = version !== latestVersion; - } - this.setState({ - AllowDownload: true, - DownloadingDependency: false, - MissingDependencies: arg.data.Dependencies, - RepertoryVersion: repertoryVersion, - VersionAvailable: versionAvailable, - }); + this.setState({ + AllowDownload: true, + DownloadingDependency: false, + MissingDependencies: arg.data.Dependencies, + RepertoryVersion: repertoryVersion, + VersionAvailable: versionAvailable, + }); + }; + + if (arg.data.Success) { + action(); + } else { + this.setErrorState(arg.data.Error, action); + } }; onDownloadFileComplete = (event, arg) => { @@ -506,6 +517,14 @@ class App extends Component { } }; + setErrorState = (error, action) => { + this.setState({ + DisplayError: true, + Error: error, + ErrorAction: action, + }); + }; + updateCheckScheduledJob = () => { if (this.state.Platform !== 'unknown') { if (ipcRenderer) { @@ -537,12 +556,18 @@ class App extends Component { this.state.ConfigStorageType && allowConfig; - const showUpgrade = !showConfig && + const showUpgrade = !this.state.DisplayError && + !showConfig && !missingDependencies && !this.state.DownloadActive && this.state.UpgradeAvailable && !this.state.UpgradeDismissed; + let errorDisplay = null; + if (this.state.DisplayError) { + + } + let configDisplay = null; if (showConfig) { configDisplay = ( @@ -664,6 +689,7 @@ class App extends Component { return (