mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-01-08 23:23:02 -06:00
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
|
const AutoLaunch = require('auto-launch');
|
||
|
|
||
|
// Local Dependencies
|
||
|
const log = require('../log.js');
|
||
|
const logLevels = require('../enums/logLevels.js');
|
||
|
const { readConfigFileSync } = require('../config.js');
|
||
|
const { isMac } = require('../utils/misc.js');
|
||
|
|
||
|
const globalConfigData = readConfigFileSync();
|
||
|
const props = isMac ? {
|
||
|
name: 'Symphony',
|
||
|
mac: {
|
||
|
useLaunchAgent: true,
|
||
|
},
|
||
|
path: process.execPath,
|
||
|
} : {
|
||
|
name: 'Symphony',
|
||
|
path: getAutoLaunchPath() || process.execPath,
|
||
|
};
|
||
|
|
||
|
class AutoLaunchController extends AutoLaunch {
|
||
|
|
||
|
constructor(opts) {
|
||
|
super(opts);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Enable auto launch
|
||
|
* @return {Promise<void>}
|
||
|
*/
|
||
|
enableAutoLaunch() {
|
||
|
log.send(logLevels.INFO, `Enabling auto launch!`);
|
||
|
return this.enable();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Disable auto launch
|
||
|
* @return {Promise<void>}
|
||
|
*/
|
||
|
disableAutoLaunch() {
|
||
|
log.send(logLevels.INFO, `Disabling auto launch!`);
|
||
|
return this.disable();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Replace forward slash in the path to backward slash
|
||
|
* @return {any}
|
||
|
*/
|
||
|
function getAutoLaunchPath() {
|
||
|
const autoLaunchPath = globalConfigData && globalConfigData.autoLaunchPath || null;
|
||
|
return autoLaunchPath ? autoLaunchPath.replace(/\//g, '\\') : null;
|
||
|
}
|
||
|
|
||
|
const autoLaunchInstance = new AutoLaunchController(props);
|
||
|
|
||
|
module.exports = {
|
||
|
enable: autoLaunchInstance.enableAutoLaunch.bind(autoLaunchInstance),
|
||
|
disable: autoLaunchInstance.disableAutoLaunch.bind(autoLaunchInstance)
|
||
|
};
|