diff --git a/src/autoStart/darwin.js b/src/autoStart/darwin.js new file mode 100644 index 0000000..4fd80e9 --- /dev/null +++ b/src/autoStart/darwin.js @@ -0,0 +1,5 @@ +// Stub in normal Discord +exports.install = (callback) => { callback(); }; +exports.update = (callback) => { callback(); }; +exports.uninstall = (callback) => { callback(); }; +exports.isInstalled = (callback) => { callback(false); }; // Stub to true or false? \ No newline at end of file diff --git a/src/autoStart/index.js b/src/autoStart/index.js index 1d5e949..b7d5423 100644 --- a/src/autoStart/index.js +++ b/src/autoStart/index.js @@ -1,18 +1,3 @@ // Stub for now at least, also retaining OpenAsar -const retainAsar = require('./retainAsar'); - -exports.install = (callback) => { callback(); }; -exports.update = (callback) => { - if (process.platform === 'win32') { - try { - retainAsar(); - } catch (e) { - log('RetainAsar', 'Error', e); - } - } - - callback(); -}; -exports.uninstall = (callback) => { callback(); }; -exports.isInstalled = (callback) => { callback(true); }; // Stub to true or false? \ No newline at end of file +module.exports = require('./' + process.platform); \ No newline at end of file diff --git a/src/autoStart/linux.js b/src/autoStart/linux.js new file mode 100644 index 0000000..ed5fe0e --- /dev/null +++ b/src/autoStart/linux.js @@ -0,0 +1,50 @@ +const fs = require('fs'); +const path = require('path'); +const { app } = require('electron'); + +const buildInfo = require('../utils/buildInfo'); + +const autostartDir = path.join(app.getPath('appData'), 'autostart'); +const desktopPath = path.join(autostartDir, (app.name ? app.name : app.getName()) + '-' + buildInfo.releaseChannel + '.desktop'); + +// Vars for use in desktop file content template +const appName = path.basename(process.execPath, '.exe'); +const exePath = app.getPath('exe'); +const iconPath = path.join(path.dirname(exePath), 'discord.png'); + +// Template for desktop file +const desktopContent = `[Desktop Entry] +Type=Application +Exec=${exePath} +Hidden=false +NoDisplay=false +Name=${appName} +Icon=${iconPath} +Comment=Text and voice chat for gamers. +X-GNOME-Autostart-enabled=true +`; + +exports.install = (callback) => { + try { + fs.mkdirSync(autostartDir); + } catch (_e) { } // Already exists, ignore + + try { + return fs.writeFile(desktopPath, desktopContent, callback); + } catch (e) { + log('AutoStart', 'Install: error writing file', e); + return callback(); // Callback anyway + } +}; + +exports.update = (callback) => { // Discord has stub here + callback(); +}; + +exports.uninstall = (callback) => { + return fs.unlink(desktopPath, callback); +}; + +exports.isInstalled = (callback) => { + return fs.access(desktopPath, fs.constants.F_OK, callback); +}; \ No newline at end of file diff --git a/src/autoStart/win32.js b/src/autoStart/win32.js new file mode 100644 index 0000000..e0d5ed0 --- /dev/null +++ b/src/autoStart/win32.js @@ -0,0 +1,39 @@ +const path = require('path'); + +const windowsUtils = require('../utils/windowsUtils'); +const retainAsar = require('./retainAsar'); + +const appSettings = require('../appSettings'); +const settings = appSettings.getSettings(); + +const appName = _path.basename(process.execPath, '.exe'); +const fullExeName = path.basename(process.execPath); +const updatePath = path.join(path.dirname(process.execPath), '..', 'Update.exe'); + +exports.install = (callback) => { + let execPath = `${updatePath} --processStart ${fullExeName}`; + + if (settings.get('START_MINIMIZED', false)) { // If start minimized enabled, pass it to Electron via --process-start-args + execPath += ' --process-start-args --start-minimized'; + } + + windowsUtils.addToRegistry([['HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/v', appName, '/d', execPath]], callback); // Make reg +}; + +exports.update = (callback) => { + isInstalled(installed => installed ? install(callback) : callback()); // Reinstall if installed, else leave it (just callback) + + retainAsar(); // Retain OpenAsar +}; + +exports.uninstall = (callback) => { + windowsUtils.spawnReg(['delete', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/v', appName, '/f'], (_error, _stdout) => { // Delete reg + callback(); + }); +}; + +exports.isInstalled = (callback) => { + windowsUtils.spawnReg(['query', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/v', appName], (_error, stdout) => { // Check reg + callback(stdout.indexOf(appName) > -1); + }); +}; \ No newline at end of file