diff options
author | 2021-08-08 00:01:37 +0000 | |
---|---|---|
committer | 2021-08-08 05:31:37 +0530 | |
commit | 97d51a7763b14c92ee71ff9a012311dd9498d803 (patch) | |
tree | bd36005031ecb1148f27aa541e7a92a5e3aa4c0c /src/environment.js | |
parent | 5.6.1-nightly.17 [skip ci] (diff) | |
download | ferdium-app-97d51a7763b14c92ee71ff9a012311dd9498d803.tar.gz ferdium-app-97d51a7763b14c92ee71ff9a012311dd9498d803.tar.zst ferdium-app-97d51a7763b14c92ee71ff9a012311dd9498d803.zip |
refactor: path-references refactoring and using 'import' instead of 'require' (#1752)
* refactor references to 'userData' and 'appData' directories to move hardcoding into single location
* convert to es6 for lower memory usage as per https://codesource.io/the-difference-between-import-and-require-in-javascript/
Diffstat (limited to 'src/environment.js')
-rw-r--r-- | src/environment.js | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/environment.js b/src/environment.js index 7b560acb6..7267f93a6 100644 --- a/src/environment.js +++ b/src/environment.js | |||
@@ -1,10 +1,11 @@ | |||
1 | import os from 'os'; | 1 | import os from 'os'; |
2 | import path from 'path'; | 2 | import { join } from 'path'; |
3 | 3 | ||
4 | import { is, api as electronApi } from 'electron-util'; | 4 | import { is, api as electronApi } from 'electron-util'; |
5 | 5 | ||
6 | import { DEFAULT_ACCENT_COLOR } from '@meetfranz/theme'; | 6 | import { DEFAULT_ACCENT_COLOR } from '@meetfranz/theme'; |
7 | 7 | ||
8 | import osName from 'os-name'; | ||
8 | import { | 9 | import { |
9 | LIVE_FERDI_API, | 10 | LIVE_FERDI_API, |
10 | DEV_FRANZ_API, | 11 | DEV_FRANZ_API, |
@@ -25,8 +26,6 @@ import { | |||
25 | import { asarPath } from './helpers/asar-helpers'; | 26 | import { asarPath } from './helpers/asar-helpers'; |
26 | import * as buildInfo from './buildInfo.json'; // eslint-disable-line import/no-unresolved | 27 | import * as buildInfo from './buildInfo.json'; // eslint-disable-line import/no-unresolved |
27 | 28 | ||
28 | const osName = require('os-name'); | ||
29 | |||
30 | export const { app } = electronApi; | 29 | export const { app } = electronApi; |
31 | export const ferdiVersion = app.getVersion(); | 30 | export const ferdiVersion = app.getVersion(); |
32 | export const electronVersion = process.versions.electron; | 31 | export const electronVersion = process.versions.electron; |
@@ -36,24 +35,32 @@ export const nodeVersion = process.versions.node; | |||
36 | // Set app directory before loading user modules | 35 | // Set app directory before loading user modules |
37 | if (process.env.FERDI_APPDATA_DIR != null) { | 36 | if (process.env.FERDI_APPDATA_DIR != null) { |
38 | app.setPath('appData', process.env.FERDI_APPDATA_DIR); | 37 | app.setPath('appData', process.env.FERDI_APPDATA_DIR); |
39 | app.setPath('userData', path.join(app.getPath('appData'))); | 38 | app.setPath('userData', join(app.getPath('appData'))); |
40 | } else if (process.env.PORTABLE_EXECUTABLE_DIR != null) { | 39 | } else if (process.env.PORTABLE_EXECUTABLE_DIR != null) { |
41 | app.setPath('appData', process.env.PORTABLE_EXECUTABLE_DIR, `${app.name}AppData`); | 40 | app.setPath('appData', process.env.PORTABLE_EXECUTABLE_DIR, `${app.name}AppData`); |
42 | app.setPath('userData', path.join(app.getPath('appData'), `${app.name}AppData`)); | 41 | app.setPath('userData', join(app.getPath('appData'), `${app.name}AppData`)); |
43 | } else if (is.windows) { | 42 | } else if (is.windows) { |
44 | app.setPath('appData', process.env.APPDATA); | 43 | app.setPath('appData', process.env.APPDATA); |
45 | app.setPath('userData', path.join(app.getPath('appData'), app.name)); | 44 | app.setPath('userData', join(app.getPath('appData'), app.name)); |
46 | } | 45 | } |
47 | 46 | ||
48 | export const isDevMode = is.development; | 47 | export const isDevMode = is.development; |
49 | if (isDevMode) { | 48 | if (isDevMode) { |
50 | app.setPath('userData', path.join(app.getPath('appData'), `${app.name}Dev`)); | 49 | app.setPath('userData', join(app.getPath('appData'), `${app.name}Dev`)); |
51 | } | 50 | } |
52 | 51 | ||
53 | export const SETTINGS_PATH = path.join(app.getPath('userData'), 'config'); | 52 | export function userDataPath(...segments) { |
53 | return join(app.getPath('userData'), ...([segments].flat())); | ||
54 | } | ||
55 | |||
56 | export function userDataRecipesPath(...segments) { | ||
57 | return userDataPath('recipes', ...([segments].flat())); | ||
58 | } | ||
54 | 59 | ||
55 | // Replacing app.asar is not beautiful but unfortunately necessary | 60 | // Replacing app.asar is not beautiful but unfortunately necessary |
56 | export const RECIPES_PATH = asarPath(path.join(__dirname, 'recipes')); | 61 | export function asarRecipesPath(...segments) { |
62 | return join(asarPath(join(__dirname, 'recipes')), ...([segments].flat())); | ||
63 | } | ||
57 | 64 | ||
58 | export const useLiveAPI = process.env.USE_LIVE_API; | 65 | export const useLiveAPI = process.env.USE_LIVE_API; |
59 | const useLocalAPI = process.env.USE_LOCAL_API; | 66 | const useLocalAPI = process.env.USE_LOCAL_API; |