Prettier support

This commit is contained in:
2021-03-10 21:14:32 -06:00
parent c51b527707
commit 0924490a6f
99 changed files with 5504 additions and 3979 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();
});
@@ -9,12 +9,10 @@ const addListeners = (ipcMain, {closeApplication, setWindowVisibility}) => {
setWindowVisibility(true);
});
ipcMain.on(Constants.IPC_Show_Window + '_sync', event => {
ipcMain.on(Constants.IPC_Show_Window + '_sync', (event) => {
setWindowVisibility(true);
event.returnValue = true;
});
};
module.exports = {
addListeners
};
module.exports = { addListeners };

View File

@@ -1,48 +1,70 @@
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, data.S3)
.then((data) => {
if (data.Code === 0) {
standardIPCReply(event, Constants.IPC_Get_Config_Reply, {
Config: data.Data,
});
} else {
standardIPCReply(event, Constants.IPC_Get_Config_Reply, {}, data.Code);
}
})
.catch(error => {
standardIPCReply(event, Constants.IPC_Get_Config_Reply, {}, error);
});
.getConfig(data.Version, data.Provider, data.Remote, data.S3)
.then((data) => {
if (data.Code === 0) {
standardIPCReply(event, Constants.IPC_Get_Config_Reply, {
Config: data.Data,
});
} else {
standardIPCReply(
event,
Constants.IPC_Get_Config_Reply,
{},
data.Code
);
}
})
.catch((error) => {
standardIPCReply(event, Constants.IPC_Get_Config_Reply, {}, error);
});
});
ipcMain.on(Constants.IPC_Get_Config_Template, (event, data) => {
helpers
.getConfigTemplate(data.Version, data.Provider, data.Remote, data.S3)
.then((data) => {
standardIPCReply(event, Constants.IPC_Get_Config_Template_Reply, {
Template: data,
.getConfigTemplate(data.Version, data.Provider, data.Remote, data.S3)
.then((data) => {
standardIPCReply(event, Constants.IPC_Get_Config_Template_Reply, {
Template: data,
});
})
.catch((error) => {
standardIPCReply(
event,
Constants.IPC_Get_Config_Template_Reply,
{},
error
);
});
})
.catch(error => {
standardIPCReply(event, Constants.IPC_Get_Config_Template_Reply, {}, error);
});
});
ipcMain.on(Constants.IPC_Set_Config_Values, (event, data) => {
const setConfigValue = (i) => {
if (i < data.Items.length) {
helpers
.setConfigValue(data.Items[i].Name, data.Items[i].Value, data.Provider, data.Remote, data.S3, data.Version)
.then(() => {
setConfigValue(++i);
})
.catch(error => {
standardIPCReply(event, Constants.IPC_Set_Config_Values_Reply, {}, error);
});
.setConfigValue(
data.Items[i].Name,
data.Items[i].Value,
data.Provider,
data.Remote,
data.S3,
data.Version
)
.then(() => {
setConfigValue(++i);
})
.catch((error) => {
standardIPCReply(
event,
Constants.IPC_Set_Config_Values_Reply,
{},
error
);
});
} else {
standardIPCReply(event, Constants.IPC_Set_Config_Values_Reply, {});
}
@@ -51,6 +73,4 @@ const addListeners = (ipcMain, {standardIPCReply}) => {
});
};
module.exports = {
addListeners
};
module.exports = { addListeners };

View File

@@ -1,47 +1,46 @@
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)
.then(code => {
standardIPCReply(event, Constants.IPC_Check_Daemon_Version_Reply, {
Valid: (code === 0),
Code: code,
.checkDaemonVersion(data.Version, data.Provider)
.then((code) => {
standardIPCReply(event, Constants.IPC_Check_Daemon_Version_Reply, {
Valid: code === 0,
Code: code,
});
})
.catch((e) => {
standardIPCReply(
event,
Constants.IPC_Check_Daemon_Version_Reply,
{
Valid: false,
},
e
);
});
})
.catch(e => {
standardIPCReply(event, Constants.IPC_Check_Daemon_Version_Reply, {
Valid: false,
}, e);
});
});
ipcMain.on(Constants.IPC_Check_Daemon_Version + '_sync', (event, data) => {
helpers
.checkDaemonVersion(data.Version, data.Provider)
.then(code => {
event.returnValue = {
data: {
Success: true,
Valid: (code === 0),
Code: code,
},
};
})
.catch(e => {
event.returnValue = {
data: {
Error: e.toString(),
Success: false,
Valid: false
},
};
});
.checkDaemonVersion(data.Version, data.Provider)
.then((code) => {
event.returnValue = {
data: {
Success: true,
Valid: code === 0,
Code: code,
},
};
})
.catch((e) => {
event.returnValue = {
data: { Error: e.toString(), Success: false, Valid: false },
};
});
});
};
module.exports = {
addListeners
};
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();
@@ -13,83 +13,99 @@ const addListeners = (ipcMain, {standardIPCReply}) => {
});
} catch (e) {
standardIPCReply(event, Constants.IPC_Check_Dependency_Installed_Reply, {
data : {
data: {
Exists: false,
},
});
}
});
ipcMain.on(Constants.IPC_Check_Dependency_Installed + '_sync', (event, data) => {
try {
const ls = fs.lstatSync(data.File);
event.returnValue = {
data: {
Exists: ls.isFile() || ls.isSymbolicLink(),
},
};
} catch (e) {
event.returnValue = {
data: {
Exists: false
},
};
ipcMain.on(
Constants.IPC_Check_Dependency_Installed + '_sync',
(event, data) => {
try {
const ls = fs.lstatSync(data.File);
event.returnValue = {
data: {
Exists: ls.isFile() || ls.isSymbolicLink(),
},
};
} catch (e) {
event.returnValue = {
data: { Exists: false },
};
}
}
});
);
ipcMain.on(Constants.IPC_Install_Dependency, (event, data) => {
if (data.Source.toLowerCase().endsWith('.dmg')) {
helpers
.executeAsync('open', ['-a', 'Finder', '-W', data.Source])
.then(() => {
standardIPCReply(event, Constants.IPC_Install_Dependency_Reply, {
Source: data.Source,
URL: data.URL,
});
})
.catch(error=> {
standardIPCReply(event, Constants.IPC_Install_Dependency_Reply, {
Source: data.Source,
URL: data.URL,
}, error);
});
} else {
const execInstall = () => {
helpers
.executeAndWait(data.Source)
.executeAsync('open', ['-a', 'Finder', '-W', data.Source])
.then(() => {
standardIPCReply(event, Constants.IPC_Install_Dependency_Reply, {
Source: data.Source,
URL: data.URL,
});
})
.catch(error => {
standardIPCReply(event, Constants.IPC_Install_Dependency_Reply, {
Source: data.Source,
URL: data.URL,
}, error);
.catch((error) => {
standardIPCReply(
event,
Constants.IPC_Install_Dependency_Reply,
{
Source: data.Source,
URL: data.URL,
},
error
);
});
};
if (data.IsWinFSP) {
} else {
const execInstall = () => {
helpers
.performWindowsUninstall(Constants.WINFSP_VERSION_NAMES)
.then(uninstalled => {
if (uninstalled) {
.executeAndWait(data.Source)
.then(() => {
standardIPCReply(event, Constants.IPC_Install_Dependency_Reply, {
RebootRequired: true,
Source: data.Source,
URL: data.URL,
});
} else {
execInstall();
}
})
.catch(error => {
standardIPCReply(event, Constants.IPC_Install_Dependency_Reply, {
Source: data.Source,
URL: data.URL,
}, error);
});
})
.catch((error) => {
standardIPCReply(
event,
Constants.IPC_Install_Dependency_Reply,
{
Source: data.Source,
URL: data.URL,
},
error
);
});
};
if (data.IsWinFSP) {
helpers
.performWindowsUninstall(Constants.WINFSP_VERSION_NAMES)
.then((uninstalled) => {
if (uninstalled) {
standardIPCReply(event, Constants.IPC_Install_Dependency_Reply, {
RebootRequired: true,
Source: data.Source,
URL: data.URL,
});
} else {
execInstall();
}
})
.catch((error) => {
standardIPCReply(
event,
Constants.IPC_Install_Dependency_Reply,
{
Source: data.Source,
URL: data.URL,
},
error
);
});
} else {
execInstall();
}
@@ -97,6 +113,4 @@ const addListeners = (ipcMain, {standardIPCReply}) => {
});
};
module.exports = {
addListeners
};
module.exports = { addListeners };

View File

@@ -2,24 +2,32 @@ 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) => {
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);
});
helpers.downloadFile(
data.URL,
destination,
(progress) => {
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
);
}
);
});
};
module.exports = {
addListeners
};
module.exports = { addListeners };

