diff options
Diffstat (limited to 'src/enforce-macos-app-location.ts')
-rw-r--r-- | src/enforce-macos-app-location.ts | 46 |
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 | |||
3 | import { isMac } from './environment'; | ||
4 | import { isDevMode } from './environment-remote'; | ||
5 | import { api } from './electron-util'; | ||
6 | |||
7 | export 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 | } | ||