[AutoStart > Linux] Clean up code (rewrite to simplify and not use as much)
This commit is contained in:
parent
7d173db003
commit
17f264e6bd
1 changed files with 9 additions and 23 deletions
|
@ -1,16 +1,15 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const mkdirp = require('mkdirp');
|
||||
const { join, basename, dirname } = 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');
|
||||
const desktopPath = join(app.getPath('appData'), 'autostart', app.name + '-' + buildInfo.releaseChannel + '.desktop');
|
||||
|
||||
// Vars for use in desktop file content template
|
||||
const appName = path.basename(process.execPath, '.exe');
|
||||
const exePath = global.systemElectron ? '/usr/share/pixmaps/Discord' : app.getPath('exe');
|
||||
const iconPath = path.join(path.dirname(exePath), 'discord.png');
|
||||
const iconPath = join(dirname(exePath), 'discord.png');
|
||||
|
||||
// Template for desktop file
|
||||
const desktopContent = `[Desktop Entry]
|
||||
|
@ -18,7 +17,7 @@ Type=Application
|
|||
Exec=${exePath}
|
||||
Hidden=false
|
||||
NoDisplay=false
|
||||
Name=${appName}
|
||||
Name=${basename(process.execPath, '.exe')}
|
||||
Icon=${iconPath}
|
||||
Comment=Text and voice chat for gamers.
|
||||
X-GNOME-Autostart-enabled=true`;
|
||||
|
@ -27,10 +26,7 @@ exports.install = (callback) => {
|
|||
log('AutoStart', 'Install');
|
||||
|
||||
try {
|
||||
fs.mkdirSync(autostartDir);
|
||||
} catch (_e) { } // Already exists, ignore
|
||||
|
||||
try {
|
||||
mkdirp.sync(dirname(desktopPath));
|
||||
return fs.writeFile(desktopPath, desktopContent, callback);
|
||||
} catch (e) {
|
||||
log('AutoStart', 'Install: error writing file', e);
|
||||
|
@ -38,18 +34,8 @@ exports.install = (callback) => {
|
|||
}
|
||||
};
|
||||
|
||||
exports.update = (callback) => { // Discord has stub here
|
||||
log('AutoStart', 'Update');
|
||||
exports.update = (callback) => callback();
|
||||
|
||||
callback();
|
||||
};
|
||||
exports.uninstall = (callback) => fs.unlink(desktopPath, callback);
|
||||
|
||||
exports.uninstall = (callback) => {
|
||||
log('AutoStart', 'Uninstall');
|
||||
|
||||
return fs.unlink(desktopPath, callback);
|
||||
};
|
||||
|
||||
exports.isInstalled = (callback) => {
|
||||
return fs.access(desktopPath, fs.constants.F_OK, callback);
|
||||
};
|
||||
exports.isInstalled = (callback) => fs.access(desktopPath, fs.constants.F_OK, callback);
|
Loading…
Reference in a new issue