aboutsummaryrefslogtreecommitdiffstats
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
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)
-rw-r--r--package-lock.json19
-rw-r--r--package.json1
-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
6 files changed, 80 insertions, 23 deletions
diff --git a/package-lock.json b/package-lock.json
index 90b90d423..b6166ff22 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13267,11 +13267,6 @@
13267 "resolved": "https://registry.npmjs.org/electron-find/-/electron-find-1.0.7.tgz", 13267 "resolved": "https://registry.npmjs.org/electron-find/-/electron-find-1.0.7.tgz",
13268 "integrity": "sha512-C2FQJuk8567P2a2loBNwl5c8kwOTQVMB0capgHtPI7zKwZG16X0UxG+sNYZExQfnJ0PA+ecECA/4LcXxQa2TCA==" 13268 "integrity": "sha512-C2FQJuk8567P2a2loBNwl5c8kwOTQVMB0capgHtPI7zKwZG16X0UxG+sNYZExQfnJ0PA+ecECA/4LcXxQa2TCA=="
13269 }, 13269 },
13270 "electron-is-dev": {
13271 "version": "1.2.0",
13272 "resolved": "https://registry.npmjs.org/electron-is-dev/-/electron-is-dev-1.2.0.tgz",
13273 "integrity": "sha512-R1oD5gMBPS7PVU8gJwH6CtT0e6VSoD0+SzSnYpNm+dBkcijgA+K7VAMHDfnRq/lkKPZArpzplTW6jfiMYosdzw=="
13274 },
13275 "electron-notarize": { 13270 "electron-notarize": {
13276 "version": "1.1.0", 13271 "version": "1.1.0",
13277 "resolved": "https://registry.npmjs.org/electron-notarize/-/electron-notarize-1.1.0.tgz", 13272 "resolved": "https://registry.npmjs.org/electron-notarize/-/electron-notarize-1.1.0.tgz",
@@ -13465,15 +13460,6 @@
13465 "semver": "^7.3.5" 13460 "semver": "^7.3.5"
13466 } 13461 }
13467 }, 13462 },
13468 "electron-util": {
13469 "version": "0.17.2",
13470 "resolved": "https://registry.npmjs.org/electron-util/-/electron-util-0.17.2.tgz",
13471 "integrity": "sha512-4Kg/aZxJ2BZklgyfH86px/D2GyROPyIcnAZar+7KiNmKI2I5l09pwQTP7V95zM3FVhgDQwV9iuJta5dyEvuWAw==",
13472 "requires": {
13473 "electron-is-dev": "^1.1.0",
13474 "new-github-issue-url": "^0.2.1"
13475 }
13476 },
13477 "electron-window-state": { 13463 "electron-window-state": {
13478 "version": "5.0.3", 13464 "version": "5.0.3",
13479 "resolved": "https://registry.npmjs.org/electron-window-state/-/electron-window-state-5.0.3.tgz", 13465 "resolved": "https://registry.npmjs.org/electron-window-state/-/electron-window-state-5.0.3.tgz",
@@ -22628,11 +22614,6 @@
22628 "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", 22614 "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==",
22629 "dev": true 22615 "dev": true
22630 }, 22616 },
22631 "new-github-issue-url": {
22632 "version": "0.2.1",
22633 "resolved": "https://registry.npmjs.org/new-github-issue-url/-/new-github-issue-url-0.2.1.tgz",
22634 "integrity": "sha512-md4cGoxuT4T4d/HDOXbrUHkTKrp/vp+m3aOA7XXVYwNsUNMK49g3SQicTSeV5GIz/5QVGAeYRAOlyp9OvlgsYA=="
22635 },
22636 "next-tick": { 22617 "next-tick": {
22637 "version": "1.0.0", 22618 "version": "1.0.0",
22638 "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", 22619 "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz",
diff --git a/package.json b/package.json
index 5484fd173..73cf13310 100644
--- a/package.json
+++ b/package.json
@@ -85,7 +85,6 @@
85 "electron-find": "1.0.7", 85 "electron-find": "1.0.7",
86 "electron-react-titlebar": "0.8.2", 86 "electron-react-titlebar": "0.8.2",
87 "electron-updater": "4.3.9", 87 "electron-updater": "4.3.9",
88 "electron-util": "0.17.2",
89 "electron-window-state": "5.0.3", 88 "electron-window-state": "5.0.3",
90 "fs-extra": "10.0.0", 89 "fs-extra": "10.0.0",
91 "jsonwebtoken": "8.5.1", 90 "jsonwebtoken": "8.5.1",
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