From 8201e0b9ef07bf13c98da0f084e86160f20f3918 Mon Sep 17 00:00:00 2001 From: Cyril Taylor Date: Tue, 14 Jan 2020 15:06:54 +0800 Subject: [PATCH] set userData location to the 'data' folder which at the same level as the Terminus executable directory if exist with portable mode --- app/lib/index.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/lib/index.ts b/app/lib/index.ts index 689a76c1..0fdd4dc1 100644 --- a/app/lib/index.ts +++ b/app/lib/index.ts @@ -4,6 +4,8 @@ import { app, ipcMain, Menu } from 'electron' import { parseArgs } from './cli' import { Application } from './app' import electronDebug = require('electron-debug') +import * as path from 'path' +import * as fs from 'fs' if (!process.env.TERMINUS_PLUGINS) { process.env.TERMINUS_PLUGINS = '' @@ -11,6 +13,17 @@ if (!process.env.TERMINUS_PLUGINS) { const application = new Application() +const portableData = path.join(`${process.env.PORTABLE_EXECUTABLE_DIR}`, 'data') +if (('PORTABLE_EXECUTABLE_DIR' in process.env) && fs.existsSync(portableData)) { + fs.stat(portableData, (err, stats) => { + if (stats.isDirectory()) { + app.setPath('userData' ,portableData) + } else { + console.warn(err) + } + }) +} + ipcMain.on('app:new-window', () => { application.newWindow() })