[Added tooltips] [IPC constants]
This commit is contained in:
94
electron.js
94
electron.js
@@ -2,7 +2,7 @@
|
||||
|
||||
const {app, BrowserWindow, Tray, nativeImage, Menu} = require('electron');
|
||||
const {ipcMain} = require('electron');
|
||||
|
||||
const Constants = require('./src/constants');
|
||||
const path = require('path');
|
||||
const url = require('url');
|
||||
require('electron-debug')();
|
||||
@@ -76,6 +76,14 @@ function createWindow() {
|
||||
autoLauncher.disable();
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Exit', click(item) {
|
||||
app.quit();
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
@@ -130,7 +138,7 @@ if (!instanceLock) {
|
||||
});
|
||||
}
|
||||
|
||||
ipcMain.on('check_installed', (event, data) => {
|
||||
ipcMain.on(Constants.IPC_Check_Installed, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
const destination = path.join(dataDirectory, data.Version);
|
||||
helpers
|
||||
@@ -141,7 +149,7 @@ ipcMain.on('check_installed', (event, data) => {
|
||||
exists = fs.existsSync(destination) && fs.lstatSync(destination).isDirectory();
|
||||
} catch (e) {
|
||||
}
|
||||
event.sender.send('check_installed_reply', {
|
||||
event.sender.send(Constants.IPC_Check_Installed_Reply, {
|
||||
data: {
|
||||
Dependencies: dependencies,
|
||||
Exists: exists,
|
||||
@@ -150,7 +158,7 @@ ipcMain.on('check_installed', (event, data) => {
|
||||
}
|
||||
});
|
||||
}).catch((e) => {
|
||||
event.sender.send('check_installed_reply', {
|
||||
event.sender.send(Constants.IPC_Check_Installed_Reply, {
|
||||
data: {
|
||||
Dependencies: [],
|
||||
Error: e,
|
||||
@@ -161,7 +169,7 @@ ipcMain.on('check_installed', (event, data) => {
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('delete_file', (event, data) => {
|
||||
ipcMain.on(Constants.IPC_Delete_File, (event, data) => {
|
||||
try {
|
||||
if (fs.existsSync(data.FilePath)) {
|
||||
fs.unlinkSync(data.FilePath);
|
||||
@@ -170,7 +178,7 @@ ipcMain.on('delete_file', (event, data) => {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on('detect_mounts', (event, data) => {
|
||||
ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
|
||||
let driveLetters = {
|
||||
Hyperspace: [],
|
||||
Sia: [],
|
||||
@@ -218,7 +226,7 @@ ipcMain.on('detect_mounts', (event, data) => {
|
||||
siaLocation = siaLocation.toUpperCase();
|
||||
grabDriveLetters(hsLocation, siaLocation);
|
||||
}
|
||||
event.sender.send('detect_mounts_reply', {
|
||||
event.sender.send(Constants.IPC_Detect_Mounts_Reply, {
|
||||
data: {
|
||||
DriveLetters: driveLetters,
|
||||
Locations: {
|
||||
@@ -236,7 +244,7 @@ ipcMain.on('detect_mounts', (event, data) => {
|
||||
.catch((err) => {
|
||||
grabDriveLetters('', '');
|
||||
|
||||
event.sender.send('detect_mounts_reply', {
|
||||
event.sender.send(Constants.IPC_Detect_Mounts_Reply, {
|
||||
data: {
|
||||
DriveLetters: driveLetters,
|
||||
Error: err,
|
||||
@@ -246,11 +254,11 @@ ipcMain.on('detect_mounts', (event, data) => {
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('download_file', (event, data) => {
|
||||
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('download_file_progress', {
|
||||
event.sender.send(Constants.IPC_Download_File_Progress, {
|
||||
data: {
|
||||
Destination: destination,
|
||||
Progress: progress,
|
||||
@@ -258,7 +266,7 @@ ipcMain.on('download_file', (event, data) => {
|
||||
}
|
||||
});
|
||||
}, (success, err) => {
|
||||
event.sender.send('download_file_complete', {
|
||||
event.sender.send(Constants.IPC_Download_File_Complete, {
|
||||
data: {
|
||||
Destination: destination,
|
||||
Error: err,
|
||||
@@ -269,7 +277,7 @@ ipcMain.on('download_file', (event, data) => {
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('extract_release', (event, data) => {
|
||||
ipcMain.on(Constants.IPC_Extract_Release, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
const destination = path.join(dataDirectory, data.Version);
|
||||
helpers.mkDirByPathSync(destination);
|
||||
@@ -283,7 +291,7 @@ ipcMain.on('extract_release', (event, data) => {
|
||||
} catch (e) {
|
||||
}
|
||||
stream.close();
|
||||
event.sender.send('extract_release_complete', {
|
||||
event.sender.send(Constants.IPC_Extract_Release_Complete, {
|
||||
data: {
|
||||
Error: e,
|
||||
Source: data.Source,
|
||||
@@ -293,7 +301,7 @@ ipcMain.on('extract_release', (event, data) => {
|
||||
})
|
||||
.on('finish', () => {
|
||||
stream.close();
|
||||
event.sender.send('extract_release_complete', {
|
||||
event.sender.send(Constants.IPC_Extract_Release_Complete, {
|
||||
data: {
|
||||
Source: data.Source,
|
||||
Success: true,
|
||||
@@ -302,20 +310,20 @@ ipcMain.on('extract_release', (event, data) => {
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('get_config', (event, data) => {
|
||||
ipcMain.on(Constants.IPC_Get_Config, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
helpers
|
||||
.getConfig(dataDirectory, data.Version, data.StorageType)
|
||||
.then((data) => {
|
||||
if (data.Code === 0) {
|
||||
event.sender.send('get_config_reply', {
|
||||
event.sender.send(Constants.IPC_Get_Config_Reply, {
|
||||
data: {
|
||||
Success: true,
|
||||
Config: data.Data,
|
||||
}
|
||||
});
|
||||
} else {
|
||||
event.sender.send('get_config_reply', {
|
||||
event.sender.send(Constants.IPC_Get_Config_Reply, {
|
||||
data: {
|
||||
Error: data.Code,
|
||||
Success: false,
|
||||
@@ -324,7 +332,7 @@ ipcMain.on('get_config', (event, data) => {
|
||||
}
|
||||
})
|
||||
.catch((e)=> {
|
||||
event.sender.send('get_config_reply', {
|
||||
event.sender.send(Constants.IPC_Get_Config_Reply, {
|
||||
data: {
|
||||
Error: e,
|
||||
Success: false,
|
||||
@@ -333,12 +341,12 @@ ipcMain.on('get_config', (event, data) => {
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('get_config_template', (event, data) => {
|
||||
ipcMain.on(Constants.IPC_Get_Config_Template, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
helpers
|
||||
.getConfigTemplate(dataDirectory, data.Version, data.StorageType)
|
||||
.then((data) => {
|
||||
event.sender.send('get_config_template_reply', {
|
||||
event.sender.send(Constants.IPC_Get_Config_Template_Reply, {
|
||||
data: {
|
||||
Success: true,
|
||||
Template: data,
|
||||
@@ -346,7 +354,7 @@ ipcMain.on('get_config_template', (event, data) => {
|
||||
});
|
||||
})
|
||||
.catch((e)=> {
|
||||
event.sender.send('get_config_template_reply', {
|
||||
event.sender.send(Constants.IPC_Get_Config_Template_Reply, {
|
||||
data: {
|
||||
Error: e,
|
||||
Success: false,
|
||||
@@ -355,40 +363,40 @@ ipcMain.on('get_config_template', (event, data) => {
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('get_platform', (event) => {
|
||||
event.sender.send('get_platform_reply', {
|
||||
ipcMain.on(Constants.IPC_Get_Platform, (event) => {
|
||||
event.sender.send(Constants.IPC_Get_Platform_Reply, {
|
||||
data: os.platform()
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('get_state', (event, data) => {
|
||||
ipcMain.on(Constants.IPC_Get_State, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data);
|
||||
helpers.mkDirByPathSync(dataDirectory);
|
||||
const configFile = path.join(dataDirectory, 'settings.json');
|
||||
if (fs.existsSync(configFile)) {
|
||||
event.sender.send('get_state_reply', {
|
||||
event.sender.send(Constants.IPC_Get_State_Reply, {
|
||||
data: JSON.parse(fs.readFileSync(configFile, 'utf8')),
|
||||
});
|
||||
} else {
|
||||
event.sender.send('get_state_reply', {
|
||||
event.sender.send(Constants.IPC_Get_State_Reply, {
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on('grab_releases', (event) => {
|
||||
event.sender.send('grab_releases_reply');
|
||||
ipcMain.on(Constants.IPC_Grab_Releases, (event) => {
|
||||
event.sender.send(Constants.IPC_Grab_Releases_Reply);
|
||||
});
|
||||
|
||||
ipcMain.on('grab_ui_releases', (event) => {
|
||||
event.sender.send('grab_ui_releases_reply');
|
||||
ipcMain.on(Constants.IPC_Grab_UI_Releases, (event) => {
|
||||
event.sender.send(Constants.IPC_Grab_UI_Releases_Reply);
|
||||
});
|
||||
|
||||
ipcMain.on('install_dependency', (event, data) => {
|
||||
ipcMain.on(Constants.IPC_Install_Dependency, (event, data) => {
|
||||
helpers
|
||||
.executeAndWait(data.Source)
|
||||
.then(()=> {
|
||||
event.sender.send('install_dependency_reply', {
|
||||
event.sender.send(Constants.IPC_Install_Dependency_Reply, {
|
||||
data: {
|
||||
Source: data.Source,
|
||||
Success: true,
|
||||
@@ -396,7 +404,7 @@ ipcMain.on('install_dependency', (event, data) => {
|
||||
});
|
||||
})
|
||||
.catch((e)=> {
|
||||
event.sender.send('install_dependency_reply', {
|
||||
event.sender.send(Constants.IPC_Install_Dependency_Reply, {
|
||||
data: {
|
||||
Error: e,
|
||||
Source: data.Source,
|
||||
@@ -406,14 +414,14 @@ ipcMain.on('install_dependency', (event, data) => {
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('install_upgrade', (event, data) => {
|
||||
ipcMain.on(Constants.IPC_Install_Upgrade, (event, data) => {
|
||||
helpers
|
||||
.executeAsync(data.Source)
|
||||
.then(()=> {
|
||||
mainWindow.close();
|
||||
})
|
||||
.catch((e)=> {
|
||||
event.sender.send('install_upgrade_reply', {
|
||||
event.sender.send(Constants.IPC_Install_Upgrade_Reply, {
|
||||
data: {
|
||||
Error: e,
|
||||
Source: data.Source,
|
||||
@@ -423,11 +431,11 @@ ipcMain.on('install_upgrade', (event, data) => {
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('mount_drive', (event, data) => {
|
||||
ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
const errorHandler = (pid) => {
|
||||
mountedPIDs.splice(mountedPIDs.indexOf(pid), 1);
|
||||
event.sender.send('unmount_drive_reply', {
|
||||
event.sender.send(Constants.IPC_Unmount_Drive_Reply, {
|
||||
data: {
|
||||
PID: -1,
|
||||
StorageType: data.StorageType,
|
||||
@@ -442,7 +450,7 @@ ipcMain.on('mount_drive', (event, data) => {
|
||||
if (pid !== -1) {
|
||||
mountedPIDs.push(pid);
|
||||
}
|
||||
event.sender.send('mount_drive_reply', {
|
||||
event.sender.send(Constants.IPC_Mount_Drive_Reply, {
|
||||
data: {
|
||||
PID: pid,
|
||||
StorageType: data.StorageType,
|
||||
@@ -455,14 +463,14 @@ ipcMain.on('mount_drive', (event, data) => {
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('save_state', (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');
|
||||
fs.writeFileSync(configFile, JSON.stringify(data.State), 'utf8');
|
||||
});
|
||||
|
||||
ipcMain.on('set_config_values', (event, data) => {
|
||||
ipcMain.on(Constants.IPC_Set_Config_Values, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
const setConfigValue = (i) => {
|
||||
if (i < data.Items.length) {
|
||||
@@ -475,18 +483,18 @@ ipcMain.on('set_config_values', (event, data) => {
|
||||
setConfigValue(++i);
|
||||
});
|
||||
} else {
|
||||
event.sender.send('set_config_values_reply', {});
|
||||
event.sender.send(Constants.IPC_Set_Config_Values_Reply, {});
|
||||
}
|
||||
};
|
||||
setConfigValue(0);
|
||||
});
|
||||
|
||||
ipcMain.on('unmount_drive', (event, data) => {
|
||||
ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => {
|
||||
helpers
|
||||
.stopProcessByPID(data.PID)
|
||||
.then((pid)=> {
|
||||
if (mountedPIDs.indexOf(pid) === -1) {
|
||||
event.sender.send('unmount_drive_reply');
|
||||
event.sender.send(Constants.IPC_Unmount_Drive_Reply);
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
|
||||
Reference in New Issue
Block a user