diff options
author | Vijay A <avijayr@protonmail.com> | 2021-07-03 09:43:22 +0530 |
---|---|---|
committer | Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com> | 2021-07-04 15:24:59 +0530 |
commit | 8fc02b903755bfd209edb1744cc82743aa41ba18 (patch) | |
tree | be2ae18db1aea93de6ceb8c2d00d4cd7a55cd1a1 /src/environment.js | |
parent | Fixed issue with not being able to add new service. (diff) | |
download | ferdium-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.
Diffstat (limited to 'src/environment.js')
-rw-r--r-- | src/environment.js | 60 |
1 files changed, 30 insertions, 30 deletions
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 @@ | |||
1 | import path from 'path'; | 1 | import path from 'path'; |
2 | 2 | ||
3 | import { is, api as electronApi } from 'electron-util'; | ||
4 | |||
3 | import { DEFAULT_ACCENT_COLOR } from '@meetfranz/theme'; | 5 | import { DEFAULT_ACCENT_COLOR } from '@meetfranz/theme'; |
4 | 6 | ||
5 | import { | 7 | import { |
@@ -21,12 +23,16 @@ import { | |||
21 | } from './config'; | 23 | } from './config'; |
22 | 24 | ||
23 | import { asarPath } from './helpers/asar-helpers'; | 25 | import { asarPath } from './helpers/asar-helpers'; |
26 | import * as buildInfo from './buildInfo.json'; // eslint-disable-line import/no-unresolved | ||
27 | |||
28 | const osName = require('os-name'); | ||
24 | 29 | ||
25 | // eslint-disable-next-line global-require | 30 | export const { app } = electronApi; |
26 | export const { app } = process.type === 'renderer' ? require('@electron/remote') : require('electron'); | 31 | export const ferdiVersion = app.getVersion(); |
27 | const { nativeTheme } = process.type === 'renderer' ? require('@electron/remote') : require('electron'); | 32 | export const electronVersion = process.versions.electron; |
33 | export const chromeVersion = process.versions.chrome; | ||
34 | export 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 |
31 | if (process.env.FERDI_APPDATA_DIR != null) { | 37 | if (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 | ||
42 | const ELECTRON_IS_DEV_VAR = 'ELECTRON_IS_DEV'; | 48 | export const isDevMode = is.development; |
43 | const NODE_ENV_VAR = 'NODE_ENV'; | ||
44 | |||
45 | export 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 | })(); | ||
58 | if (isDevMode) { | 49 | if (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 | ||
67 | export const useLiveAPI = process.env.LIVE_API; | 58 | export const useLiveAPI = process.env.LIVE_API; |
68 | 59 | ||
69 | let { platform } = process; | 60 | export const isMac = is.macos; |
70 | if (process.env.OS_PLATFORM) { | 61 | export const isWindows = is.windows; |
71 | platform = process.env.OS_PLATFORM; | 62 | export const isLinux = is.linux; |
72 | } | ||
73 | |||
74 | export const isMac = platform === 'darwin'; | ||
75 | export const isWindows = platform === 'win32'; | ||
76 | export const isLinux = platform === 'linux'; | ||
77 | 63 | ||
78 | export const ctrlKey = isMac ? '⌘' : 'Ctrl'; | 64 | export const ctrlKey = isMac ? '⌘' : 'Ctrl'; |
79 | export const cmdKey = isMac ? 'Cmd' : 'Ctrl'; | 65 | export 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 = { | |||
165 | export function termsBase() { | 151 | export 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 | |||
155 | export 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 | } | ||