aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers
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/helpers
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/helpers')
-rw-r--r--src/helpers/recipe-helpers.js11
-rw-r--r--src/helpers/service-helpers.js16
-rw-r--r--src/helpers/userAgent-helpers.js5
3 files changed, 14 insertions, 18 deletions
diff --git a/src/helpers/recipe-helpers.js b/src/helpers/recipe-helpers.js
index 7daa0aaab..7e4bfa85a 100644
--- a/src/helpers/recipe-helpers.js
+++ b/src/helpers/recipe-helpers.js
@@ -1,12 +1,12 @@
1import path from 'path'; 1import { parse } from 'path';
2import { app } from '@electron/remote'; 2import { userDataRecipesPath } from '../environment';
3 3
4export function getRecipeDirectory(id = '') { 4export function getRecipeDirectory(id = '') {
5 return path.join(app.getPath('userData'), 'recipes', id); 5 return userDataRecipesPath(id);
6} 6}
7 7
8export function getDevRecipeDirectory(id = '') { 8export function getDevRecipeDirectory(id = '') {
9 return path.join(app.getPath('userData'), 'recipes', 'dev', id); 9 return userDataRecipesPath('dev', id);
10} 10}
11 11
12export function loadRecipeConfig(recipeId) { 12export function loadRecipeConfig(recipeId) {
@@ -19,8 +19,7 @@ export function loadRecipeConfig(recipeId) {
19 let config = require(configPath); 19 let config = require(configPath);
20 20
21 const moduleConfigPath = require.resolve(configPath); 21 const moduleConfigPath = require.resolve(configPath);
22 const paths = path.parse(moduleConfigPath); 22 config.path = parse(moduleConfigPath).dir;
23 config.path = paths.dir;
24 23
25 return config; 24 return config;
26 } catch (e) { 25 } catch (e) {
diff --git a/src/helpers/service-helpers.js b/src/helpers/service-helpers.js
index 28d483182..745f40dd9 100644
--- a/src/helpers/service-helpers.js
+++ b/src/helpers/service-helpers.js
@@ -1,18 +1,16 @@
1import path from 'path'; 1import { readdirSync, removeSync } from 'fs-extra';
2import { app } from '@electron/remote'; 2import { userDataPath } from '../environment';
3import fs from 'fs-extra';
4 3
5export function getServicePartitionsDirectory() { 4export function getServicePartitionsDirectory(...segments) {
6 return path.join(app.getPath('userData'), 'Partitions'); 5 return userDataPath('Partitions', ...([segments].flat()));
7} 6}
8 7
9export function removeServicePartitionDirectory(id = '', addServicePrefix = false) { 8export function removeServicePartitionDirectory(id = '', addServicePrefix = false) {
10 const servicePartition = path.join(getServicePartitionsDirectory(), `${addServicePrefix ? 'service-' : ''}${id}`); 9 const servicePartition = getServicePartitionsDirectory(`${addServicePrefix ? 'service-' : ''}${id}`);
11 10 return removeSync(servicePartition);
12 return fs.remove(servicePartition);
13} 11}
14 12
15export async function getServiceIdsFromPartitions() { 13export async function getServiceIdsFromPartitions() {
16 const files = await fs.readdir(getServicePartitionsDirectory()); 14 const files = readdirSync(getServicePartitionsDirectory());
17 return files.filter((n) => n !== '__chrome_extension'); 15 return files.filter((n) => n !== '__chrome_extension');
18} 16}
diff --git a/src/helpers/userAgent-helpers.js b/src/helpers/userAgent-helpers.js
index 9c9c8f132..ede5e6dc4 100644
--- a/src/helpers/userAgent-helpers.js
+++ b/src/helpers/userAgent-helpers.js
@@ -1,11 +1,10 @@
1import os from 'os'; 1import os from 'os';
2import macosVersion from 'macos-version'; 2import macosVersion from 'macos-version';
3import { chrome } from 'useragent-generator';
3import { 4import {
4 chromeVersion, isMac, isWindows, is64Bit, osArch, osRelease, 5 chromeVersion, isMac, isWindows, is64Bit, osArch, osRelease,
5} from '../environment'; 6} from '../environment';
6 7
7const uaGenerator = require('useragent-generator');
8
9function macOS() { 8function macOS() {
10 const version = macosVersion(); 9 const version = macosVersion();
11 let cpuName = os.cpus()[0].model.split(' ')[0]; 10 let cpuName = os.cpus()[0].model.split(' ')[0];
@@ -38,5 +37,5 @@ export default function userAgent() {
38 platformString = linux(); 37 platformString = linux();
39 } 38 }
40 39
41 return uaGenerator.chrome({ os: platformString, version: chromeVersion }); 40 return chrome({ os: platformString, version: chromeVersion });
42} 41}