aboutsummaryrefslogtreecommitdiffstats
path: root/src/environment-remote.ts
diff options
context:
space:
mode:
authorLibravatar Vijay A <vraravam@users.noreply.github.com>2021-10-01 21:51:55 +0530
committerLibravatar Vijay A <vraravam@users.noreply.github.com>2021-10-01 21:51:55 +0530
commit204a80708e6e0a2189de16438a3eb4b57ef84987 (patch)
treea8fa3afb58dbfec67bced4281837d33fd4e71413 /src/environment-remote.ts
parentrefactor: move 'asarRecipesPath' into 'asar-helpers' (diff)
downloadferdium-app-204a80708e6e0a2189de16438a3eb4b57ef84987.tar.gz
ferdium-app-204a80708e6e0a2189de16438a3eb4b57ef84987.tar.zst
ferdium-app-204a80708e6e0a2189de16438a3eb4b57ef84987.zip
refactor: split 'environment' into 'environment-remote' with only the remote module dependency
(might be a pre-requisite for the electron v14 upgrade)
Diffstat (limited to 'src/environment-remote.ts')
-rw-r--r--src/environment-remote.ts93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/environment-remote.ts b/src/environment-remote.ts
new file mode 100644
index 000000000..1ff019c5f
--- /dev/null
+++ b/src/environment-remote.ts
@@ -0,0 +1,93 @@
1import { join } from 'path';
2import osName from 'os-name';
3import { api as electronApi } from 'electron-util';
4import {
5 LIVE_FERDI_API,
6 DEV_FRANZ_API,
7 LOCAL_API,
8 LOCAL_API_WEBSITE,
9 DEV_API_FRANZ_WEBSITE,
10 LIVE_API_FERDI_WEBSITE,
11 LIVE_WS_API,
12 LOCAL_WS_API,
13 DEV_WS_API,
14 LOCAL_TODOS_FRONTEND_URL,
15 PRODUCTION_TODOS_FRONTEND_URL,
16} from './config';
17import { chromeVersion, electronVersion, isWindows, nodeVersion, osArch } from './environment';
18
19// @ts-expect-error Cannot find module './buildInfo.json' or its corresponding type declarations.
20import * as buildInfo from './buildInfo.json';
21
22export const { app } = electronApi;
23export const ferdiVersion = app.getVersion();
24export const ferdiLocale = app.getLocale();
25
26// Set app directory before loading user modules
27if (process.env.FERDI_APPDATA_DIR != null) {
28 app.setPath('appData', process.env.FERDI_APPDATA_DIR);
29 app.setPath('userData', app.getPath('appData'));
30} else if (process.env.PORTABLE_EXECUTABLE_DIR != null) {
31 app.setPath('appData', join(process.env.PORTABLE_EXECUTABLE_DIR, `${app.name}AppData`));
32 app.setPath('userData', join(app.getPath('appData'), `${app.name}AppData`));
33} else if (isWindows && process.env.APPDATA != null) {
34 app.setPath('appData', process.env.APPDATA);
35 app.setPath('userData', join(app.getPath('appData'), app.name));
36}
37
38export const isDevMode = process.env.ELECTRON_IS_DEV !== undefined ? Number.parseInt(process.env.ELECTRON_IS_DEV, 10) === 1 : !app.isPackaged;
39if (isDevMode) {
40 app.setPath('userData', join(app.getPath('appData'), `${app.name}Dev`));
41}
42
43export function userDataPath(...segments: string[]) {
44 return join(app.getPath('userData'), ...[segments].flat());
45}
46
47export function userDataRecipesPath(...segments: any[]) {
48 return userDataPath('recipes', ...[segments].flat());
49}
50
51const useLocalAPI = process.env.USE_LOCAL_API;
52export const useLiveAPI = process.env.USE_LIVE_API;
53
54let api: string;
55let wsApi: string;
56let web: string;
57let todos: string;
58if (!isDevMode || (isDevMode && useLiveAPI)) {
59 api = LIVE_FERDI_API;
60 wsApi = LIVE_WS_API;
61 web = LIVE_API_FERDI_WEBSITE;
62 todos = PRODUCTION_TODOS_FRONTEND_URL;
63} else if (isDevMode && useLocalAPI) {
64 api = LOCAL_API;
65 wsApi = LOCAL_WS_API;
66 web = LOCAL_API_WEBSITE;
67 todos = LOCAL_TODOS_FRONTEND_URL;
68} else {
69 api = DEV_FRANZ_API;
70 wsApi = DEV_WS_API;
71 web = DEV_API_FRANZ_WEBSITE;
72 todos = PRODUCTION_TODOS_FRONTEND_URL;
73}
74
75export const API = api;
76export const API_VERSION = 'v1';
77export const WS_API = wsApi;
78export const WEBSITE = web;
79export const TODOS_FRONTEND = todos;
80
81export function aboutAppDetails() {
82 return [
83 `Version: ${ferdiVersion}`,
84 `Electron: ${electronVersion}`,
85 `Chrome: ${chromeVersion}`,
86 `Node.js: ${nodeVersion}`,
87 `Platform: ${osName()}`,
88 `Arch: ${osArch}`,
89 `Build date: ${new Date(Number(buildInfo.timestamp))}`,
90 `Git SHA: ${buildInfo.gitHashShort}`,
91 `Git branch: ${buildInfo.gitBranch}`,
92 ].join('\n');
93}