CEO updated
This commit is contained in:
+102
-12
@@ -6,15 +6,17 @@ const {fork} = require('child_process');
|
||||
|
||||
const {encryptFileInPlace, decryptFileInPlace} = require('./aes_encrypt');
|
||||
const {lockFile, unlockFile} = require("../../helpers/lock_mechanism");
|
||||
//const {decryptUserFilesToDirectory} = require("../../jobs/backup");
|
||||
|
||||
const isMac = process.platform === 'darwin';
|
||||
let html_page = undefined;
|
||||
let mainWindow = undefined;
|
||||
let alertWindow = undefined;
|
||||
|
||||
let backupProcess = null;
|
||||
let receiverProcess = null;
|
||||
let fetcherProcess = null;
|
||||
let backupProcess = null;
|
||||
let externalEndpointsProcess = null;
|
||||
let sendFileProcess = null;
|
||||
|
||||
const create_initial_keys = () => {
|
||||
const SECRET_KEY = crypto.randomBytes(32);
|
||||
@@ -144,12 +146,16 @@ app.on('before-quit', () => {
|
||||
if (backupProcess !== null) {
|
||||
backupProcess.kill();
|
||||
}
|
||||
if (receiverProcess !== null) {
|
||||
receiverProcess.kill();
|
||||
if (externalEndpointsProcess !== null) {
|
||||
externalEndpointsProcess.kill();
|
||||
}
|
||||
if (fetcherProcess !== null) {
|
||||
fetcherProcess.kill();
|
||||
}
|
||||
|
||||
if (sendFileProcess !== null) {
|
||||
sendFileProcess.kill();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
@@ -214,7 +220,24 @@ ipcMain.handle('change-content', async (event, nextPage) => {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle('open-backup-dir-dialog', async (event) => {
|
||||
ipcMain.handle('open-dir-dialog', async (event) => {
|
||||
try {
|
||||
const result = await dialog.showOpenDialog({
|
||||
properties: ['openDirectory'],
|
||||
});
|
||||
|
||||
if (result.canceled || result.filePaths.length === 0) {
|
||||
return {canceled: true}
|
||||
}
|
||||
|
||||
return result.filePaths[0];
|
||||
} catch (error) {
|
||||
console.error('Error opening file dialog:', error);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.handle('open-json-dir-config', async (event, fileName) => {
|
||||
try {
|
||||
const result = await dialog.showOpenDialog({
|
||||
properties: ['openDirectory'],
|
||||
@@ -226,10 +249,9 @@ ipcMain.handle('open-backup-dir-dialog', async (event) => {
|
||||
|
||||
const dirPath = result.filePaths[0];
|
||||
await fs.promises.writeFile(
|
||||
path.join(__dirname, '..', '..', 'dirBackup.json'),
|
||||
path.join(__dirname, '..', '..', fileName),
|
||||
JSON.stringify({
|
||||
path: dirPath,
|
||||
structure: {}
|
||||
path: dirPath
|
||||
}, null, 2));
|
||||
|
||||
return true;
|
||||
@@ -271,13 +293,81 @@ ipcMain.on('close-alert-window', () => {
|
||||
});
|
||||
|
||||
//External processes
|
||||
ipcMain.handle('start-fetcher', async (event, args) => {
|
||||
if (fetcherProcess === null) {
|
||||
fetcherProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'fetcher.js'), args, {silent: false});
|
||||
ipcMain.handle('start-main-processes', async (event, args) => {
|
||||
if (!backupProcess) {
|
||||
backupProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'backup.js'), args, { silent: false });
|
||||
backupProcess.on('exit', () => {
|
||||
backupProcess = null;
|
||||
});
|
||||
backupProcess.on('error', (err) => {
|
||||
console.log('Backup process error:', err);
|
||||
});
|
||||
}
|
||||
|
||||
if (!fetcherProcess) {
|
||||
fetcherProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'fetcher.js'), args, { silent: false });
|
||||
fetcherProcess.on('exit', () => {
|
||||
fetcherProcess = null;
|
||||
// Optionally, notify the renderer process that the fetcher has finished
|
||||
});
|
||||
fetcherProcess.on('error', (err) => {
|
||||
console.log('Fetcher process error:', err);
|
||||
});
|
||||
|
||||
fetcherProcess.on('message', (message) => {
|
||||
if (message.type === 'startBackup') {
|
||||
backupProcess.send({
|
||||
type: 'startBackup'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!externalEndpointsProcess) {
|
||||
externalEndpointsProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'external_endpoints.js'), args, { silent: false });
|
||||
externalEndpointsProcess.on('exit', () => {
|
||||
externalEndpointsProcess = null;
|
||||
});
|
||||
externalEndpointsProcess.on('error', (err) => {
|
||||
console.log('External endpoints process error:', err);
|
||||
});
|
||||
}
|
||||
|
||||
return true; // Indicate that the operation has started
|
||||
});
|
||||
|
||||
ipcMain.handle('start-send-file-process', async (event, args) => {
|
||||
if (sendFileProcess === null) {
|
||||
sendFileProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'send_file.js'), args, {silent: false});
|
||||
sendFileProcess.on('exit', () => {
|
||||
sendFileProcess = null;
|
||||
});
|
||||
}
|
||||
return true; // Indicate that the operation has started
|
||||
});
|
||||
|
||||
ipcMain.handle('kill-before-logout', async(event) =>{
|
||||
if (backupProcess !== null) {
|
||||
backupProcess.kill('SIGINT');
|
||||
}
|
||||
if (externalEndpointsProcess !== null) {
|
||||
externalEndpointsProcess.kill('SIGINT');
|
||||
}
|
||||
if (fetcherProcess !== null) {
|
||||
fetcherProcess.kill('SIGINT');
|
||||
}
|
||||
|
||||
if (sendFileProcess !== null) {
|
||||
sendFileProcess.kill('SIGINT');
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.handle('decrypt-backup-files', async(event, destPath) => {
|
||||
console.log('ai intrat in handle')
|
||||
if(backupProcess != null){
|
||||
console.log('esti in process');
|
||||
backupProcess.send({
|
||||
type: 'decryptBackup',
|
||||
decryptDestPath: destPath
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
@@ -7,13 +7,12 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
||||
changeContent: (nextPage) => ipcRenderer.invoke('change-content', nextPage),
|
||||
showAlert: (message) => ipcRenderer.invoke('show-alert', message),
|
||||
closeAlertWindow: () => ipcRenderer.send('close-alert-window'),
|
||||
openBackupDirDialog: () => ipcRenderer.invoke('open-backup-dir-dialog'),
|
||||
openJsonDirConfigDialog: (fileName) => ipcRenderer.invoke('open-json-dir-config', fileName),
|
||||
openDirDialog: () => ipcRenderer.invoke('open-dir-dialog'),
|
||||
openFileDialog: () => ipcRenderer.invoke('open-file-dialog'),
|
||||
checkFileExists: (fileName) => ipcRenderer.invoke('check-file-exists', fileName),
|
||||
|
||||
startFetcher: async (args) => ipcRenderer.invoke('start-fetcher', args),
|
||||
startBackup: async (args) => ipcRenderer.invoke('start-backup', args),
|
||||
startDecryptFiles: async (args) => ipcRenderer.invoke('start-decrypt-files', args),
|
||||
startSendFiles: async (args) => ipcRenderer.invoke('start-send_files', args),
|
||||
startReceiver: async (args) => ipcRenderer.invoke('start-receiver', args)
|
||||
startMainProcesses: async (args) => ipcRenderer.invoke('start-main-processes', args),
|
||||
killBeforeLogout: async() => ipcRenderer.invoke('kill-before-logout'),
|
||||
decryptFiles: async(destPath) => ipcRenderer.invoke('decrypt-backup-files', destPath)
|
||||
});
|
||||
Reference in New Issue
Block a user