From 234785180a7541848f76d2d6d35c2c1cd1f792d0 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 24 May 2019 12:38:31 -0500 Subject: [PATCH] #22: Display error if daemon version is too low --- public/electron.js | 38 +++++++++++++++++++++++++ src/containers/MountItems/MountItems.js | 20 ++++++++----- src/helpers.js | 28 ++++++++++++++++++ 3 files changed, 79 insertions(+), 7 deletions(-) diff --git a/public/electron.js b/public/electron.js index 2cbb403..b42a955 100644 --- a/public/electron.js +++ b/public/electron.js @@ -278,6 +278,44 @@ ipcMain.on(Constants.IPC_Browse_Directory + '_sync', (event, data) => { }); }); +ipcMain.on(Constants.IPC_Check_Daemon_Version, (event, data) => { + const dataDirectory = helpers.resolvePath(data.Directory); + helpers + .checkDaemonVersion(dataDirectory, data.Version, data.StorageType) + .then(code => { + standardIPCReply(event, Constants.IPC_Check_Daemon_Version_Reply, { + Valid: (code === 0), + }); + }) + .catch(e=> { + standardIPCReply(event, Constants.IPC_Check_Daemon_Version_Reply, { + Valid: false, + }, e); + }); +}); + +ipcMain.on(Constants.IPC_Check_Daemon_Version + '_sync', (event, data) => { + const dataDirectory = helpers.resolvePath(data.Directory); + helpers + .checkDaemonVersion(dataDirectory, data.Version, data.StorageType) + .then(code => { + event.returnValue = { + data: { + Valid: (code === 0), + }, + }; + }) + .catch(e => { + event.returnValue = { + data: { + Error: e.toString(), + Success: false, + Valid: false + }, + }; + }); +}); + ipcMain.on(Constants.IPC_Check_Dependency_Installed, (event, data) => { try { const exists = fs.lstatSync(data.File).isFile(); diff --git a/src/containers/MountItems/MountItems.js b/src/containers/MountItems/MountItems.js index 89ab410..f81eb90 100644 --- a/src/containers/MountItems/MountItems.js +++ b/src/containers/MountItems/MountItems.js @@ -95,18 +95,24 @@ class MountItems extends IPCContainer { let allowAction = true; if (mount) { let result = this.sendSyncRequest(Constants.IPC_Check_Daemon_Version, { + Directory: this.props.directory, StorageType: storageType, Version: this.props.version }); if (result.Success) { - if (this.props.platform !== 'win32') { - result = this.sendSyncRequest(Constants.IPC_Check_Mount_Location, { - Location: location, - }); - if (!result.Success) { - allowAction = false; - this.props.errorHandler(result.Error.toString()); + if (result.Valid) { + if (this.props.platform !== 'win32') { + result = this.sendSyncRequest(Constants.IPC_Check_Mount_Location, { + Location: location, + }); + if (!result.Success) { + allowAction = false; + this.props.errorHandler(result.Error.toString()); + } } + } else { + allowAction = false; + this.props.errorHandler("Incompatible " + storageType + " daemon. Please upgrade " + storageType); } } else { allowAction = false; diff --git a/src/helpers.js b/src/helpers.js index 57491f9..5dd3538 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -16,6 +16,34 @@ const tryParse = (j, def) => { } }; +module.exports.checkDaemonVersion = (directory, version, storageType) => { + return new Promise((resolve, reject) => { + const processOptions = { + detached: true, + shell: false, + windowsHide: true, + }; + + const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory'); + const args = []; + args.push('-cv'); + if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) { + args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]); + } + + const process = new spawn(command, args, processOptions); + + process.on('error', err => { + reject(err); + }); + + process.on('exit', code => { + resolve(code); + }); + process.unref(); + }); +}; + module.exports.createSignatureFiles = (signature, publicKey) => { const fileName1 = RandomString.generate({ length: 12,