OpenAsar/src/autoStart/linux.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-12-13 08:40:18 +00:00
const fs = require('fs');
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');
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
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
Name=${basename(process.execPath, '.exe')}
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.
X-GNOME-Autostart-enabled=true`;
2021-12-13 08:40:18 +00:00
exports.install = (callback) => {
log('AutoStart', 'Install');
2021-12-13 08:40:18 +00:00
try {
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
}
};
exports.update = (callback) => callback();
exports.uninstall = (callback) => fs.unlink(desktopPath, callback);
2021-12-13 08:40:18 +00:00
exports.isInstalled = (callback) => fs.access(desktopPath, fs.constants.F_OK, callback);