Redux changes and refactoring
This commit is contained in:
@@ -119,7 +119,7 @@ function createWindow() {
|
||||
// Unmount all items
|
||||
for (const i in mountedLocations) {
|
||||
const data = mountedData[mountedLocations[i]];
|
||||
helpers.stopMountProcessSync(data.DataDirectory, data.Version, data.StorageType);
|
||||
helpers.stopMountProcessSync(data.Version, data.StorageType);
|
||||
}
|
||||
|
||||
mountedLocations = [];
|
||||
@@ -223,10 +223,10 @@ const loadUiSettings = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const monitorMount = (sender, storageType, dataDirectory, version, pid, location) => {
|
||||
const monitorMount = (sender, storageType, version, pid, location) => {
|
||||
manualMountDetection[storageType] = setInterval(() => {
|
||||
helpers
|
||||
.detectRepertoryMounts(dataDirectory, version)
|
||||
.detectRepertoryMounts(version)
|
||||
.then(result => {
|
||||
if (result[storageType].PID !== pid) {
|
||||
if (result[storageType].PID === -1) {
|
||||
@@ -252,7 +252,7 @@ const monitorMount = (sender, storageType, dataDirectory, version, pid, location
|
||||
};
|
||||
|
||||
const saveUiSettings = () => {
|
||||
const settingFile = path.join(helpers.resolvePath(Constants.DATA_LOCATIONS[os.platform()]), 'ui.json');
|
||||
const settingFile = path.join(helpers.getDataDirectory(), 'ui.json');
|
||||
try {
|
||||
fs.writeFileSync(settingFile, JSON.stringify({
|
||||
launch_hidden: launchHidden,
|
||||
@@ -288,9 +288,8 @@ 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)
|
||||
.checkDaemonVersion(data.Version, data.StorageType)
|
||||
.then(code => {
|
||||
standardIPCReply(event, Constants.IPC_Check_Daemon_Version_Reply, {
|
||||
Valid: (code === 0),
|
||||
@@ -304,9 +303,8 @@ ipcMain.on(Constants.IPC_Check_Daemon_Version, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Check_Daemon_Version + '_sync', (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
helpers
|
||||
.checkDaemonVersion(dataDirectory, data.Version, data.StorageType)
|
||||
.checkDaemonVersion(data.Version, data.StorageType)
|
||||
.then(code => {
|
||||
event.returnValue = {
|
||||
data: {
|
||||
@@ -361,8 +359,7 @@ ipcMain.on(Constants.IPC_Check_Dependency_Installed + '_sync', (event, data) =>
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Check_Installed, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
const destination = path.join(dataDirectory, data.Version);
|
||||
const destination = path.join(helpers.getDataDirectory(), data.Version);
|
||||
helpers
|
||||
.getMissingDependencies(data.Dependencies)
|
||||
.then((dependencies) => {
|
||||
@@ -492,10 +489,9 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
|
||||
|
||||
mainWindowTray.setImage(image);
|
||||
};
|
||||
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
|
||||
helpers
|
||||
.detectRepertoryMounts(dataDirectory, data.Version)
|
||||
.detectRepertoryMounts(data.Version)
|
||||
.then((results) => {
|
||||
let storageData = {};
|
||||
let locations = {};
|
||||
@@ -510,7 +506,7 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
|
||||
if (storageData[provider].PID !== -1) {
|
||||
expectedUnmount[provider] = false;
|
||||
if (firstMountCheck) {
|
||||
monitorMount(event.sender, provider, dataDirectory, data.Version, storageData[provider].PID, storageData[provider].Location);
|
||||
monitorMount(event.sender, provider, data.Version, storageData[provider].PID, storageData[provider].Location);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -540,8 +536,7 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Download_File, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
const destination = path.join(dataDirectory, data.Filename);
|
||||
const destination = path.join(helpers.getDataDirectory(), data.Filename);
|
||||
helpers.downloadFile(data.URL, destination, (progress) => {
|
||||
standardIPCReply(event, Constants.IPC_Download_File_Progress, {
|
||||
Destination: destination,
|
||||
@@ -557,8 +552,7 @@ ipcMain.on(Constants.IPC_Download_File, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Extract_Release, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
const destination = path.join(dataDirectory, data.Version);
|
||||
const destination = path.join(helpers.getDataDirectory(), data.Version);
|
||||
helpers.mkDirByPathSync(destination);
|
||||
|
||||
const stream = fs.createReadStream(data.Source);
|
||||
@@ -598,9 +592,8 @@ ipcMain.on(Constants.IPC_Extract_Release, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Get_Config, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
helpers
|
||||
.getConfig(dataDirectory, data.Version, data.StorageType)
|
||||
.getConfig(data.Version, data.StorageType)
|
||||
.then((data) => {
|
||||
if (data.Code === 0) {
|
||||
standardIPCReply(event, Constants.IPC_Get_Config_Reply, {
|
||||
@@ -616,9 +609,8 @@ ipcMain.on(Constants.IPC_Get_Config, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Get_Config_Template, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
helpers
|
||||
.getConfigTemplate(dataDirectory, data.Version, data.StorageType)
|
||||
.getConfigTemplate(data.Version, data.StorageType)
|
||||
.then((data) => {
|
||||
standardIPCReply(event, Constants.IPC_Get_Config_Template_Reply, {
|
||||
Template: data,
|
||||
@@ -630,37 +622,35 @@ ipcMain.on(Constants.IPC_Get_Config_Template, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Get_Platform, (event) => {
|
||||
let platform = os.platform();
|
||||
const platform = os.platform();
|
||||
if (platform === 'linux') {
|
||||
const scriptFile = path.join(os.tmpdir(), 'repertory_detect_linux.sh');
|
||||
fs.writeFileSync(scriptFile, detectScript);
|
||||
helpers
|
||||
.executeScript(scriptFile)
|
||||
.then(data => {
|
||||
platform = data.replace(/(\r\n|\n|\r)/gm,"");
|
||||
event.sender.send(Constants.IPC_Get_Platform_Reply, {
|
||||
OSPlatform: os.platform(),
|
||||
AppPlatform: data.replace(/(\r\n|\n|\r)/gm,""),
|
||||
Platform: platform,
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
event.sender.send(Constants.IPC_Get_Platform_Reply, {
|
||||
OSPlatform: os.platform(),
|
||||
AppPlatform: platform,
|
||||
Platform: platform,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
event.sender.send(Constants.IPC_Get_Platform_Reply, {
|
||||
OSPlatform: os.platform(),
|
||||
AppPlatform: platform,
|
||||
Platform: platform,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Get_State, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data);
|
||||
helpers.mkDirByPathSync(dataDirectory);
|
||||
const configFile = path.join(dataDirectory, 'settings.json');
|
||||
ipcMain.on(Constants.IPC_Get_State, event => {
|
||||
helpers.mkDirByPathSync(helpers.getDataDirectory());
|
||||
const configFile = path.join(helpers.getDataDirectory(), 'settings.json');
|
||||
if (fs.existsSync(configFile)) {
|
||||
event.sender.send(Constants.IPC_Get_State_Reply, {
|
||||
data: JSON.parse(fs.readFileSync(configFile, 'utf8')),
|
||||
@@ -815,14 +805,12 @@ ipcMain.on(Constants.IPC_Install_Upgrade, (event, data) => {
|
||||
|
||||
ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
|
||||
expectedUnmount[data.StorageType] = false;
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
|
||||
|
||||
if (mountedLocations.indexOf(data.Location) !== -1) {
|
||||
console.log(data.StorageType + ' already mounted: ' + data.Location);
|
||||
} else {
|
||||
mountedLocations.push(data.Location);
|
||||
mountedData[data.Location] = {
|
||||
DataDirectory: dataDirectory,
|
||||
Version: data.Version,
|
||||
StorageType: data.StorageType,
|
||||
};
|
||||
@@ -839,7 +827,7 @@ ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
|
||||
}, error || Error(data.StorageType + ' Unmounted'));
|
||||
};
|
||||
helpers
|
||||
.executeMount(dataDirectory, data.Version, data.StorageType, data.Location, data.NoConsoleSupported, (error, pid) => {
|
||||
.executeMount(data.Version, data.StorageType, data.Location, data.NoConsoleSupported, (error, pid) => {
|
||||
errorHandler(pid, error);
|
||||
})
|
||||
.then(() => {
|
||||
@@ -854,18 +842,16 @@ ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Save_State, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
helpers.mkDirByPathSync(dataDirectory);
|
||||
const configFile = path.join(dataDirectory, 'settings.json');
|
||||
helpers.mkDirByPathSync(helpers.getDataDirectory());
|
||||
const configFile = path.join(helpers.getDataDirectory(), 'settings.json');
|
||||
fs.writeFileSync(configFile, JSON.stringify(data.State), 'utf8');
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Set_Config_Values, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
const setConfigValue = (i) => {
|
||||
if (i < data.Items.length) {
|
||||
helpers
|
||||
.setConfigValue(data.Items[i].Name, data.Items[i].Value, dataDirectory, data.StorageType, data.Version)
|
||||
.setConfigValue(data.Items[i].Name, data.Items[i].Value, data.StorageType, data.Version)
|
||||
.then(() => {
|
||||
setConfigValue(++i);
|
||||
})
|
||||
@@ -895,10 +881,9 @@ ipcMain.on(Constants.IPC_Show_Window + '_sync', event => {
|
||||
ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => {
|
||||
clearManualMountDetection(data.StorageType);
|
||||
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
expectedUnmount[data.StorageType] = true;
|
||||
helpers
|
||||
.stopMountProcess(dataDirectory, data.Version, data.StorageType)
|
||||
.stopMountProcess(data.Version, data.StorageType)
|
||||
.then((result)=> {
|
||||
console.log(result);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user