[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 fs = require('fs');
|
||||||
const path = require('path');
|
const mkdirp = require('mkdirp');
|
||||||
|
const { join, basename, dirname } = require('path');
|
||||||
const { app } = require('electron');
|
const { app } = require('electron');
|
||||||
|
|
||||||
const buildInfo = require('../utils/buildInfo');
|
const buildInfo = require('../utils/buildInfo');
|
||||||
|
|
||||||
const autostartDir = path.join(app.getPath('appData'), 'autostart');
|
const desktopPath = join(app.getPath('appData'), 'autostart', app.name + '-' + buildInfo.releaseChannel + '.desktop');
|
||||||
const desktopPath = path.join(autostartDir, (app.name ? app.name : app.getName()) + '-' + buildInfo.releaseChannel + '.desktop');
|
|
||||||
|
|
||||||
// Vars for use in desktop file content template
|
// 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 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
|
// Template for desktop file
|
||||||
const desktopContent = `[Desktop Entry]
|
const desktopContent = `[Desktop Entry]
|
||||||
|
@ -18,7 +17,7 @@ Type=Application
|
||||||
Exec=${exePath}
|
Exec=${exePath}
|
||||||
Hidden=false
|
Hidden=false
|
||||||
NoDisplay=false
|
NoDisplay=false
|
||||||
Name=${appName}
|
Name=${basename(process.execPath, '.exe')}
|
||||||
Icon=${iconPath}
|
Icon=${iconPath}
|
||||||
Comment=Text and voice chat for gamers.
|
Comment=Text and voice chat for gamers.
|
||||||
X-GNOME-Autostart-enabled=true`;
|
X-GNOME-Autostart-enabled=true`;
|
||||||
|
@ -27,10 +26,7 @@ exports.install = (callback) => {
|
||||||
log('AutoStart', 'Install');
|
log('AutoStart', 'Install');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.mkdirSync(autostartDir);
|
mkdirp.sync(dirname(desktopPath));
|
||||||
} catch (_e) { } // Already exists, ignore
|
|
||||||
|
|
||||||
try {
|
|
||||||
return fs.writeFile(desktopPath, desktopContent, callback);
|
return fs.writeFile(desktopPath, desktopContent, callback);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('AutoStart', 'Install: error writing file', e);
|
log('AutoStart', 'Install: error writing file', e);
|
||||||
|
@ -38,18 +34,8 @@ exports.install = (callback) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.update = (callback) => { // Discord has stub here
|
exports.update = (callback) => callback();
|
||||||
log('AutoStart', 'Update');
|
|
||||||
|
|
||||||
callback();
|
exports.uninstall = (callback) => fs.unlink(desktopPath, callback);
|
||||||
};
|
|
||||||
|
|
||||||
exports.uninstall = (callback) => {
|
exports.isInstalled = (callback) => fs.access(desktopPath, fs.constants.F_OK, callback);
|
||||||
log('AutoStart', 'Uninstall');
|
|
||||||
|
|
||||||
return fs.unlink(desktopPath, callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.isInstalled = (callback) => {
|
|
||||||
return fs.access(desktopPath, fs.constants.F_OK, callback);
|
|
||||||
};
|
|
Loading…
Reference in a new issue