View File

@@ -1,19 +1,23 @@
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,
properties: ['openDirectory'],
title: data.Title,
}, (filePaths) => {
if (filePaths && (filePaths.length > 0)) {
event.returnValue = filePaths[0];
} else {
event.returnValue = '';
dialog.showOpenDialog(
getMainWindow(),
{
defaultPath: data.Location,
properties: ['openDirectory'],
title: data.Title,
},
(filePaths) => {
if (filePaths && filePaths.length > 0) {
event.returnValue = filePaths[0];
} else {
event.returnValue = '';
}
}
});
);
});
ipcMain.on(Constants.IPC_Delete_File, (event, data) => {
@@ -21,11 +25,8 @@ const addListeners = (ipcMain, {getMainWindow, dialog}) => {
if (fs.existsSync(data.FilePath)) {
fs.unlinkSync(data.FilePath);
}
} catch (e) {
}
} catch (e) {}
});
};
module.exports = {
addListeners
};
module.exports = { addListeners };

View File

@@ -10,38 +10,45 @@ let manualMountDetection = {};
let mountedData = {};
let mountedLocations = [];
const clearManualMountDetection = provider => {
const clearManualMountDetection = (provider) => {
if (manualMountDetection[provider]) {
clearInterval(manualMountDetection[provider]);
delete manualMountDetection[provider];
}
};
const monitorMount = (sender, provider, providerList, version, pid, location) => {
const monitorMount = (
sender,
provider,
providerList,
version,
pid,
location
) => {
manualMountDetection[provider] = setInterval(() => {
helpers
.detectRepertoryMounts(version, providerList)
.then(result => {
if (result[provider].PID !== pid) {
if (result[provider].PID === -1) {
clearManualMountDetection(provider);
sender.send(Constants.IPC_Unmount_Drive_Reply, {
data: {
Expected: expectedUnmount[provider],
Location: location,
Provider: provider,
Error: Error(provider + ' Unmounted').toString(),
Success: false,
}
});
} else {
pid = result[provider].PID;
.detectRepertoryMounts(version, providerList)
.then((result) => {
if (result[provider].PID !== pid) {
if (result[provider].PID === -1) {
clearManualMountDetection(provider);
sender.send(Constants.IPC_Unmount_Drive_Reply, {
data: {
Expected: expectedUnmount[provider],
Location: location,
Provider: provider,
Error: Error(provider + ' Unmounted').toString(),
Success: false,
},
});
} else {
pid = result[provider].PID;
}
}
}
})
.catch(e => {
console.log(e);
});
})
.catch((e) => {
console.log(e);
});
}, 6000);
};
@@ -55,22 +62,27 @@ const unmountAllDrives = () => {
// Unmount all items
for (const mountLocation of mountedLocations) {
const data = mountedData[mountLocation];
helpers.stopMountProcessSync(data.Version, data.Provider, data.Remote, data.S3);
helpers.stopMountProcessSync(
data.Version,
data.Provider,
data.Remote,
data.S3
);
}
mountedLocations = [];
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,
Error: ''
};
let response = { Success: true, Error: '' };
try {
if (fs.existsSync(data.Location) && fs.statSync(data.Location).isDirectory()) {
if (
fs.existsSync(data.Location) &&
fs.statSync(data.Location).isDirectory()
) {
if (fs.readdirSync(data.Location).length !== 0) {
response.Success = false;
response.Error = 'Directory not empty: ' + data.Location;
@@ -106,8 +118,7 @@ const addListeners = (ipcMain, {setTrayImage, standardIPCReply}) => {
if (Object.keys(locations).length > 0) {
for (const provider of providerList) {
driveInUse = locations[provider].startsWith(drive);
if (driveInUse)
break;
if (driveInUse) break;
}
}
if (!driveInUse) {
@@ -117,17 +128,18 @@ const addListeners = (ipcMain, {setTrayImage, standardIPCReply}) => {
driveLetters[provider].push(drive);
}
}
} catch (e) {
}
} catch (e) {}
}
}
if (Object.keys(locations).length > 0) {
for (const provider of providerList) {
if (locations[provider].length > 0) {
if (!driveLetters[provider].find((driveLetter) => {
return driveLetter === locations[provider];
})) {
if (
!driveLetters[provider].find((driveLetter) => {
return driveLetter === locations[provider];
})
) {
driveLetters[provider].push(locations[provider]);
}
}
@@ -135,66 +147,79 @@ const addListeners = (ipcMain, {setTrayImage, standardIPCReply}) => {
}
};
const setImage = locations => {
const setImage = (locations) => {
let driveInUse;
if (Object.keys(locations).length > 0) {
for (const provider of providerList) {
driveInUse = locations[provider] && locations[provider].length > 0;
if (driveInUse)
break;
if (driveInUse) break;
}
}
setTrayImage(driveInUse)
setTrayImage(driveInUse);
};
helpers
.detectRepertoryMounts(data.Version, providerList)
.then((results) => {
let storageData = {};
let locations = {};
for (const provider of providerList) {
storageData[provider] = results[provider] ? results[provider] : {
Active: false,
Location: '',
PID: -1,
};
locations[provider] = storageData[provider].Location;
.detectRepertoryMounts(data.Version, providerList)
.then((results) => {
let storageData = {};
let locations = {};
for (const provider of providerList) {
storageData[provider] = results[provider]
? results[provider]
: {
Active: false,
Location: '',
PID: -1,
};
locations[provider] = storageData[provider].Location;
if (storageData[provider].PID !== -1) {
expectedUnmount[provider] = false;
if (firstMountCheck) {
monitorMount(event.sender, provider, providerList, data.Version, storageData[provider].PID, storageData[provider].Location);
if (storageData[provider].PID !== -1) {
expectedUnmount[provider] = false;
if (firstMountCheck) {
monitorMount(
event.sender,
provider,
providerList,
data.Version,
storageData[provider].PID,
storageData[provider].Location
);
}
}
}
}
if (os.platform() === 'win32') {
grabDriveLetters(locations);
}
if (os.platform() === 'win32') {
grabDriveLetters(locations);
}
setImage(locations);
if (firstMountCheck) {
firstMountCheck = false;
}
standardIPCReply(event, Constants.IPC_Detect_Mount_Reply, {
Active: storageData[provider].Active,
DriveLetters: driveLetters[provider],
Location: locations[provider],
PID: storageData[provider].PID,
Provider: provider,
setImage(locations);
if (firstMountCheck) {
firstMountCheck = false;
}
standardIPCReply(event, Constants.IPC_Detect_Mount_Reply, {
Active: storageData[provider].Active,
DriveLetters: driveLetters[provider],
Location: locations[provider],
PID: storageData[provider].PID,
Provider: provider,
});
})
.catch((error) => {
if (os.platform() === 'win32') {
grabDriveLetters({});
}
setImage({});
standardIPCReply(
event,
Constants.IPC_Detect_Mount_Reply,
{
DriveLetters: driveLetters[provider],
Provider: provider,
},
error
);
});
})
.catch(error => {
if (os.platform() === 'win32') {
grabDriveLetters({});
}
setImage({});
standardIPCReply(event, Constants.IPC_Detect_Mount_Reply, {
DriveLetters: driveLetters[provider],
Provider: provider,
}, error);
});
});
ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
@@ -216,28 +241,40 @@ const addListeners = (ipcMain, {setTrayImage, standardIPCReply}) => {
delete mountedData[data.Location];
}
standardIPCReply(event, Constants.IPC_Unmount_Drive_Reply, {
Expected: expectedUnmount[data.Provider],
Location: data.Location,
Provider: data.Provider,
Remote: data.Remote,
S3: data.S3,
}, error || Error(data.Provider + ' Unmounted'));
standardIPCReply(
event,
Constants.IPC_Unmount_Drive_Reply,
{
Expected: expectedUnmount[data.Provider],
Location: data.Location,
Provider: data.Provider,
Remote: data.Remote,
S3: data.S3,
},
error || Error(data.Provider + ' Unmounted')
);
};
helpers
.executeMount(data.Version, data.Provider, data.Remote, data.S3, data.Location, (error, pid) => {
errorHandler(pid, error);
})
.then(() => {
standardIPCReply(event, Constants.IPC_Mount_Drive_Reply, {
Provider: data.Provider,
Remote: data.Remote,
S3: data.S3,
.executeMount(
data.Version,
data.Provider,
data.Remote,
data.S3,
data.Location,
(error, pid) => {
errorHandler(pid, error);
}
)
.then(() => {
standardIPCReply(event, Constants.IPC_Mount_Drive_Reply, {
Provider: data.Provider,
Remote: data.Remote,
S3: data.S3,
});
})
.catch((error) => {
errorHandler(-1, error);
});
})
.catch(error => {
errorHandler(-1, error);
});
}
});
@@ -245,17 +282,31 @@ const addListeners = (ipcMain, {setTrayImage, standardIPCReply}) => {
if (data.Remote) {
data.Name = data.Name.replace(':', '_');
}
const dataDirectory = path.resolve(path.join(helpers.getDataDirectory(), '..', data.Remote ? 'remote' : 's3', data.Name));
const dataDirectory = path.resolve(
path.join(
helpers.getDataDirectory(),
'..',
data.Remote ? 'remote' : 's3',
data.Name
)
);
try {
helpers.removeDirectoryRecursively(dataDirectory);
standardIPCReply(event, Constants.IPC_Remove_Mount_Reply, {DataDirectory: dataDirectory});
standardIPCReply(event, Constants.IPC_Remove_Mount_Reply, {
DataDirectory: dataDirectory,
});
} catch (e) {
standardIPCReply(event, Constants.IPC_Remove_Mount_Reply, {DataDirectory: dataDirectory}, e);
standardIPCReply(
event,
Constants.IPC_Remove_Mount_Reply,
{ DataDirectory: dataDirectory },
e
);
}
});
ipcMain.on(Constants.IPC_Unmount_All_Drives, event => {
ipcMain.on(Constants.IPC_Unmount_All_Drives, (event) => {
unmountAllDrives();
standardIPCReply(event, Constants.IPC_Unmount_All_Drives_Reply);
});
@@ -265,17 +316,17 @@ const addListeners = (ipcMain, {setTrayImage, standardIPCReply}) => {
expectedUnmount[data.Provider] = true;
helpers
.stopMountProcess(data.Version, data.Provider, data.Remote, data.S3)
.then(result => {
console.log(result);
})
.catch(e => {
console.log(e);
});
.stopMountProcess(data.Version, data.Provider, data.Remote, data.S3)
.then((result) => {
console.log(result);
})
.catch((e) => {
console.log(e);
});
});
};
module.exports = {
addListeners,
unmountAllDrives
unmountAllDrives,
};

View File

@@ -1,49 +1,64 @@
const Constants = require('../../constants');
const helpers = require('../../helpers');
const addListeners = (ipcMain, {standardIPCReply}) => {
const addListeners = (ipcMain, { standardIPCReply }) => {
ipcMain.on(Constants.IPC_Get_Directory_Items, (event, data) => {
helpers
.grabDirectoryItems(data.Path, data.Version, data.Provider, data.Remote, data.S3)
.then(data => {
standardIPCReply(event, Constants.IPC_Get_Directory_Items_Reply, {
Items: data.items,
.grabDirectoryItems(
data.Path,
data.Version,
data.Provider,
data.Remote,
data.S3
)
.then((data) => {
standardIPCReply(event, Constants.IPC_Get_Directory_Items_Reply, {
Items: data.items,
});
})
.catch((e) => {
standardIPCReply(event, Constants.IPC_Get_Directory_Items_Reply, {}, e);
});
})
.catch(e => {
standardIPCReply(event, Constants.IPC_Get_Directory_Items_Reply, {}, e);
});
});
ipcMain.on(Constants.IPC_Get_Pinned_Files, (event, data) => {
helpers
.grabDirectoryItems(data.Path, data.Version, data.Provider, data.Remote, data.S3)
.then(data => {
standardIPCReply(event, Constants.IPC_Get_Directory_Items_Reply, {
Items: data.items,
.grabDirectoryItems(
data.Path,
data.Version,
data.Provider,
data.Remote,
data.S3
)
.then((data) => {
standardIPCReply(event, Constants.IPC_Get_Directory_Items_Reply, {
Items: data.items,
});
})
.catch((e) => {
standardIPCReply(event, Constants.IPC_Get_Directory_Items_Reply, {}, e);
});
})
.catch(e => {
standardIPCReply(event, Constants.IPC_Get_Directory_Items_Reply, {}, e);
});
});
ipcMain.on(Constants.IPC_Get_Pinned_Files_Status, (event, data) => {
});
ipcMain.on(Constants.IPC_Get_Pinned_Files_Status, (event, data) => {});
ipcMain.on(Constants.IPC_Set_Pinned + '_sync', (event, data) => {
helpers
.setPinned(data.Path, data.Pinned, data.Version, data.Provider, data.Remote, data.S3)
.then(success => {
event.returnValue = success;
})
.catch(e => {
event.returnValue = false;
});
.setPinned(
data.Path,
data.Pinned,
data.Version,
data.Provider,
data.Remote,
data.S3
)
.then((success) => {
event.returnValue = success;
})
.catch((e) => {
event.returnValue = false;
});
});
};
module.exports = {
addListeners
};
module.exports = { addListeners };

View File

@@ -10,11 +10,11 @@ const getPlatformOverride = () => {
return _platformOverride;
};
const setPlatformOverride = platformOverride => {
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, {
@@ -25,40 +25,44 @@ const addListeners = (ipcMain, {detectScript, saveUiSettings}) => {
const platform = os.platform();
if (platform === 'linux') {
if (_platformOverride && (_platformOverride.length > 0)) {
if (_platformOverride && _platformOverride.length > 0) {
sendResponse(_platformOverride, 'linux');
} else {
const scriptFile = path.join(os.tmpdir(), 'repertory_detect_linux.sh');
fs.writeFileSync(scriptFile, detectScript);
helpers
.executeScript(scriptFile)
.then(data => {
let appPlatform = data.replace(/(\r\n|\n|\r)/gm, "");
if (appPlatform === 'unknown') {
helpers
.downloadFile(Constants.LINUX_DETECT_SCRIPT_URL, scriptFile, null, err => {
if (err) {
sendResponse(appPlatform, platform);
} else {
helpers
.executeScript(scriptFile)
.then(data => {
appPlatform = data.replace(/(\r\n|\n|\r)/gm, "");
sendResponse(appPlatform, platform);
})
.catch(() => {
sendResponse(appPlatform, platform);
});
}
});
} else {
sendResponse(appPlatform, platform);
}
})
.catch(() => {
sendResponse(platform, platform);
});
.executeScript(scriptFile)
.then((data) => {
let appPlatform = data.replace(/(\r\n|\n|\r)/gm, '');
if (appPlatform === 'unknown') {
helpers.downloadFile(
Constants.LINUX_DETECT_SCRIPT_URL,
scriptFile,
null,
(err) => {
if (err) {
sendResponse(appPlatform, platform);
} else {
helpers
.executeScript(scriptFile)
.then((data) => {
appPlatform = data.replace(/(\r\n|\n|\r)/gm, '');
sendResponse(appPlatform, platform);
})
.catch(() => {
sendResponse(appPlatform, platform);
});
}
}
);
} else {
sendResponse(appPlatform, platform);
}
})
.catch(() => {
sendResponse(platform, platform);
});
}
} else {
sendResponse(platform, platform);
@@ -75,5 +79,5 @@ const addListeners = (ipcMain, {detectScript, saveUiSettings}) => {
module.exports = {
getPlatformOverride,
setPlatformOverride,
addListeners
addListeners,
};

View File

@@ -5,28 +5,35 @@ 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
.getMissingDependencies(data.Dependencies)
.then((dependencies) => {
let exists = false;
try {
exists = fs.existsSync(destination) && fs.lstatSync(destination).isDirectory();
} catch (e) {
}
standardIPCReply(event, Constants.IPC_Check_Installed_Reply, {
Dependencies: dependencies,
Exists: exists,
Version: data.Version,
.getMissingDependencies(data.Dependencies)
.then((dependencies) => {
let exists = false;
try {
exists =
fs.existsSync(destination) &&
fs.lstatSync(destination).isDirectory();
} catch (e) {}
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
);
});
}).catch(error => {
standardIPCReply(event, Constants.IPC_Check_Installed_Reply, {
Dependencies: [],
Version: data.Version,
}, error);
});
});
ipcMain.on(Constants.IPC_Cleanup_Releases + '_sync', (event, data) => {
@@ -44,52 +51,61 @@ const addListeners = (ipcMain, {getCleanupReleases, standardIPCReply}) => {
const stream = fs.createReadStream(data.Source);
stream
.pipe(unzip.Extract({ path: destination }))
.on('error', error => {
try {
helpers.removeDirectoryRecursively(destination);
} catch (e) {
}
stream.close();
standardIPCReply(event, Constants.IPC_Extract_Release_Complete, {
Source: data.Source,
}, error);
})
.on('finish', () => {
stream.close();
if (os.platform() !== 'win32') {
helpers
.executeAndWait("chmod +x \"" + path.join(destination, 'repertory') + "\"")
.then(() => {
.pipe(unzip.Extract({ path: destination }))
.on('error', (error) => {
try {
helpers.removeDirectoryRecursively(destination);
} catch (e) {}
stream.close();
standardIPCReply(
event,
Constants.IPC_Extract_Release_Complete,
{
Source: data.Source,
},
error
);
})
.on('finish', () => {
stream.close();
if (os.platform() !== 'win32') {
helpers
.executeAndWait(
'chmod +x "' + path.join(destination, 'repertory') + '"'
)
.then(() => {
standardIPCReply(event, Constants.IPC_Extract_Release_Complete, {
Source: data.Source,
});
})
.catch((error) => {
standardIPCReply(
event,
Constants.IPC_Extract_Release_Complete,
{
Source: data.Source,
},
error
);
});
} else {
standardIPCReply(event, Constants.IPC_Extract_Release_Complete, {
Source: data.Source,
});
})
.catch(error => {
standardIPCReply(event, Constants.IPC_Extract_Release_Complete, {
Source: data.Source,
}, error);
})
} else {
standardIPCReply(event, Constants.IPC_Extract_Release_Complete, {
Source: data.Source,
});
}
});
}
});
});
ipcMain.on(Constants.IPC_Test_Release, (event, data) => {
helpers
.testRepertoryBinary(data.Version)
.then(() => {
standardIPCReply(event, Constants.IPC_Test_Release_Reply, {});
})
.catch(error => {
standardIPCReply(event, Constants.IPC_Test_Release_Reply, {}, error);
});
.testRepertoryBinary(data.Version)
.then(() => {
standardIPCReply(event, Constants.IPC_Test_Release_Reply, {});
})
.catch((error) => {
standardIPCReply(event, Constants.IPC_Test_Release_Reply, {}, error);
});
});
};
module.exports = {
addListeners
};
module.exports = { addListeners };

View File

@@ -1,47 +1,50 @@
const Constants = require('../../constants');
const helpers = require('../../helpers');
const addListeners = (ipcMain, {standardIPCReply}) => {
const addListeners = (ipcMain, { standardIPCReply }) => {
ipcMain.on(Constants.IPC_Export_Skylinks, (event, data) => {
helpers
.exportSkylinks(data.Version, data.Paths)
.then(result => {
standardIPCReply(event, Constants.IPC_Export_Skylinks_Reply, {
Result: result,
.exportSkylinks(data.Version, data.Paths)
.then((result) => {
standardIPCReply(event, Constants.IPC_Export_Skylinks_Reply, {
Result: result,
});
})
.catch((error) => {
standardIPCReply(event, Constants.IPC_Export_Skylinks_Reply, {}, error);
});
})
.catch(error => {
standardIPCReply(event, Constants.IPC_Export_Skylinks_Reply, {}, error);
});
});
ipcMain.on(Constants.IPC_Grab_Skynet_Tree, (event, data) => {
helpers
.grabSkynetFileTree(data.Version)
.then(result => {
standardIPCReply(event, Constants.IPC_Grab_Skynet_Tree_Reply, {
Result: result,
.grabSkynetFileTree(data.Version)
.then((result) => {
standardIPCReply(event, Constants.IPC_Grab_Skynet_Tree_Reply, {
Result: result,
});
})
.catch((error) => {
standardIPCReply(
event,
Constants.IPC_Grab_Skynet_Tree_Reply,
{},
error
);
});
})
.catch(error => {
standardIPCReply(event, Constants.IPC_Grab_Skynet_Tree_Reply, {}, error);
});
});
ipcMain.on(Constants.IPC_Import_Skylinks, (event, data) => {
helpers
.importSkylinks(data.Version, data.JsonArray)
.then(result => {
standardIPCReply(event, Constants.IPC_Import_Skylinks_Reply, {
Result: result,
.importSkylinks(data.Version, data.JsonArray)
.then((result) => {
standardIPCReply(event, Constants.IPC_Import_Skylinks_Reply, {
Result: result,
});
})
.catch((error) => {
standardIPCReply(event, Constants.IPC_Import_Skylinks_Reply, {}, error);
});
})
.catch(error => {
standardIPCReply(event, Constants.IPC_Import_Skylinks_Reply, {}, error);
});
});
};
module.exports = {
addListeners
};
module.exports = { addListeners };

View File

@@ -3,18 +3,19 @@ const fs = require('fs');
const helpers = require('../../helpers');
const path = require('path');
const getDirectories = source => {
const getDirectories = (source) => {
try {
return fs.readdirSync(source, {withFileTypes: true})
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
return fs
.readdirSync(source, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
} catch {
return [];
}
}
};
const addListeners = ipcMain => {
ipcMain.on(Constants.IPC_Get_State, event => {
const addListeners = (ipcMain) => {
ipcMain.on(Constants.IPC_Get_State, (event) => {
helpers.mkDirByPathSync(helpers.getDataDirectory());
let data = {};
@@ -32,14 +33,16 @@ const addListeners = ipcMain => {
AutoMount: false,
AutoRestart: true,
MountLocation: '',
}
};
}
}
data.RemoteMounts = data.RemoteMounts || [];
data.S3Mounts = data.S3Mounts || [];
const remoteItems = getDirectories(path.join(helpers.getRepertoryDirectory(), 'remote'));
const remoteItems = getDirectories(
path.join(helpers.getRepertoryDirectory(), 'remote')
);
for (const dir of remoteItems) {
const name = 'Remote' + dir.replace('_', ':');
if (!data.RemoteMounts || data.RemoteMounts.indexOf(name) === -1) {
@@ -52,7 +55,9 @@ const addListeners = ipcMain => {
}
}
const s3Items = getDirectories(path.join(helpers.getRepertoryDirectory(), 's3'));
const s3Items = getDirectories(
path.join(helpers.getRepertoryDirectory(), 's3')
);
for (const dir of s3Items) {
const name = 'S3' + dir;
if (!data.S3Mounts || data.S3Mounts.indexOf(name) === -1) {
@@ -76,6 +81,4 @@ const addListeners = ipcMain => {
});
};
module.exports = {
addListeners
};
module.exports = { addListeners };

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']);
@@ -11,6 +11,4 @@ const addListeners = (ipcMain, {closeApplication}) => {
});
};
module.exports = {
addListeners
};
module.exports = { addListeners };

View File

@@ -3,7 +3,10 @@ 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;
@@ -19,25 +22,34 @@ const addListeners = (ipcMain, {setIsInstalling, unmountAllDrives, standardIPCRe
if (tempPub) {
fs.unlinkSync(tempPub);
}
} catch (e) {
}
} catch (e) {}
};
const errorHandler = err => {
const errorHandler = (err) => {
cleanupFiles();
setIsInstalling(false);
standardIPCReply(event, Constants.IPC_Install_Upgrade_Reply, {
AllowSkipVerification: allowSkipVerification,
Source: data.Source,
}, err);
standardIPCReply(
event,
Constants.IPC_Install_Upgrade_Reply,
{
AllowSkipVerification: allowSkipVerification,
Source: data.Source,
},
err
);
};
// TODO Enable verification in 1.0.4
const hasSignature = false;//!data.SkipVerification && data.Signature && (data.Signature.length > 0);
const hasHash = false;//!data.SkipVerification && data.Sha256 && (data.Sha256.length > 0);
const hasSignature = false; //! data.SkipVerification && data.Signature
//! && (data.Signature.length > 0);
const hasHash = false; //! data.SkipVerification && data.Sha256 &&
//! (data.Sha256.length > 0);
if (hasSignature) {
try {
const files = helpers.createSignatureFiles(data.Signature, Constants.DEV_PUBLIC_KEY);
const files = helpers.createSignatureFiles(
data.Signature,
Constants.DEV_PUBLIC_KEY
);
tempPub = files.PublicKeyFile;
tempSig = files.SignatureFile;
} catch (e) {
@@ -69,35 +81,37 @@ const addListeners = (ipcMain, {setIsInstalling, unmountAllDrives, standardIPCRe
const executeInstall = () => {
setIsInstalling(true);
helpers
.executeAsync(command, args)
.then(() => {
cleanupFiles();
standardIPCReply(event, Constants.IPC_Install_Upgrade_Reply)
})
.catch(error => {
setIsInstalling(false);
errorHandler(error);
});
.executeAsync(command, args)
.then(() => {
cleanupFiles();
standardIPCReply(event, Constants.IPC_Install_Upgrade_Reply);
})
.catch((error) => {
setIsInstalling(false);
errorHandler(error);
});
};
if (hasSignature) {
helpers
.verifySignature(data.Source, tempSig, tempPub)
.then(() => {
executeInstall();
})
.catch(() => {
errorHandler(Error('Failed to verify installation package signature'));
});
.verifySignature(data.Source, tempSig, tempPub)
.then(() => {
executeInstall();
})
.catch(() => {
errorHandler(
Error('Failed to verify installation package signature')
);
});
} else if (hasHash) {
helpers
.verifyHash(data.Source, data.Sha256)
.then(()=> {
executeInstall();
})
.catch(() => {
errorHandler(Error('Failed to verify installation package hash'));
});
.verifyHash(data.Source, data.Sha256)
.then(() => {
executeInstall();
})
.catch(() => {
errorHandler(Error('Failed to verify installation package hash'));
});
} else {
if (platform === 'darwin') {
setTimeout(executeInstall, 3000);
@@ -111,6 +125,4 @@ const addListeners = (ipcMain, {setIsInstalling, unmountAllDrives, standardIPCRe
});
};
module.exports = {
addListeners
};
module.exports = { addListeners };