From 62f30ccd4c430213860da36d52de793cfcfd293a Mon Sep 17 00:00:00 2001 From: Makazzz Date: Tue, 29 Oct 2019 14:45:00 -0400 Subject: Creating function instead --- src/config.js | 14 +++----------- src/helpers/portable-helpers.js | 16 ++++++++++++++++ src/index.js | 14 +++----------- 3 files changed, 22 insertions(+), 22 deletions(-) create mode 100644 src/helpers/portable-helpers.js (limited to 'src') diff --git a/src/config.js b/src/config.js index a7389b8bc..33067fc9d 100644 --- a/src/config.js +++ b/src/config.js @@ -113,17 +113,9 @@ export const FILE_SYSTEM_SETTINGS_TYPES = [ export const LOCAL_SERVER = 'You are using Ferdi without a server'; -// Set app directory before loading user modules -if (process.env.FERDI_APPDATA_DIR != null) { - app.setPath('appData', process.env.FERDI_APPDATA_DIR); - app.setPath('userData', path.join(app.getPath('appData'))); -} else if (process.env.PORTABLE_EXECUTABLE_DIR != null) { - app.setPath('appData', process.env.PORTABLE_EXECUTABLE_DIR, `${app.getName()}AppData`); - app.setPath('userData', path.join(app.getPath('appData'), `${app.getName()}AppData`)); -} else if (process.platform === 'win32') { - app.setPath('appData', process.env.APPDATA); - app.setPath('userData', path.join(app.getPath('appData'), app.getName())); -} +import { portable } from './helpers/portable-helpers'; + +portable(); export const SETTINGS_PATH = path.join(app.getPath('userData'), 'config'); diff --git a/src/helpers/portable-helpers.js b/src/helpers/portable-helpers.js new file mode 100644 index 000000000..60b7b91f1 --- /dev/null +++ b/src/helpers/portable-helpers.js @@ -0,0 +1,16 @@ +import { app } from 'electron'; +import path from 'path'; + +// Set app directory before loading user modules +export function portable() { + if (process.env.FERDI_APPDATA_DIR != null) { + app.setPath('appData', process.env.FERDI_APPDATA_DIR); + app.setPath('userData', path.join(app.getPath('appData'))); + } else if (process.env.PORTABLE_EXECUTABLE_DIR != null) { + app.setPath('appData', process.env.PORTABLE_EXECUTABLE_DIR, `${app.getName()}AppData`); + app.setPath('userData', path.join(app.getPath('appData'), `${app.getName()}AppData`)); + } else if (process.platform === 'win32') { + app.setPath('appData', process.env.APPDATA); + app.setPath('userData', path.join(app.getPath('appData'), app.getName())); + } +} diff --git a/src/index.js b/src/index.js index 3453b46f7..8d52e5396 100644 --- a/src/index.js +++ b/src/index.js @@ -9,17 +9,9 @@ import fs from 'fs-extra'; import path from 'path'; import windowStateKeeper from 'electron-window-state'; -// Set app directory before loading user modules -if (process.env.FERDI_APPDATA_DIR != null) { - app.setPath('appData', process.env.FERDI_APPDATA_DIR); - app.setPath('userData', path.join(app.getPath('appData'))); -} else if (process.env.PORTABLE_EXECUTABLE_DIR != null) { - app.setPath('appData', process.env.PORTABLE_EXECUTABLE_DIR, `${app.getName()}AppData`); - app.setPath('userData', path.join(app.getPath('appData'), `${app.getName()}AppData`)); -} else if (process.platform === 'win32') { - app.setPath('appData', process.env.APPDATA); - app.setPath('userData', path.join(app.getPath('appData'), app.getName())); -} +import { portable } from './helpers/portable-helpers'; + +portable(); if (isDevMode) { app.setPath('userData', path.join(app.getPath('appData'), `${app.getName()}Dev`)); -- cgit v1.2.3-70-g09d2