mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
- Deleting the data folder on crash and unexpected shutdown - Created script for clearing the index data on start up - Working in dev env - Added path to package - Windows path file change - Working on production build - Completed implementation - Few changes to callback - Few changes to callback - Updated package - Fixed windows bug - Fixed windows bug - Fixed windows bug - Added exe for task - Added exe for task - Fixed exe file - Code refactoring - Updated api file - Added uuid for the task name - Updated exe for the uuid - Updated API file - AIP version - Fixes all the scenarios for mac - Updated the boot file to clear data file on login - Fixed data folder deleting on application is open - Windows launch agent - Working on all the scenario - Added a launch script and starting the register - Updated search-win-task.exe file - Updating the aip file - Updating the aip file - Removed randomString lib - Requested changes (PR) - Included the library from new repo electron-uitls - Updated AIP file - Updated AIP - Bumped up electron-utils version - Added missing quotes - Bumped up electron-utils version - Added missing quotes - Bumped utils version - Bumped utils version - Update AIP
105 lines
3.0 KiB
JavaScript
105 lines
3.0 KiB
JavaScript
const { exec, execSync } = require('child_process');
|
|
const os = require('os');
|
|
const { randomString } = require('./randomString.js');
|
|
const log = require('../../log.js');
|
|
const logLevels = require('../../enums/logLevels.js');
|
|
const Winreg = require('winreg');
|
|
|
|
/**
|
|
* Register for creating launch agent
|
|
* @type {Registry}
|
|
*/
|
|
const regKey = new Winreg({
|
|
hive: Winreg.HKCU,
|
|
key: '\\Software\\Microsoft\\Windows\\CurrentVersion\\Run'
|
|
});
|
|
|
|
/**
|
|
* Clears the data folder on app crash
|
|
* @param pid
|
|
* @param script
|
|
* @param cb (callback)
|
|
*/
|
|
function launchAgent(pid, script, cb) {
|
|
exec(`sh "${script}" true ${pid}`, (error, stdout, stderr) => {
|
|
if (error) {
|
|
log.send(logLevels.ERROR, `Lanuchd: Error creating script ${error}`);
|
|
return cb(false);
|
|
}
|
|
if (stderr) {
|
|
log.send(logLevels.ERROR, `Lanuchd: Error creating script ${stderr}`);
|
|
}
|
|
return cb(true);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Clears the data folder on boot
|
|
* @param script
|
|
* @param cb (callback)
|
|
*/
|
|
function launchDaemon(script, cb) {
|
|
exec(`sh "${script}" true`, (error, stdout, stderr) => {
|
|
if (error) {
|
|
log.send(logLevels.ERROR, `Lanuchd: Error creating script ${error}`);
|
|
return cb(false);
|
|
}
|
|
if (stderr) {
|
|
log.send(logLevels.ERROR, `Lanuchd: Error creating script ${stderr}`);
|
|
}
|
|
return cb(true);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Windows clears the data folder on app crash
|
|
* @param script
|
|
* @param dataFolder
|
|
* @param pid
|
|
* @param clearScript
|
|
*/
|
|
function taskScheduler(script, dataFolder, pid, clearScript) {
|
|
let userName;
|
|
if (os.userInfo) {
|
|
userName = os.userInfo().username;
|
|
} else {
|
|
try {
|
|
userName = execSync('whoami').toString().replace(/^.*\\/, '');
|
|
} catch (e) {
|
|
log.send(logLevels.WARN, `whoami failed (using randomString): ${e}`);
|
|
userName = randomString();
|
|
}
|
|
}
|
|
exec(`SCHTASKS /Create /SC MINUTE /TN "SymphonyTask${userName}" /TR "'${script}' '${dataFolder}' 'SymphonyTask${userName}' '${pid}'" /F`, (error, stdout, stderr) => {
|
|
if (error) {
|
|
log.send(logLevels.ERROR, `Lanuchd: Error creating task ${error}`);
|
|
}
|
|
if (stderr) {
|
|
log.send(logLevels.WARN, `Lanuchd: Error creating task ${stderr}`);
|
|
}
|
|
log.send(logLevels.INFO, `Lanuchd: Creating task successful ${stdout}`);
|
|
});
|
|
|
|
winRegScript(userName, clearScript, dataFolder);
|
|
}
|
|
|
|
/**
|
|
* Clear the data folder on user login for first time
|
|
* @param userName
|
|
* @param script
|
|
* @param dataFolder
|
|
*/
|
|
function winRegScript(userName, script, dataFolder) {
|
|
regKey.set(`SymphonyTask-${userName}`, Winreg.REG_SZ, `"${script}" "${dataFolder}"`, function(err) {
|
|
if (err !== null) {
|
|
log.send(logLevels.INFO, `winReg: Creating task failed ${err}`);
|
|
}
|
|
log.send(logLevels.INFO, 'winReg: Creating task successful');
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
launchAgent,
|
|
launchDaemon,
|
|
taskScheduler
|
|
}; |