OpenAsar/src/autoStart/linux.js

33 lines
999 B
JavaScript
Raw Normal View History

2021-12-13 08:40:18 +00:00
const fs = require('fs');
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 exec = app.getPath('exe');
2021-12-13 08:40:18 +00:00
// Template for desktop file
const desktopContent = `[Desktop Entry]
Type=Application
Exec=${exec}
Name=${basename(process.execPath)}
Icon=${join(global.systemElectron ? '/usr/share/pixmaps' : dirname(exec), 'discord.png')}
2023-03-23 20:53:23 +00:00
Comment=Text and voice chat for gamers.`;
2021-12-13 08:40:18 +00:00
exports.install = (cb) => {
2021-12-13 08:40:18 +00:00
try {
fs.mkdirSync(dirname(desktopPath), { recursive: true });
fs.writeFile(desktopPath, desktopContent, cb);
} catch {
cb(); // Callback anyway
2021-12-13 08:40:18 +00:00
}
};
exports.update = (cb) => cb();
exports.uninstall = (cb) => fs.unlink(desktopPath, cb);
2021-12-13 08:40:18 +00:00
exports.isInstalled = (cb) => fs.access(desktopPath, fs.constants.F_OK, cb);