diff options
author | 2021-08-08 00:01:37 +0000 | |
---|---|---|
committer | 2021-08-08 05:31:37 +0530 | |
commit | 97d51a7763b14c92ee71ff9a012311dd9498d803 (patch) | |
tree | bd36005031ecb1148f27aa541e7a92a5e3aa4c0c /src/stores | |
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/stores')
-rw-r--r-- | src/stores/AppStore.js | 6 | ||||
-rw-r--r-- | src/stores/RecipesStore.js | 9 | ||||
-rw-r--r-- | src/stores/ServicesStore.js | 21 |
3 files changed, 16 insertions, 20 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 6b5ca7c9a..1d706f1ef 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js | |||
@@ -12,7 +12,6 @@ import moment from 'moment'; | |||
12 | import AutoLaunch from 'auto-launch'; | 12 | import AutoLaunch from 'auto-launch'; |
13 | import ms from 'ms'; | 13 | import ms from 'ms'; |
14 | import { URL } from 'url'; | 14 | import { URL } from 'url'; |
15 | import path from 'path'; | ||
16 | import { readJsonSync } from 'fs-extra'; | 15 | import { readJsonSync } from 'fs-extra'; |
17 | 16 | ||
18 | import Store from './lib/Store'; | 17 | import Store from './lib/Store'; |
@@ -24,6 +23,7 @@ import { | |||
24 | ferdiVersion, | 23 | ferdiVersion, |
25 | electronVersion, | 24 | electronVersion, |
26 | osRelease, | 25 | osRelease, |
26 | userDataPath, | ||
27 | } from '../environment'; | 27 | } from '../environment'; |
28 | import locales from '../i18n/translations'; | 28 | import locales from '../i18n/translations'; |
29 | import { onVisibilityChange } from '../helpers/visibility-helper'; | 29 | import { onVisibilityChange } from '../helpers/visibility-helper'; |
@@ -307,9 +307,7 @@ export default class AppStore extends Store { | |||
307 | id: workspace.id, | 307 | id: workspace.id, |
308 | services: workspace.services, | 308 | services: workspace.services, |
309 | })), | 309 | })), |
310 | windowSettings: readJsonSync( | 310 | windowSettings: readJsonSync(userDataPath('window-state.json')), |
311 | path.join(app.getPath('userData'), 'window-state.json'), | ||
312 | ), | ||
313 | settings, | 311 | settings, |
314 | features: this.stores.features.features, | 312 | features: this.stores.features.features, |
315 | user: this.stores.user.data.id, | 313 | user: this.stores.user.data.id, |
diff --git a/src/stores/RecipesStore.js b/src/stores/RecipesStore.js index c7c4c1deb..d2acebb75 100644 --- a/src/stores/RecipesStore.js +++ b/src/stores/RecipesStore.js | |||
@@ -1,13 +1,12 @@ | |||
1 | import { action, computed, observable } from 'mobx'; | 1 | import { action, computed, observable } from 'mobx'; |
2 | import fs from 'fs-extra'; | 2 | import { readJSONSync } from 'fs-extra'; |
3 | import path from 'path'; | ||
4 | import semver from 'semver'; | 3 | import semver from 'semver'; |
5 | 4 | ||
6 | import Store from './lib/Store'; | 5 | import Store from './lib/Store'; |
7 | import CachedRequest from './lib/CachedRequest'; | 6 | import CachedRequest from './lib/CachedRequest'; |
8 | import Request from './lib/Request'; | 7 | import Request from './lib/Request'; |
9 | import { matchRoute } from '../helpers/routing-helpers'; | 8 | import { matchRoute } from '../helpers/routing-helpers'; |
10 | import { RECIPES_PATH } from '../environment'; | 9 | import { asarRecipesPath } from '../environment'; |
11 | 10 | ||
12 | const debug = require('debug')('Ferdi:RecipeStore'); | 11 | const debug = require('debug')('Ferdi:RecipeStore'); |
13 | 12 | ||
@@ -90,8 +89,8 @@ export default class RecipesStore extends Store { | |||
90 | const remoteUpdates = await this.getRecipeUpdatesRequest.execute(recipes)._promise; | 89 | const remoteUpdates = await this.getRecipeUpdatesRequest.execute(recipes)._promise; |
91 | 90 | ||
92 | // Check for local updates | 91 | // Check for local updates |
93 | const allJsonFile = path.join(RECIPES_PATH, 'all.json'); | 92 | const allJsonFile = asarRecipesPath('all.json'); |
94 | const allJson = await fs.readJSON(allJsonFile); | 93 | const allJson = readJSONSync(allJsonFile); |
95 | const localUpdates = []; | 94 | const localUpdates = []; |
96 | 95 | ||
97 | Object.keys(recipes).forEach((recipe) => { | 96 | Object.keys(recipes).forEach((recipe) => { |
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 829797930..499495d08 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -3,8 +3,8 @@ import { action, reaction, computed, observable } from 'mobx'; | |||
3 | import { debounce, remove } from 'lodash'; | 3 | import { debounce, remove } from 'lodash'; |
4 | import ms from 'ms'; | 4 | import ms from 'ms'; |
5 | import { app } from '@electron/remote'; | 5 | import { app } from '@electron/remote'; |
6 | import fs from 'fs-extra'; | 6 | import { ensureFileSync, pathExistsSync, writeFileSync } from 'fs-extra'; |
7 | import path from 'path'; | 7 | import { join } from 'path'; |
8 | 8 | ||
9 | import Store from './lib/Store'; | 9 | import Store from './lib/Store'; |
10 | import Request from './lib/Request'; | 10 | import Request from './lib/Request'; |
@@ -524,9 +524,9 @@ export default class ServicesStore extends Store { | |||
524 | const devDirectory = getDevRecipeDirectory(recipe); | 524 | const devDirectory = getDevRecipeDirectory(recipe); |
525 | let directory; | 525 | let directory; |
526 | 526 | ||
527 | if (await fs.pathExists(normalDirectory)) { | 527 | if (pathExistsSync(normalDirectory)) { |
528 | directory = normalDirectory; | 528 | directory = normalDirectory; |
529 | } else if (await fs.pathExists(devDirectory)) { | 529 | } else if (pathExistsSync(devDirectory)) { |
530 | directory = devDirectory; | 530 | directory = devDirectory; |
531 | } else { | 531 | } else { |
532 | // Recipe cannot be found on drive | 532 | // Recipe cannot be found on drive |
@@ -534,20 +534,19 @@ export default class ServicesStore extends Store { | |||
534 | } | 534 | } |
535 | 535 | ||
536 | // Create and open file | 536 | // Create and open file |
537 | const filePath = path.join(directory, file); | 537 | const filePath = join(directory, file); |
538 | if (file === 'user.js') { | 538 | if (file === 'user.js') { |
539 | if (!fs.existsSync(filePath)) { | 539 | if (!pathExistsSync(filePath)) { |
540 | await fs.writeFile( | 540 | writeFileSync( |
541 | filePath, | 541 | filePath, |
542 | `module.exports = (config, Ferdi) => { | 542 | `module.exports = (config, Ferdi) => { |
543 | // Write your scripts here | 543 | // Write your scripts here |
544 | console.log("Hello, World!", config); | 544 | console.log("Hello, World!", config); |
545 | } | 545 | }; |
546 | `, | 546 | `); |
547 | ); | ||
548 | } | 547 | } |
549 | } else { | 548 | } else { |
550 | await fs.ensureFile(filePath); | 549 | ensureFileSync(filePath); |
551 | } | 550 | } |
552 | shell.showItemInFolder(filePath); | 551 | shell.showItemInFolder(filePath); |
553 | } | 552 | } |