aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/electron-util.ts30
-rw-r--r--src/enforce-macos-app-location.ts46
-rw-r--r--src/environment-remote.ts2
-rw-r--r--src/index.js5
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
3import electron from 'electron';
4import { initialize } from '@electron/remote/main';
5
6export 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
14export 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
22export 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
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}
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 @@
1import { join } from 'path'; 1import { join } from 'path';
2import osName from 'os-name'; 2import osName from 'os-name';
3import { api as electronApi } from 'electron-util'; 3import { api as electronApi } from './electron-util';
4import { 4import {
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';
5import { emptyDirSync, ensureFileSync } from 'fs-extra'; 5import { emptyDirSync, ensureFileSync } from 'fs-extra';
6import { join } from 'path'; 6import { join } from 'path';
7import windowStateKeeper from 'electron-window-state'; 7import windowStateKeeper from 'electron-window-state';
8import { enforceMacOSAppLocation } from 'electron-util';
9import ms from 'ms'; 8import ms from 'ms';
9import { initializeRemote } from './electron-util';
10import { enforceMacOSAppLocation } from './enforce-macos-app-location';
10 11
11require('@electron/remote/main').initialize(); 12initializeRemote();
12 13
13import { DEFAULT_APP_SETTINGS, DEFAULT_WINDOW_OPTIONS } from './config'; 14import { DEFAULT_APP_SETTINGS, DEFAULT_WINDOW_OPTIONS } from './config';
14 15