diff options
author | 2021-09-18 11:15:25 +0200 | |
---|---|---|
committer | 2021-09-18 11:15:25 +0200 | |
commit | d4101a48b3eee8b1fb177831aa02a4b4fbec2588 (patch) | |
tree | c92f2fbe91197fde8589207463d0d6526b4ff76b /src/environment.js | |
parent | 5.6.3-nightly.6 [skip ci] (diff) | |
download | ferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.tar.gz ferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.tar.zst ferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.zip |
chore: convert various files from JS to TS (#1959)
Diffstat (limited to 'src/environment.js')
-rw-r--r-- | src/environment.js | 190 |
1 files changed, 0 insertions, 190 deletions
diff --git a/src/environment.js b/src/environment.js deleted file mode 100644 index b315466fc..000000000 --- a/src/environment.js +++ /dev/null | |||
@@ -1,190 +0,0 @@ | |||
1 | import os from 'os'; | ||
2 | import { join } from 'path'; | ||
3 | |||
4 | import { is, api as electronApi } from 'electron-util'; | ||
5 | |||
6 | import { DEFAULT_ACCENT_COLOR } from '@meetfranz/theme'; | ||
7 | |||
8 | import osName from 'os-name'; | ||
9 | import { | ||
10 | LIVE_FERDI_API, | ||
11 | DEV_FRANZ_API, | ||
12 | LOCAL_API, | ||
13 | LOCAL_API_WEBSITE, | ||
14 | DEV_API_FRANZ_WEBSITE, | ||
15 | LIVE_API_FERDI_WEBSITE, | ||
16 | LIVE_WS_API, | ||
17 | LOCAL_WS_API, | ||
18 | DEV_WS_API, | ||
19 | LOCAL_TODOS_FRONTEND_URL, | ||
20 | PRODUCTION_TODOS_FRONTEND_URL, | ||
21 | DEFAULT_TODO_SERVICE, | ||
22 | SEARCH_ENGINE_DDG, | ||
23 | iconSizeBias, | ||
24 | } from './config'; | ||
25 | |||
26 | import { asarPath } from './helpers/asar-helpers'; | ||
27 | import * as buildInfo from './buildInfo.json'; // eslint-disable-line import/no-unresolved | ||
28 | |||
29 | export const { app } = electronApi; | ||
30 | export const ferdiVersion = app.getVersion(); | ||
31 | export const electronVersion = process.versions.electron; | ||
32 | export const chromeVersion = process.versions.chrome; | ||
33 | export const nodeVersion = process.versions.node; | ||
34 | export const ferdiLocale = app.getLocale(); | ||
35 | |||
36 | // Set app directory before loading user modules | ||
37 | if (process.env.FERDI_APPDATA_DIR != null) { | ||
38 | app.setPath('appData', process.env.FERDI_APPDATA_DIR); | ||
39 | app.setPath('userData', join(app.getPath('appData'))); | ||
40 | } else if (process.env.PORTABLE_EXECUTABLE_DIR != null) { | ||
41 | app.setPath('appData', process.env.PORTABLE_EXECUTABLE_DIR, `${app.name}AppData`); | ||
42 | app.setPath('userData', join(app.getPath('appData'), `${app.name}AppData`)); | ||
43 | } else if (is.windows) { | ||
44 | app.setPath('appData', process.env.APPDATA); | ||
45 | app.setPath('userData', join(app.getPath('appData'), app.name)); | ||
46 | } | ||
47 | |||
48 | export const isDevMode = is.development; | ||
49 | if (isDevMode) { | ||
50 | app.setPath('userData', join(app.getPath('appData'), `${app.name}Dev`)); | ||
51 | } | ||
52 | |||
53 | export function userDataPath(...segments) { | ||
54 | return join(app.getPath('userData'), ...([segments].flat())); | ||
55 | } | ||
56 | |||
57 | export function userDataRecipesPath(...segments) { | ||
58 | return userDataPath('recipes', ...([segments].flat())); | ||
59 | } | ||
60 | |||
61 | // Replacing app.asar is not beautiful but unfortunately necessary | ||
62 | export function asarRecipesPath(...segments) { | ||
63 | return join(asarPath(join(__dirname, 'recipes')), ...([segments].flat())); | ||
64 | } | ||
65 | |||
66 | export const useLiveAPI = process.env.USE_LIVE_API; | ||
67 | const useLocalAPI = process.env.USE_LOCAL_API; | ||
68 | |||
69 | export const isMac = is.macos; | ||
70 | export const isWindows = is.windows; | ||
71 | export const isLinux = is.linux; | ||
72 | export const osPlatform = os.platform(); | ||
73 | export const osArch = os.arch(); | ||
74 | export const osRelease = os.release(); | ||
75 | export const is64Bit = osArch.match(/64/); | ||
76 | |||
77 | // for accelerator, show the shortform that electron/OS understands | ||
78 | // for tooltip, show symbol | ||
79 | const ctrlKey = isMac ? '⌘' : 'Ctrl'; | ||
80 | const cmdKey = isMac ? 'Cmd' : 'Ctrl'; | ||
81 | |||
82 | export const altKey = (isAccelerator = true) => (!isAccelerator && isMac ? '⌥' : 'Alt'); | ||
83 | export const shiftKey = (isAccelerator = true) => (!isAccelerator && isMac ? '⇧' : 'Shift'); | ||
84 | |||
85 | // Platform specific shortcut keys | ||
86 | export const cmdOrCtrlShortcutKey = (isAccelerator = true) => (isAccelerator ? cmdKey : ctrlKey); | ||
87 | export const lockFerdiShortcutKey = (isAccelerator = true) => `${cmdOrCtrlShortcutKey(isAccelerator)}+${shiftKey(isAccelerator)}+L`; | ||
88 | export const todosToggleShortcutKey = (isAccelerator = true) => `${cmdOrCtrlShortcutKey(isAccelerator)}+T`; | ||
89 | export const workspaceToggleShortcutKey = (isAccelerator = true) => `${cmdOrCtrlShortcutKey(isAccelerator)}+D`; | ||
90 | export const muteFerdiShortcutKey = (isAccelerator = true) => `${cmdOrCtrlShortcutKey(isAccelerator)}+${shiftKey(isAccelerator)}+M`; | ||
91 | export const addNewServiceShortcutKey = (isAccelerator = true) => `${cmdOrCtrlShortcutKey(isAccelerator)}+N`; | ||
92 | export const settingsShortcutKey = (isAccelerator = true) => `${cmdOrCtrlShortcutKey(isAccelerator)}+${isMac ? ',' : 'P'}`; | ||
93 | |||
94 | let api; | ||
95 | let wsApi; | ||
96 | let web; | ||
97 | let todos; | ||
98 | if (!isDevMode || (isDevMode && useLiveAPI)) { | ||
99 | api = LIVE_FERDI_API; | ||
100 | wsApi = LIVE_WS_API; | ||
101 | web = LIVE_API_FERDI_WEBSITE; | ||
102 | todos = PRODUCTION_TODOS_FRONTEND_URL; | ||
103 | } else if (isDevMode && useLocalAPI) { | ||
104 | api = LOCAL_API; | ||
105 | wsApi = LOCAL_WS_API; | ||
106 | web = LOCAL_API_WEBSITE; | ||
107 | todos = LOCAL_TODOS_FRONTEND_URL; | ||
108 | } else { | ||
109 | api = DEV_FRANZ_API; | ||
110 | wsApi = DEV_WS_API; | ||
111 | web = DEV_API_FRANZ_WEBSITE; | ||
112 | todos = PRODUCTION_TODOS_FRONTEND_URL; | ||
113 | } | ||
114 | |||
115 | export const API = api; | ||
116 | export const API_VERSION = 'v1'; | ||
117 | export const WS_API = wsApi; | ||
118 | export const WEBSITE = web; | ||
119 | export const TODOS_FRONTEND = todos; | ||
120 | |||
121 | export const DEFAULT_APP_SETTINGS = { | ||
122 | autoLaunchInBackground: false, | ||
123 | runInBackground: true, | ||
124 | reloadAfterResume: true, | ||
125 | enableSystemTray: true, | ||
126 | startMinimized: false, | ||
127 | confirmOnQuit: false, | ||
128 | minimizeToSystemTray: false, | ||
129 | closeToSystemTray: false, | ||
130 | privateNotifications: false, | ||
131 | clipboardNotifications: true, | ||
132 | notifyTaskBarOnMessage: false, | ||
133 | showDisabledServices: true, | ||
134 | showMessageBadgeWhenMuted: true, | ||
135 | showDragArea: false, | ||
136 | enableSpellchecking: true, | ||
137 | spellcheckerLanguage: 'en-us', | ||
138 | darkMode: isMac && electronApi.nativeTheme.shouldUseDarkColors, | ||
139 | splitMode: false, | ||
140 | locale: '', | ||
141 | fallbackLocale: 'en-US', | ||
142 | beta: false, | ||
143 | isAppMuted: false, | ||
144 | enableGPUAcceleration: true, | ||
145 | |||
146 | // Ferdi specific options | ||
147 | server: LIVE_FERDI_API, | ||
148 | predefinedTodoServer: DEFAULT_TODO_SERVICE, | ||
149 | autohideMenuBar: false, | ||
150 | lockingFeatureEnabled: false, | ||
151 | locked: false, | ||
152 | lockedPassword: '', | ||
153 | useTouchIdToUnlock: true, | ||
154 | scheduledDNDEnabled: false, | ||
155 | scheduledDNDStart: '17:00', | ||
156 | scheduledDNDEnd: '09:00', | ||
157 | hibernateOnStartup: true, | ||
158 | hibernationStrategy: '300', // seconds | ||
159 | wakeUpStrategy: '300', // seconds | ||
160 | inactivityLock: 0, | ||
161 | automaticUpdates: true, | ||
162 | showServiceNavigationBar: false, | ||
163 | universalDarkMode: true, | ||
164 | userAgentPref: '', | ||
165 | adaptableDarkMode: true, | ||
166 | accentColor: DEFAULT_ACCENT_COLOR, | ||
167 | serviceRibbonWidth: 68, | ||
168 | iconSize: iconSizeBias, | ||
169 | sentry: false, | ||
170 | nightly: false, | ||
171 | navigationBarBehaviour: 'custom', | ||
172 | searchEngine: SEARCH_ENGINE_DDG, | ||
173 | useVerticalStyle: false, | ||
174 | alwaysShowWorkspaces: false, | ||
175 | liftSingleInstanceLock: false, | ||
176 | }; | ||
177 | |||
178 | export function aboutAppDetails() { | ||
179 | return [ | ||
180 | `Version: ${ferdiVersion}`, | ||
181 | `Electron: ${electronVersion}`, | ||
182 | `Chrome: ${chromeVersion}`, | ||
183 | `Node.js: ${nodeVersion}`, | ||
184 | `Platform: ${osName()}`, | ||
185 | `Arch: ${process.arch}`, | ||
186 | `Build date: ${new Date(Number(buildInfo.timestamp))}`, | ||
187 | `Git SHA: ${buildInfo.gitHashShort}`, | ||
188 | `Git branch: ${buildInfo.gitBranch}`, | ||
189 | ].join('\n'); | ||
190 | } | ||