aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Vijay A <avijayr@protonmail.com>2021-07-03 09:43:22 +0530
committerLibravatar Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com>2021-07-04 15:24:59 +0530
commit8fc02b903755bfd209edb1744cc82743aa41ba18 (patch)
treebe2ae18db1aea93de6ceb8c2d00d4cd7a55cd1a1
parentFixed issue with not being able to add new service. (diff)
downloadferdium-app-8fc02b903755bfd209edb1744cc82743aa41ba18.tar.gz
ferdium-app-8fc02b903755bfd209edb1744cc82743aa41ba18.tar.zst
ferdium-app-8fc02b903755bfd209edb1744cc82743aa41ba18.zip
Use utility methods from 'electron-util'
(already a dependency) rather than re-implementing by ourselves.
-rw-r--r--package-lock.json18
-rw-r--r--package.json2
-rw-r--r--src/environment.js60
-rw-r--r--src/helpers/userAgent-helpers.js14
-rw-r--r--src/index.js9
-rw-r--r--src/lib/Menu.js8
-rw-r--r--src/stores/AppStore.js8
7 files changed, 57 insertions, 62 deletions
diff --git a/package-lock.json b/package-lock.json
index 6eae814cb..f6d914dfb 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -15866,6 +15866,11 @@
15866 "resolved": "https://registry.npmjs.org/electron-find/-/electron-find-1.0.6.tgz", 15866 "resolved": "https://registry.npmjs.org/electron-find/-/electron-find-1.0.6.tgz",
15867 "integrity": "sha512-RenjzlCCzX7edLywLy+qRYvzds11sBv8+SrJu/3l3eVLt9d9uNqCPk+uFZ525uAhSUaUalgZWDlhQdxIgT1khg==" 15867 "integrity": "sha512-RenjzlCCzX7edLywLy+qRYvzds11sBv8+SrJu/3l3eVLt9d9uNqCPk+uFZ525uAhSUaUalgZWDlhQdxIgT1khg=="
15868 }, 15868 },
15869 "electron-is-dev": {
15870 "version": "1.2.0",
15871 "resolved": "https://registry.npmjs.org/electron-is-dev/-/electron-is-dev-1.2.0.tgz",
15872 "integrity": "sha512-R1oD5gMBPS7PVU8gJwH6CtT0e6VSoD0+SzSnYpNm+dBkcijgA+K7VAMHDfnRq/lkKPZArpzplTW6jfiMYosdzw=="
15873 },
15869 "electron-notarize": { 15874 "electron-notarize": {
15870 "version": "1.0.0", 15875 "version": "1.0.0",
15871 "resolved": "https://registry.npmjs.org/electron-notarize/-/electron-notarize-1.0.0.tgz", 15876 "resolved": "https://registry.npmjs.org/electron-notarize/-/electron-notarize-1.0.0.tgz",
@@ -16613,19 +16618,12 @@
16613 } 16618 }
16614 }, 16619 },
16615 "electron-util": { 16620 "electron-util": {
16616 "version": "0.16.0", 16621 "version": "0.17.0",
16617 "resolved": "https://registry.npmjs.org/electron-util/-/electron-util-0.16.0.tgz", 16622 "resolved": "https://registry.npmjs.org/electron-util/-/electron-util-0.17.0.tgz",
16618 "integrity": "sha512-r13cauuQ8p8d++ZVdeMDtQ2VlpblJBcpKnK7sf2tGnN8CCWyRGYerS2K5f3FiblFIQkyS0rE4tFVG0IOEc2F3A==", 16623 "integrity": "sha512-61+NEPdIN68EBC9XDPNAKs14HlPdc7HsL6lfQ+QTiya+3BMzayBqUsvN1LrT7IoGpPuuZns+iaCKf1N78dEF+w==",
16619 "requires": { 16624 "requires": {
16620 "electron-is-dev": "^1.1.0", 16625 "electron-is-dev": "^1.1.0",
16621 "new-github-issue-url": "^0.2.1" 16626 "new-github-issue-url": "^0.2.1"
16622 },
16623 "dependencies": {
16624 "electron-is-dev": {
16625 "version": "1.2.0",
16626 "resolved": "https://registry.npmjs.org/electron-is-dev/-/electron-is-dev-1.2.0.tgz",
16627 "integrity": "sha512-R1oD5gMBPS7PVU8gJwH6CtT0e6VSoD0+SzSnYpNm+dBkcijgA+K7VAMHDfnRq/lkKPZArpzplTW6jfiMYosdzw=="
16628 }
16629 } 16627 }
16630 }, 16628 },
16631 "electron-window-state": { 16629 "electron-window-state": {
diff --git a/package.json b/package.json
index a15f44d9c..097ddd383 100644
--- a/package.json
+++ b/package.json
@@ -84,7 +84,7 @@
84 "electron-find": "1.0.6", 84 "electron-find": "1.0.6",
85 "electron-react-titlebar": "0.8.2", 85 "electron-react-titlebar": "0.8.2",
86 "electron-updater": "4.3.9", 86 "electron-updater": "4.3.9",
87 "electron-util": "0.16.0", 87 "electron-util": "0.17.0",
88 "electron-window-state": "5.0.3", 88 "electron-window-state": "5.0.3",
89 "fs-extra": "10.0.0", 89 "fs-extra": "10.0.0",
90 "gulp-csso": "4.0.1", 90 "gulp-csso": "4.0.1",
diff --git a/src/environment.js b/src/environment.js
index 6a55045a7..be6dc7176 100644
--- a/src/environment.js
+++ b/src/environment.js
@@ -1,5 +1,7 @@
1import path from 'path'; 1import path from 'path';
2 2
3import { is, api as electronApi } from 'electron-util';
4
3import { DEFAULT_ACCENT_COLOR } from '@meetfranz/theme'; 5import { DEFAULT_ACCENT_COLOR } from '@meetfranz/theme';
4 6
5import { 7import {
@@ -21,12 +23,16 @@ import {
21} from './config'; 23} from './config';
22 24
23import { asarPath } from './helpers/asar-helpers'; 25import { asarPath } from './helpers/asar-helpers';
26import * as buildInfo from './buildInfo.json'; // eslint-disable-line import/no-unresolved
27
28const osName = require('os-name');
24 29
25// eslint-disable-next-line global-require 30export const { app } = electronApi;
26export const { app } = process.type === 'renderer' ? require('@electron/remote') : require('electron'); 31export const ferdiVersion = app.getVersion();
27const { nativeTheme } = process.type === 'renderer' ? require('@electron/remote') : require('electron'); 32export const electronVersion = process.versions.electron;
33export const chromeVersion = process.versions.chrome;
34export const nodeVersion = process.versions.node;
28 35
29// TODO: This seems to be duplicated between here and 'index.js'
30// Set app directory before loading user modules 36// Set app directory before loading user modules
31if (process.env.FERDI_APPDATA_DIR != null) { 37if (process.env.FERDI_APPDATA_DIR != null) {
32 app.setPath('appData', process.env.FERDI_APPDATA_DIR); 38 app.setPath('appData', process.env.FERDI_APPDATA_DIR);
@@ -34,27 +40,12 @@ if (process.env.FERDI_APPDATA_DIR != null) {
34} else if (process.env.PORTABLE_EXECUTABLE_DIR != null) { 40} else if (process.env.PORTABLE_EXECUTABLE_DIR != null) {
35 app.setPath('appData', process.env.PORTABLE_EXECUTABLE_DIR, `${app.name}AppData`); 41 app.setPath('appData', process.env.PORTABLE_EXECUTABLE_DIR, `${app.name}AppData`);
36 app.setPath('userData', path.join(app.getPath('appData'), `${app.name}AppData`)); 42 app.setPath('userData', path.join(app.getPath('appData'), `${app.name}AppData`));
37} else if (process.platform === 'win32') { 43} else if (is.windows) {
38 app.setPath('appData', process.env.APPDATA); 44 app.setPath('appData', process.env.APPDATA);
39 app.setPath('userData', path.join(app.getPath('appData'), app.name)); 45 app.setPath('userData', path.join(app.getPath('appData'), app.name));
40} 46}
41 47
42const ELECTRON_IS_DEV_VAR = 'ELECTRON_IS_DEV'; 48export const isDevMode = is.development;
43const NODE_ENV_VAR = 'NODE_ENV';
44
45export const isDevMode = (() => {
46 const isEnvVarSet = name => name in process.env;
47 if (isEnvVarSet(ELECTRON_IS_DEV_VAR)) {
48 // Copied from https://github.com/sindresorhus/electron-is-dev/blob/f05330b856782dac7987b10859bfd95ea6a187a6/index.js
49 // but electron-is-dev breaks in a renderer process, so we use the app import from above instead.
50 const electronIsDev = process.env[ELECTRON_IS_DEV_VAR];
51 return electronIsDev === 'true' || Number.parseInt(electronIsDev, 10) === 1;
52 }
53 if (isEnvVarSet(NODE_ENV_VAR)) {
54 return process.env[NODE_ENV_VAR] === 'development';
55 }
56 return !app.isPackaged;
57})();
58if (isDevMode) { 49if (isDevMode) {
59 app.setPath('userData', path.join(app.getPath('appData'), `${app.name}Dev`)); 50 app.setPath('userData', path.join(app.getPath('appData'), `${app.name}Dev`));
60} 51}
@@ -66,14 +57,9 @@ export const RECIPES_PATH = asarPath(path.join(__dirname, 'recipes'));
66 57
67export const useLiveAPI = process.env.LIVE_API; 58export const useLiveAPI = process.env.LIVE_API;
68 59
69let { platform } = process; 60export const isMac = is.macos;
70if (process.env.OS_PLATFORM) { 61export const isWindows = is.windows;
71 platform = process.env.OS_PLATFORM; 62export const isLinux = is.linux;
72}
73
74export const isMac = platform === 'darwin';
75export const isWindows = platform === 'win32';
76export const isLinux = platform === 'linux';
77 63
78export const ctrlKey = isMac ? '⌘' : 'Ctrl'; 64export const ctrlKey = isMac ? '⌘' : 'Ctrl';
79export const cmdKey = isMac ? 'Cmd' : 'Ctrl'; 65export const cmdKey = isMac ? 'Cmd' : 'Ctrl';
@@ -123,7 +109,7 @@ export const DEFAULT_APP_SETTINGS = {
123 showDragArea: false, 109 showDragArea: false,
124 enableSpellchecking: true, 110 enableSpellchecking: true,
125 spellcheckerLanguage: 'en-us', 111 spellcheckerLanguage: 'en-us',
126 darkMode: isMac ? nativeTheme.shouldUseDarkColors : false, 112 darkMode: isMac && electronApi.nativeTheme.shouldUseDarkColors,
127 locale: '', 113 locale: '',
128 fallbackLocale: 'en-US', 114 fallbackLocale: 'en-US',
129 beta: false, 115 beta: false,
@@ -165,3 +151,17 @@ export const DEFAULT_APP_SETTINGS = {
165export function termsBase() { 151export function termsBase() {
166 return window.ferdi.stores.settings.all.app.server !== LIVE_FRANZ_API ? window.ferdi.stores.settings.all.app.server : DEV_API_FRANZ_WEBSITE; 152 return window.ferdi.stores.settings.all.app.server !== LIVE_FRANZ_API ? window.ferdi.stores.settings.all.app.server : DEV_API_FRANZ_WEBSITE;
167} 153}
154
155export function aboutAppDetails() {
156 return [
157 `Version: ${ferdiVersion}`,
158 `Electron: ${electronVersion}`,
159 `Chrome: ${chromeVersion}`,
160 `Node.js: ${nodeVersion}`,
161 `Platform: ${osName()}`,
162 `Arch: ${process.arch}`,
163 `Build date: ${new Date(Number(buildInfo.timestamp))}`,
164 `Git SHA: ${buildInfo.gitHashShort}`,
165 `Git branch: ${buildInfo.gitBranch}`,
166 ].join('\n');
167}
diff --git a/src/helpers/userAgent-helpers.js b/src/helpers/userAgent-helpers.js
index 73c454304..fc9a6f507 100644
--- a/src/helpers/userAgent-helpers.js
+++ b/src/helpers/userAgent-helpers.js
@@ -1,8 +1,8 @@
1import os from 'os'; 1import os from 'os';
2import macosVersion from 'macos-version'; 2import macosVersion from 'macos-version';
3import { app, isMac, isWindows } from '../environment'; 3import {
4 4 ferdiVersion, electronVersion, chromeVersion, isMac, isWindows,
5export const ferdiVersion = app.getVersion(); 5} from '../environment';
6 6
7function macOS() { 7function macOS() {
8 const version = macosVersion(); 8 const version = macosVersion();
@@ -34,17 +34,17 @@ export default function userAgent(removeChromeVersion = false, addFerdiVersion =
34 platformString = linux(); 34 platformString = linux();
35 } 35 }
36 36
37 let chromeVersion = 'Chrome'; 37 let chromeVersionString = 'Chrome';
38 if (!removeChromeVersion) { 38 if (!removeChromeVersion) {
39 chromeVersion = `Chrome/${process.versions.chrome}`; 39 chromeVersionString = `Chrome/${chromeVersion}`;
40 } 40 }
41 41
42 let applicationString = ''; 42 let applicationString = '';
43 if (addFerdiVersion) { 43 if (addFerdiVersion) {
44 applicationString = ` Ferdi/${ferdiVersion} Electron/${process.versions.electron}`; 44 applicationString = ` Ferdi/${ferdiVersion} Electron/${electronVersion}`;
45 } 45 }
46 46
47 // Chrome is pinned to WebKit 537.36, the latest version before hard forking to Blink. 47 // Chrome is pinned to WebKit 537.36, the latest version before hard forking to Blink.
48 return `Mozilla/5.0 (${platformString}) AppleWebKit/537.36 (KHTML, like Gecko) ${chromeVersion} Safari/537.36${applicationString}`; 48 return `Mozilla/5.0 (${platformString}) AppleWebKit/537.36 (KHTML, like Gecko) ${chromeVersionString} Safari/537.36${applicationString}`;
49 // Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36 Ferdi/5.5.1-nightly.13 Electron/8.2.3 49 // Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36 Ferdi/5.5.1-nightly.13 Electron/8.2.3
50} 50}
diff --git a/src/index.js b/src/index.js
index d3b996540..8a4283f49 100644
--- a/src/index.js
+++ b/src/index.js
@@ -24,6 +24,7 @@ import {
24 isMac, 24 isMac,
25 isWindows, 25 isWindows,
26 isLinux, 26 isLinux,
27 aboutAppDetails,
27} from './environment'; 28} from './environment';
28 29
29import { mainIpcHandler as basicAuthHandler } from './features/basicAuth'; 30import { mainIpcHandler as basicAuthHandler } from './features/basicAuth';
@@ -34,14 +35,12 @@ import Settings from './electron/Settings';
34import handleDeepLink from './electron/deepLinking'; 35import handleDeepLink from './electron/deepLinking';
35import { isPositionValid } from './electron/windowUtils'; 36import { isPositionValid } from './electron/windowUtils';
36import { appId } from './package.json'; // eslint-disable-line import/no-unresolved 37import { appId } from './package.json'; // eslint-disable-line import/no-unresolved
37import * as buildInfo from './buildInfo.json'; // eslint-disable-line import/no-unresolved
38import './electron/exception'; 38import './electron/exception';
39 39
40import { asarPath } from './helpers/asar-helpers'; 40import { asarPath } from './helpers/asar-helpers';
41import { isValidExternalURL } from './helpers/url-helpers'; 41import { isValidExternalURL } from './helpers/url-helpers';
42import userAgent, { ferdiVersion } from './helpers/userAgent-helpers'; 42import userAgent from './helpers/userAgent-helpers';
43 43
44const osName = require('os-name');
45const debug = require('debug')('Ferdi:App'); 44const debug = require('debug')('Ferdi:App');
46 45
47// From Electron 9 onwards, app.allowRendererProcessReuse = true by default. This causes the app to crash on Windows due to the 46// From Electron 9 onwards, app.allowRendererProcessReuse = true by default. This causes the app to crash on Windows due to the
@@ -147,7 +146,7 @@ if (!settings.get('enableGPUAcceleration')) {
147} 146}
148 147
149app.setAboutPanelOptions({ 148app.setAboutPanelOptions({
150 applicationVersion: `Version: ${ferdiVersion}\nElectron: ${process.versions.electron}\nChrome: ${process.versions.chrome}\nNode.js: ${process.versions.node}\nPlatform: ${osName()}\nArch: ${process.arch}\nBuild date: ${new Date(Number(buildInfo.timestamp))}\nGit SHA: ${buildInfo.gitHashShort}\nGit branch: ${buildInfo.gitBranch}`, 149 applicationVersion: aboutAppDetails(),
151 version: '', 150 version: '',
152}); 151});
153 152
@@ -156,7 +155,7 @@ const createWindow = () => {
156 const mainWindowState = windowStateKeeper({ 155 const mainWindowState = windowStateKeeper({
157 defaultWidth: DEFAULT_WINDOW_OPTIONS.width, 156 defaultWidth: DEFAULT_WINDOW_OPTIONS.width,
158 defaultHeight: DEFAULT_WINDOW_OPTIONS.height, 157 defaultHeight: DEFAULT_WINDOW_OPTIONS.height,
159 maximize: true, // Automatically maximizes the window, if it was last clsoed maximized 158 maximize: true, // Automatically maximizes the window, if it was last closed maximized
160 fullScreen: true, // Automatically restores the window to full screen, if it was last closed full screen 159 fullScreen: true, // Automatically restores the window to full screen, if it was last closed full screen
161 }); 160 });
162 161
diff --git a/src/lib/Menu.js b/src/lib/Menu.js
index d66fa009f..c60536f0c 100644
--- a/src/lib/Menu.js
+++ b/src/lib/Menu.js
@@ -6,7 +6,7 @@ import { autorun, observable } from 'mobx';
6import { defineMessages } from 'react-intl'; 6import { defineMessages } from 'react-intl';
7import { CUSTOM_WEBSITE_RECIPE_ID, GITHUB_FERDI_URL, LIVE_API_FERDI_WEBSITE } from '../config'; 7import { CUSTOM_WEBSITE_RECIPE_ID, GITHUB_FERDI_URL, LIVE_API_FERDI_WEBSITE } from '../config';
8import { 8import {
9 cmdKey, ctrlKey, isLinux, isMac, termsBase, 9 cmdKey, ctrlKey, isLinux, isMac, aboutAppDetails, termsBase,
10} from '../environment'; 10} from '../environment';
11import { announcementsStore } from '../features/announcements'; 11import { announcementsStore } from '../features/announcements';
12import { announcementActions } from '../features/announcements/actions'; 12import { announcementActions } from '../features/announcements/actions';
@@ -14,10 +14,6 @@ import { todosStore } from '../features/todos';
14import { todoActions } from '../features/todos/actions'; 14import { todoActions } from '../features/todos/actions';
15import { workspaceActions } from '../features/workspaces/actions'; 15import { workspaceActions } from '../features/workspaces/actions';
16import { workspaceStore } from '../features/workspaces/index'; 16import { workspaceStore } from '../features/workspaces/index';
17import * as buildInfo from '../buildInfo.json'; // eslint-disable-line import/no-unresolved
18import { ferdiVersion } from '../helpers/userAgent-helpers';
19
20const osName = require('os-name');
21 17
22const menuItems = defineMessages({ 18const menuItems = defineMessages({
23 edit: { 19 edit: {
@@ -1025,7 +1021,7 @@ export default class FranzMenu {
1025 type: 'info', 1021 type: 'info',
1026 title: 'Franz Ferdinand', 1022 title: 'Franz Ferdinand',
1027 message: 'Ferdi', 1023 message: 'Ferdi',
1028 detail: `Version: ${ferdiVersion}\nElectron: ${process.versions.electron}\nChrome: ${process.versions.chrome}\nNode.js: ${process.versions.node}\nPlatform: ${osName()}\nArch: ${process.arch}\nBuild date: ${new Date(Number(buildInfo.timestamp))}\nGit SHA: ${buildInfo.gitHashShort}\nGit branch: ${buildInfo.gitBranch}`, 1024 detail: aboutAppDetails(),
1029 }); 1025 });
1030 }, 1026 },
1031 }; 1027 };
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index 3116677c2..bbcf78a43 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -14,7 +14,9 @@ import { readJsonSync } from 'fs-extra';
14import Store from './lib/Store'; 14import Store from './lib/Store';
15import Request from './lib/Request'; 15import Request from './lib/Request';
16import { CHECK_INTERVAL } from '../config'; 16import { CHECK_INTERVAL } from '../config';
17import { DEFAULT_APP_SETTINGS, isMac } from '../environment'; 17import {
18 DEFAULT_APP_SETTINGS, isMac, ferdiVersion, electronVersion,
19} from '../environment';
18import locales from '../i18n/translations'; 20import locales from '../i18n/translations';
19import { onVisibilityChange } from '../helpers/visibility-helper'; 21import { onVisibilityChange } from '../helpers/visibility-helper';
20import { getLocale } from '../helpers/i18n-helpers'; 22import { getLocale } from '../helpers/i18n-helpers';
@@ -263,8 +265,8 @@ export default class AppStore extends Store {
263 screens: screen.getAllDisplays(), 265 screens: screen.getAllDisplays(),
264 }, 266 },
265 ferdi: { 267 ferdi: {
266 version: app.getVersion(), 268 version: ferdiVersion,
267 electron: process.versions.electron, 269 electron: electronVersion,
268 installedRecipes: this.stores.recipes.all.map(recipe => ({ 270 installedRecipes: this.stores.recipes.all.map(recipe => ({
269 id: recipe.id, 271 id: recipe.id,
270 version: recipe.version, 272 version: recipe.version,