Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
feat: promote user data path setting from testing-only to experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Nov 19, 2020
1 parent dc5309c commit f9cbee2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
22 changes: 22 additions & 0 deletions app/index.ts
@@ -1,9 +1,31 @@
import { app, ipcMain, shell } from 'electron';
import path from 'path';
import fs from 'fs';
import log from 'electron-log';
import './@types/modules';
import { initializeApplication } from './application';
import { isTesting } from './javascripts/main/utils';
import { setupTesting } from './javascripts/main/testing';
import { CommandLineArgs } from './javascripts/shared/CommandLineArgs';

/** Allow a custom userData path to be used. */
const userDataPathIndex = process.argv.indexOf(CommandLineArgs.UserDataPath);
if (userDataPathIndex > 0) {
let userDataPath = process.argv[userDataPathIndex + 1];
if (typeof userDataPath === 'string') {
userDataPath = path.resolve(userDataPath);

/** Make sure the path is actually a writeable folder */
try {
fs.closeSync(fs.openSync(path.join(userDataPath, 'sn-test-file'), 'w'));
} catch (e) {
console.error('Failed to write to provided user data path. Aborting');
app.exit(1);
}

app.setPath('userData', userDataPath);
}
}

if (isTesting()) {
setupTesting();
Expand Down
11 changes: 0 additions & 11 deletions app/javascripts/main/testing.ts
@@ -1,11 +1,9 @@
import { app, BrowserWindow } from 'electron';
import path from 'path';
import {
AppMessageType,
MessageType,
TestIPCMessage,
} from '../../../test/TestIpcMessage';
import { CommandLineArgs } from '../shared/CommandLineArgs';
import { isTesting } from './utils';

const messageHandlers: {
Expand All @@ -26,15 +24,6 @@ export function send(type: AppMessageType): void {
}

export function setupTesting(): void {
/** Allow a custom userData path to be used. */
const userDataPathIndex = process.argv.indexOf(CommandLineArgs.UserDataPath);
if (userDataPathIndex > 0) {
const userDataPath = process.argv[userDataPathIndex + 1];
if (typeof userDataPath === 'string') {
app.setPath('userData', path.resolve(userDataPath));
}
}

process.on('message', async (message: TestIPCMessage) => {
const handler = messageHandlers[message.type];

Expand Down
2 changes: 1 addition & 1 deletion app/javascripts/shared/CommandLineArgs.ts
@@ -1,4 +1,4 @@
export const CommandLineArgs = {
Testing: '--testing-INSECURE',
UserDataPath: '--user-data-path',
UserDataPath: '--experimental-user-data-path',
};

0 comments on commit f9cbee2

Please sign in to comment.