diff options
author | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2021-10-02 05:47:36 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-02 05:47:36 +0530 |
commit | 7612949b153ca25b8d36920732dd37defec7a581 (patch) | |
tree | 17cf03fce793afb1a51ffdb778a47e36cc39fd50 /src | |
parent | fix: fix issue with past commit related to 'environment-remote' (diff) | |
download | ferdium-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')
-rw-r--r-- | src/electron-util.ts | 30 | ||||
-rw-r--r-- | src/enforce-macos-app-location.ts | 46 | ||||
-rw-r--r-- | src/environment-remote.ts | 2 | ||||
-rw-r--r-- | src/index.js | 5 |
4 files changed, 80 insertions, 3 deletions
diff --git a/src/electron-util.ts b/src/electron-util.ts new file mode 100644 index 000000000..f4b26cb10 --- /dev/null +++ b/src/electron-util.ts | |||
@@ -0,0 +1,30 @@ | |||
1 | // Enhanced from: https://github.com/dertieran/electron-util/blob/replace-remote/source/api.js | ||
2 | |||
3 | import electron from 'electron'; | ||
4 | import { initialize } from '@electron/remote/main'; | ||
5 | |||
6 | export const initializeRemote = () => { | ||
7 | if (process.type !== 'browser') { | ||
8 | throw new Error('The remote api must be initialized from the main process.'); | ||
9 | } | ||
10 | |||
11 | initialize(); | ||
12 | }; | ||
13 | |||
14 | export const remote = new Proxy({}, { | ||
15 | get: (_target, property) => { | ||
16 | // eslint-disable-next-line global-require | ||
17 | const remote = require('@electron/remote'); | ||
18 | return remote[property]; | ||
19 | }, | ||
20 | }); | ||
21 | |||
22 | export const api = new Proxy(electron, { | ||
23 | get: (target, property) => { | ||
24 | if (target[property]) { | ||
25 | return target[property]; | ||
26 | } | ||
27 | |||
28 | return remote[property]; | ||
29 | }, | ||
30 | }); | ||
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 | } | ||
diff --git a/src/environment-remote.ts b/src/environment-remote.ts index 1ff019c5f..89926a428 100644 --- a/src/environment-remote.ts +++ b/src/environment-remote.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { join } from 'path'; | 1 | import { join } from 'path'; |
2 | import osName from 'os-name'; | 2 | import osName from 'os-name'; |
3 | import { api as electronApi } from 'electron-util'; | 3 | import { api as electronApi } from './electron-util'; |
4 | import { | 4 | import { |
5 | LIVE_FERDI_API, | 5 | LIVE_FERDI_API, |
6 | DEV_FRANZ_API, | 6 | DEV_FRANZ_API, |
diff --git a/src/index.js b/src/index.js index ed37134c9..87f45e7fc 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -5,10 +5,11 @@ import { app, BrowserWindow, ipcMain, session, dialog } from 'electron'; | |||
5 | import { emptyDirSync, ensureFileSync } from 'fs-extra'; | 5 | import { emptyDirSync, ensureFileSync } from 'fs-extra'; |
6 | import { join } from 'path'; | 6 | import { join } from 'path'; |
7 | import windowStateKeeper from 'electron-window-state'; | 7 | import windowStateKeeper from 'electron-window-state'; |
8 | import { enforceMacOSAppLocation } from 'electron-util'; | ||
9 | import ms from 'ms'; | 8 | import ms from 'ms'; |
9 | import { initializeRemote } from './electron-util'; | ||
10 | import { enforceMacOSAppLocation } from './enforce-macos-app-location'; | ||
10 | 11 | ||
11 | require('@electron/remote/main').initialize(); | 12 | initializeRemote(); |
12 | 13 | ||
13 | import { DEFAULT_APP_SETTINGS, DEFAULT_WINDOW_OPTIONS } from './config'; | 14 | import { DEFAULT_APP_SETTINGS, DEFAULT_WINDOW_OPTIONS } from './config'; |
14 | 15 | ||