aboutsummaryrefslogtreecommitdiffstats
path: root/src/enforce-macos-app-location.ts
diff options
context:
space:
mode:
authorLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2021-10-02 05:47:36 +0530
committerLibravatar GitHub <noreply@github.com>2021-10-02 05:47:36 +0530
commit7612949b153ca25b8d36920732dd37defec7a581 (patch)
tree17cf03fce793afb1a51ffdb778a47e36cc39fd50 /src/enforce-macos-app-location.ts
parentfix: fix issue with past commit related to 'environment-remote' (diff)
downloadferdium-app-7612949b153ca25b8d36920732dd37defec7a581.tar.gz
ferdium-app-7612949b153ca25b8d36920732dd37defec7a581.tar.zst
ferdium-app-7612949b153ca25b8d36920732dd37defec7a581.zip
refactor: remove 'electron-util' and 'electron-is-dev' as dependencies (#2008)
(pre-requisite for electron v14)
Diffstat (limited to 'src/enforce-macos-app-location.ts')
-rw-r--r--src/enforce-macos-app-location.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/enforce-macos-app-location.ts b/src/enforce-macos-app-location.ts
new file mode 100644
index 000000000..0f858013d
--- /dev/null
+++ b/src/enforce-macos-app-location.ts
@@ -0,0 +1,46 @@
1// Enhanced from: https://github.com/dertieran/electron-util/blob/replace-remote/source/enforce-macos-app-location.js
2
3import { isMac } from './environment';
4import { isDevMode } from './environment-remote';
5import { api } from './electron-util';
6
7export function enforceMacOSAppLocation() {
8 if (isDevMode || !isMac || api.app.isInApplicationsFolder()) {
9 return;
10 }
11
12 const clickedButtonIndex = api.dialog.showMessageBoxSync({
13 type: 'error',
14 message: 'Move to Applications folder?',
15 detail: 'Ferdi must live in the Applications folder to be able to run correctly.',
16 buttons: [
17 'Move to Applications folder',
18 'Quit Ferdi',
19 ],
20 defaultId: 0,
21 cancelId: 1,
22 });
23
24 if (clickedButtonIndex === 1) {
25 api.app.quit();
26 return;
27 }
28
29 api.app.moveToApplicationsFolder({
30 conflictHandler: conflict => {
31 if (conflict === 'existsAndRunning') { // Can't replace the active version of the app
32 api.dialog.showMessageBoxSync({
33 type: 'error',
34 message: 'Another version of Ferdi is currently running. Quit it, then launch this version of the app again.',
35 buttons: [
36 'OK',
37 ],
38 });
39
40 api.app.quit();
41 }
42
43 return true;
44 },
45 });
46}