summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-04-20 13:32:37 +0200
committerOskar Nyberg <oskar@mullvad.net>2021-04-20 13:32:37 +0200
commitf303e65532c1117bb0eaad2c2f072a8f7bef7651 (patch)
tree80ca22019d8288f2cc1ccd1690ff7a4b7b982d5e
parent635c3cbc166a57b9a00c622eb62572566430cb38 (diff)
parent32ac19525d4b481c6fad5fc7f58faa50279160ca (diff)
downloadmullvadvpn-f303e65532c1117bb0eaad2c2f072a8f7bef7651.tar.xz
mullvadvpn-f303e65532c1117bb0eaad2c2f072a8f7bef7651.zip
Merge branch 'search-for-mullvad-vpn'
-rw-r--r--CHANGELOG.md2
-rw-r--r--gui/src/main/autostart.ts35
2 files changed, 22 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b9152848d2..a963d155cc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -42,6 +42,8 @@ Line wrap the file at 100 chars. Th
#### Windows
- Prevent tray icons from being extraced to `%TEMP%` directory.
+#### Linux
+- Fix find `mullvad-vpn.desktop` in `XDG_DATA_DIRS` instead of using hardcoded path.
## [2021.3-beta1] - 2021-04-13
This release is for desktop only.
diff --git a/gui/src/main/autostart.ts b/gui/src/main/autostart.ts
index f5369b6723..8c77ba3b6a 100644
--- a/gui/src/main/autostart.ts
+++ b/gui/src/main/autostart.ts
@@ -1,16 +1,11 @@
import { app } from 'electron';
-import * as fs from 'fs';
-import * as path from 'path';
-import { promisify } from 'util';
+import fs from 'fs';
+import path from 'path';
import log from '../shared/logging';
+import { getDesktopEntries } from './linux-desktop-entry';
const DESKTOP_FILE_NAME = 'mullvad-vpn.desktop';
-const mkdirAsync = promisify(fs.mkdir);
-const statAsync = promisify(fs.stat);
-const symlinkAsync = promisify(fs.symlink);
-const unlinkAsync = promisify(fs.unlink);
-
export function getOpenAtLogin() {
if (process.platform === 'linux') {
try {
@@ -32,15 +27,15 @@ export function getOpenAtLogin() {
export async function setOpenAtLogin(openAtLogin: boolean) {
if (process.platform === 'linux') {
try {
- const desktopFilePath = path.join('/usr/share/applications', DESKTOP_FILE_NAME);
+ const desktopFilePath = await getDesktopEntryPath();
const autostartDir = path.join(app.getPath('appData'), 'autostart');
const autostartFilePath = path.join(autostartDir, DESKTOP_FILE_NAME);
if (openAtLogin) {
await createDirIfNecessary(autostartDir);
- await symlinkAsync(desktopFilePath, autostartFilePath);
+ await fs.promises.symlink(desktopFilePath, autostartFilePath);
} else {
- await unlinkAsync(autostartFilePath);
+ await fs.promises.unlink(autostartFilePath);
}
} catch (error) {
log.error(`Failed to set auto-start: ${error.message}`);
@@ -50,24 +45,34 @@ export async function setOpenAtLogin(openAtLogin: boolean) {
}
}
+async function getDesktopEntryPath(): Promise<string> {
+ const entries = await getDesktopEntries();
+ const entry = entries.find((entry) => path.parse(entry).base === DESKTOP_FILE_NAME);
+ if (entry) {
+ return entry;
+ } else {
+ throw new Error(`Couldn't find ${DESKTOP_FILE_NAME}`);
+ }
+}
+
const createDirIfNecessary = async (directory: string) => {
let stat;
try {
- stat = await statAsync(directory);
+ stat = await fs.promises.stat(directory);
} catch (error) {
// Path doesn't exist, so it has to be created
- return mkdirAsync(directory);
+ return fs.promises.mkdir(directory);
}
// Is there a file instead of a directory?
if (!stat.isDirectory()) {
// Try to remove existing file and replace it with a new directory
try {
- await unlinkAsync(directory);
+ await fs.promises.unlink(directory);
} catch (error) {
log.error(`Failed to remove path before creating a directory for it: ${error.message}`);
}
- return mkdirAsync(directory);
+ return fs.promises.mkdir(directory);
}
};