2021-12-13 08:40:18 +00:00
|
|
|
const fs = require('fs');
|
2022-01-29 11:03:08 +00:00
|
|
|
const mkdirp = require('mkdirp');
|
|
|
|
const { join, basename, dirname } = require('path');
|
2021-12-13 08:40:18 +00:00
|
|
|
const { app } = require('electron');
|
|
|
|
|
|
|
|
const buildInfo = require('../utils/buildInfo');
|
|
|
|
|
2022-01-29 11:03:08 +00:00
|
|
|
const desktopPath = join(app.getPath('appData'), 'autostart', app.name + '-' + buildInfo.releaseChannel + '.desktop');
|
2021-12-13 08:40:18 +00:00
|
|
|
|
|
|
|
// Vars for use in desktop file content template
|
2022-02-13 19:13:29 +00:00
|
|
|
const exePath = app.getPath('exe');
|
2021-12-13 08:40:18 +00:00
|
|
|
|
|
|
|
// Template for desktop file
|
|
|
|
const desktopContent = `[Desktop Entry]
|
|
|
|
Type=Application
|
|
|
|
Exec=${exePath}
|
|
|
|
Hidden=false
|
|
|
|
NoDisplay=false
|
2022-01-29 11:03:08 +00:00
|
|
|
Name=${basename(process.execPath, '.exe')}
|
2022-02-13 19:13:29 +00:00
|
|
|
Icon=${join(global.systemElectron ? '/usr/share/pixmaps/Discord' : dirname(exePath), 'discord.png')}
|
2021-12-13 08:40:18 +00:00
|
|
|
Comment=Text and voice chat for gamers.
|
2022-01-28 19:17:06 +00:00
|
|
|
X-GNOME-Autostart-enabled=true`;
|
2021-12-13 08:40:18 +00:00
|
|
|
|
|
|
|
exports.install = (callback) => {
|
2021-12-13 18:59:56 +00:00
|
|
|
log('AutoStart', 'Install');
|
|
|
|
|
2021-12-13 08:40:18 +00:00
|
|
|
try {
|
2022-01-29 11:03:08 +00:00
|
|
|
mkdirp.sync(dirname(desktopPath));
|
2021-12-13 08:40:18 +00:00
|
|
|
return fs.writeFile(desktopPath, desktopContent, callback);
|
|
|
|
} catch (e) {
|
|
|
|
log('AutoStart', 'Install: error writing file', e);
|
|
|
|
return callback(); // Callback anyway
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-29 11:03:08 +00:00
|
|
|
exports.update = (callback) => callback();
|
2021-12-13 18:59:56 +00:00
|
|
|
|
2022-01-29 11:03:08 +00:00
|
|
|
exports.uninstall = (callback) => fs.unlink(desktopPath, callback);
|
2021-12-13 08:40:18 +00:00
|
|
|
|
2022-01-29 11:03:08 +00:00
|
|
|
exports.isInstalled = (callback) => fs.access(desktopPath, fs.constants.F_OK, callback);
|