Add --data-dir to switch userData directory
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@ npm-debug.log*
|
|||||||
test-results.xml
|
test-results.xml
|
||||||
test_config.json
|
test_config.json
|
||||||
.idea
|
.idea
|
||||||
|
testUserData
|
||||||
|
@@ -16,7 +16,7 @@ remote.getCurrentWindow().removeAllListeners('focus');
|
|||||||
|
|
||||||
var config;
|
var config;
|
||||||
try {
|
try {
|
||||||
var configFile = remote.getGlobal('config-file');
|
const configFile = remote.app.getPath('userData') + '/config.json';
|
||||||
config = settings.readFileSync(configFile);
|
config = settings.readFileSync(configFile);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
window.location = 'settings.html';
|
window.location = 'settings.html';
|
||||||
|
@@ -10,7 +10,7 @@ const React = require('react');
|
|||||||
const ReactDOM = require('react-dom');
|
const ReactDOM = require('react-dom');
|
||||||
const SettingsPage = require('./components/SettingsPage.jsx');
|
const SettingsPage = require('./components/SettingsPage.jsx');
|
||||||
|
|
||||||
var configFile = remote.getGlobal('config-file');
|
const configFile = remote.app.getPath('userData') + '/config.json';
|
||||||
|
|
||||||
require('electron-context-menu')({
|
require('electron-context-menu')({
|
||||||
window: remote.getCurrentWindow()
|
window: remote.getCurrentWindow()
|
||||||
|
11
src/main.js
11
src/main.js
@@ -90,16 +90,13 @@ if (argv.hidden) {
|
|||||||
hideOnStartup = true;
|
hideOnStartup = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: We should document this if that hasn't been done already
|
if (argv['data-dir']) {
|
||||||
if (argv['config-file']) {
|
app.setPath('userData', path.resolve(argv['data-dir']));
|
||||||
global['config-file'] = argv['config-file'];
|
|
||||||
} else {
|
|
||||||
global['config-file'] = app.getPath('userData') + '/config.json';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var config = {};
|
var config = {};
|
||||||
try {
|
try {
|
||||||
const configFile = global['config-file'];
|
const configFile = app.getPath('userData') + '/config.json';
|
||||||
config = settings.readFileSync(configFile);
|
config = settings.readFileSync(configFile);
|
||||||
if (config.version !== settings.version || wasUpdated()) {
|
if (config.version !== settings.version || wasUpdated()) {
|
||||||
clearAppCache();
|
clearAppCache();
|
||||||
@@ -112,7 +109,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.on('update-config', () => {
|
ipcMain.on('update-config', () => {
|
||||||
const configFile = global['config-file'];
|
const configFile = app.getPath('userData') + '/config.json';
|
||||||
config = settings.readFileSync(configFile);
|
config = settings.readFileSync(configFile);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -17,7 +17,8 @@ const electronBinaryPath = (() => {
|
|||||||
const exeExtension = (process.platform === 'win32') ? '.exe' : '';
|
const exeExtension = (process.platform === 'win32') ? '.exe' : '';
|
||||||
return path.join(sourceRootDir, 'node_modules/electron/dist/electron' + exeExtension);
|
return path.join(sourceRootDir, 'node_modules/electron/dist/electron' + exeExtension);
|
||||||
})();
|
})();
|
||||||
const configFilePath = path.join(sourceRootDir, 'test/test_config.json');
|
const userDataDir = path.join(sourceRootDir, 'test/testUserData/');
|
||||||
|
const configFilePath = path.join(userDataDir, 'config.json');
|
||||||
const mattermostURL = 'http://example.com/team';
|
const mattermostURL = 'http://example.com/team';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -27,7 +28,7 @@ module.exports = {
|
|||||||
getSpectronApp() {
|
getSpectronApp() {
|
||||||
const app = new Application({
|
const app = new Application({
|
||||||
path: electronBinaryPath,
|
path: electronBinaryPath,
|
||||||
args: [`${path.join(sourceRootDir, 'dist')}`, '--config-file=' + configFilePath]
|
args: [`${path.join(sourceRootDir, 'dist')}`, `--data-dir=${userDataDir}`]
|
||||||
});
|
});
|
||||||
chaiAsPromised.transferPromiseness = app.transferPromiseness;
|
chaiAsPromised.transferPromiseness = app.transferPromiseness;
|
||||||
return app;
|
return app;
|
||||||
|
Reference in New Issue
Block a user