aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores
diff options
context:
space:
mode:
authorLibravatar Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com>2021-08-08 00:01:37 +0000
committerLibravatar GitHub <noreply@github.com>2021-08-08 05:31:37 +0530
commit97d51a7763b14c92ee71ff9a012311dd9498d803 (patch)
treebd36005031ecb1148f27aa541e7a92a5e3aa4c0c /src/stores
parent5.6.1-nightly.17 [skip ci] (diff)
downloadferdium-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.js6
-rw-r--r--src/stores/RecipesStore.js9
-rw-r--r--src/stores/ServicesStore.js21
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';
12import AutoLaunch from 'auto-launch'; 12import AutoLaunch from 'auto-launch';
13import ms from 'ms'; 13import ms from 'ms';
14import { URL } from 'url'; 14import { URL } from 'url';
15import path from 'path';
16import { readJsonSync } from 'fs-extra'; 15import { readJsonSync } from 'fs-extra';
17 16
18import Store from './lib/Store'; 17import 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';
28import locales from '../i18n/translations'; 28import locales from '../i18n/translations';
29import { onVisibilityChange } from '../helpers/visibility-helper'; 29import { 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 @@
1import { action, computed, observable } from 'mobx'; 1import { action, computed, observable } from 'mobx';
2import fs from 'fs-extra'; 2import { readJSONSync } from 'fs-extra';
3import path from 'path';
4import semver from 'semver'; 3import semver from 'semver';
5 4
6import Store from './lib/Store'; 5import Store from './lib/Store';
7import CachedRequest from './lib/CachedRequest'; 6import CachedRequest from './lib/CachedRequest';
8import Request from './lib/Request'; 7import Request from './lib/Request';
9import { matchRoute } from '../helpers/routing-helpers'; 8import { matchRoute } from '../helpers/routing-helpers';
10import { RECIPES_PATH } from '../environment'; 9import { asarRecipesPath } from '../environment';
11 10
12const debug = require('debug')('Ferdi:RecipeStore'); 11const 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';
3import { debounce, remove } from 'lodash'; 3import { debounce, remove } from 'lodash';
4import ms from 'ms'; 4import ms from 'ms';
5import { app } from '@electron/remote'; 5import { app } from '@electron/remote';
6import fs from 'fs-extra'; 6import { ensureFileSync, pathExistsSync, writeFileSync } from 'fs-extra';
7import path from 'path'; 7import { join } from 'path';
8 8
9import Store from './lib/Store'; 9import Store from './lib/Store';
10import Request from './lib/Request'; 10import 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 }