Skip to content

Commit

Permalink
Merge pull request balena-io#2433 from resin-io/fix-cli-settings
Browse files Browse the repository at this point in the history
fix(cli): Don't use electron to get USER_DATA_DIR in CLI
  • Loading branch information
thundron committed Aug 7, 2018
2 parents d0ee569 + 40d84b7 commit 93906b9
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions lib/gui/app/models/local-settings.js
Expand Up @@ -16,10 +16,10 @@

'use strict'

const electron = require('electron')
const Bluebird = require('bluebird')
const fs = require('fs')
const path = require('path')
const os = require('os')

/**
* @summary Number of spaces to indent JSON output with
Expand All @@ -36,14 +36,31 @@ const JSON_INDENT = 2
* - `$XDG_CONFIG_HOME/etcher` or `~/.config/etcher` on Linux
* - `~/Library/Application Support/etcher` on macOS
* See https://electronjs.org/docs/api/app#appgetpathname
* NOTE: The ternary is due to this module being loaded both,
* in Electron's main and renderer processes
* @constant
* @type {String}
*/
const USER_DATA_DIR = electron.app
? electron.app.getPath('userData')
: electron.remote.app.getPath('userData')
const USER_DATA_DIR = (() => {
// Electron
if (process.versions.electron) {
// NOTE: The ternary is due to this module being loaded both,
// Electron's main process and renderer process
const electron = require('electron')
return electron.app
? electron.app.getPath('userData')
: electron.remote.app.getPath('userData')
}

// CLI
if (process.platform === 'win32') {
return path.join(process.env.APPDATA, 'etcher')
}

if (process.platform === 'darwin') {
return path.join(os.homedir(), 'Library', 'Application Support', 'etcher')
}

return path.join(process.env.XDG_CONFIG_HOME || os.homedir(), '.config', 'etcher')
})()

/**
* @summary Configuration file path
Expand Down

0 comments on commit 93906b9

Please sign in to comment.