[AutoStart] Complete rewrite
This commit is contained in:
parent
07b9d052c0
commit
9e0566a418
4 changed files with 95 additions and 16 deletions
5
src/autoStart/darwin.js
Normal file
5
src/autoStart/darwin.js
Normal file
|
@ -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?
|
|
@ -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?
|
||||
module.exports = require('./' + process.platform);
|
50
src/autoStart/linux.js
Normal file
50
src/autoStart/linux.js
Normal file
|
@ -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);
|
||||
};
|
39
src/autoStart/win32.js
Normal file
39
src/autoStart/win32.js
Normal file
|
@ -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);
|
||||
});
|
||||
};
|
Loading…
Reference in a new issue