diff options
Diffstat (limited to 'src/environment.js')
-rw-r--r-- | src/environment.js | 108 |
1 files changed, 103 insertions, 5 deletions
diff --git a/src/environment.js b/src/environment.js index 18d686232..6a55045a7 100644 --- a/src/environment.js +++ b/src/environment.js | |||
@@ -1,5 +1,8 @@ | |||
1 | import path from 'path'; | ||
2 | |||
3 | import { DEFAULT_ACCENT_COLOR } from '@meetfranz/theme'; | ||
4 | |||
1 | import { | 5 | import { |
2 | isDevMode as isDev, | ||
3 | LIVE_FERDI_API, | 6 | LIVE_FERDI_API, |
4 | DEV_FRANZ_API, | 7 | DEV_FRANZ_API, |
5 | LOCAL_API, | 8 | LOCAL_API, |
@@ -12,16 +15,56 @@ import { | |||
12 | LOCAL_TODOS_FRONTEND_URL, | 15 | LOCAL_TODOS_FRONTEND_URL, |
13 | PRODUCTION_TODOS_FRONTEND_URL, | 16 | PRODUCTION_TODOS_FRONTEND_URL, |
14 | LIVE_FRANZ_API, | 17 | LIVE_FRANZ_API, |
18 | DEFAULT_TODO_SERVICE, | ||
19 | SEARCH_ENGINE_DDG, | ||
20 | iconSizeBias, | ||
15 | } from './config'; | 21 | } from './config'; |
16 | 22 | ||
23 | import { asarPath } from './helpers/asar-helpers'; | ||
24 | |||
17 | // eslint-disable-next-line global-require | 25 | // eslint-disable-next-line global-require |
18 | export const { app } = process.type === 'renderer' ? require('@electron/remote') : require('electron'); | 26 | export const { app } = process.type === 'renderer' ? require('@electron/remote') : require('electron'); |
27 | const { nativeTheme } = process.type === 'renderer' ? require('@electron/remote') : require('electron'); | ||
19 | 28 | ||
20 | // TODO Remove this re-export and move the code from config.js to here. | 29 | // TODO: This seems to be duplicated between here and 'index.js' |
21 | export const isDevMode = isDev; | 30 | // Set app directory before loading user modules |
31 | if (process.env.FERDI_APPDATA_DIR != null) { | ||
32 | app.setPath('appData', process.env.FERDI_APPDATA_DIR); | ||
33 | app.setPath('userData', path.join(app.getPath('appData'))); | ||
34 | } else if (process.env.PORTABLE_EXECUTABLE_DIR != null) { | ||
35 | app.setPath('appData', process.env.PORTABLE_EXECUTABLE_DIR, `${app.name}AppData`); | ||
36 | app.setPath('userData', path.join(app.getPath('appData'), `${app.name}AppData`)); | ||
37 | } else if (process.platform === 'win32') { | ||
38 | app.setPath('appData', process.env.APPDATA); | ||
39 | app.setPath('userData', path.join(app.getPath('appData'), app.name)); | ||
40 | } | ||
41 | |||
42 | const ELECTRON_IS_DEV_VAR = 'ELECTRON_IS_DEV'; | ||
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) { | ||
59 | app.setPath('userData', path.join(app.getPath('appData'), `${app.name}Dev`)); | ||
60 | } | ||
61 | |||
62 | export const SETTINGS_PATH = path.join(app.getPath('userData'), 'config'); | ||
63 | |||
64 | // Replacing app.asar is not beautiful but unfortunately necessary | ||
65 | export const RECIPES_PATH = asarPath(path.join(__dirname, 'recipes')); | ||
22 | 66 | ||
23 | export const useLiveAPI = process.env.LIVE_API; | 67 | export const useLiveAPI = process.env.LIVE_API; |
24 | export const useLocalAPI = process.env.LOCAL_API; | ||
25 | 68 | ||
26 | let { platform } = process; | 69 | let { platform } = process; |
27 | if (process.env.OS_PLATFORM) { | 70 | if (process.env.OS_PLATFORM) { |
@@ -46,7 +89,7 @@ if (!isDevMode || (isDevMode && useLiveAPI)) { | |||
46 | web = LIVE_API_FERDI_WEBSITE; | 89 | web = LIVE_API_FERDI_WEBSITE; |
47 | // web = DEV_API_FRANZ_WEBSITE; | 90 | // web = DEV_API_FRANZ_WEBSITE; |
48 | todos = PRODUCTION_TODOS_FRONTEND_URL; | 91 | todos = PRODUCTION_TODOS_FRONTEND_URL; |
49 | } else if (isDevMode && useLocalAPI) { | 92 | } else if (isDevMode && process.env.LOCAL_API) { |
50 | api = LOCAL_API; | 93 | api = LOCAL_API; |
51 | wsApi = LOCAL_WS_API; | 94 | wsApi = LOCAL_WS_API; |
52 | web = LOCAL_API_WEBSITE; | 95 | web = LOCAL_API_WEBSITE; |
@@ -64,6 +107,61 @@ export const WS_API = wsApi; | |||
64 | export const WEBSITE = web; | 107 | export const WEBSITE = web; |
65 | export const TODOS_FRONTEND = todos; | 108 | export const TODOS_FRONTEND = todos; |
66 | 109 | ||
110 | export const DEFAULT_APP_SETTINGS = { | ||
111 | autoLaunchInBackground: false, | ||
112 | runInBackground: true, | ||
113 | reloadAfterResume: true, | ||
114 | enableSystemTray: true, | ||
115 | startMinimized: false, | ||
116 | minimizeToSystemTray: false, | ||
117 | closeToSystemTray: false, | ||
118 | privateNotifications: false, | ||
119 | clipboardNotifications: true, | ||
120 | notifyTaskBarOnMessage: false, | ||
121 | showDisabledServices: true, | ||
122 | showMessageBadgeWhenMuted: true, | ||
123 | showDragArea: false, | ||
124 | enableSpellchecking: true, | ||
125 | spellcheckerLanguage: 'en-us', | ||
126 | darkMode: isMac ? nativeTheme.shouldUseDarkColors : false, | ||
127 | locale: '', | ||
128 | fallbackLocale: 'en-US', | ||
129 | beta: false, | ||
130 | isAppMuted: false, | ||
131 | enableGPUAcceleration: true, | ||
132 | serviceLimit: 5, | ||
133 | |||
134 | // Ferdi specific options | ||
135 | server: LIVE_FERDI_API, | ||
136 | predefinedTodoServer: DEFAULT_TODO_SERVICE, | ||
137 | autohideMenuBar: false, | ||
138 | lockingFeatureEnabled: false, | ||
139 | locked: false, | ||
140 | lockedPassword: '', | ||
141 | useTouchIdToUnlock: true, | ||
142 | scheduledDNDEnabled: false, | ||
143 | scheduledDNDStart: '17:00', | ||
144 | scheduledDNDEnd: '09:00', | ||
145 | hibernate: false, | ||
146 | hibernateOnStartup: true, | ||
147 | hibernationStrategy: 300, | ||
148 | inactivityLock: 0, | ||
149 | automaticUpdates: true, | ||
150 | showServiceNavigationBar: false, | ||
151 | universalDarkMode: true, | ||
152 | userAgentPref: '', | ||
153 | adaptableDarkMode: true, | ||
154 | accentColor: DEFAULT_ACCENT_COLOR, | ||
155 | serviceRibbonWidth: 68, | ||
156 | iconSize: iconSizeBias, | ||
157 | sentry: false, | ||
158 | nightly: false, | ||
159 | navigationBarBehaviour: 'custom', | ||
160 | searchEngine: SEARCH_ENGINE_DDG, | ||
161 | useVerticalStyle: false, | ||
162 | alwaysShowWorkspaces: false, | ||
163 | }; | ||
164 | |||
67 | export function termsBase() { | 165 | export function termsBase() { |
68 | return window.ferdi.stores.settings.all.app.server !== LIVE_FRANZ_API ? window.ferdi.stores.settings.all.app.server : DEV_API_FRANZ_WEBSITE; | 166 | return window.ferdi.stores.settings.all.app.server !== LIVE_FRANZ_API ? window.ferdi.stores.settings.all.app.server : DEV_API_FRANZ_WEBSITE; |
69 | } | 167 | } |