You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

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