From d70be3abf98d1db4874bfbbdcc460221808d84f4 Mon Sep 17 00:00:00 2001 From: Nathaniel Walser Date: Sat, 30 Sep 2023 21:05:57 +0200 Subject: [PATCH] added possibility to set config file path in environment file --- .env | 1 + app/lib/config.ts | 12 +++++------- app/lib/index.ts | 12 ++++++++---- package.json | 5 ++++- tabby-electron/src/services/platform.service.ts | 3 ++- yarn.lock | 5 +++++ 6 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000000..5231482462 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +CONFIG_DIRECTORY="C:\Users\Nathaniel Walser\Desktop\tabby" \ No newline at end of file diff --git a/app/lib/config.ts b/app/lib/config.ts index ef86d0a929..9dd5c729b7 100644 --- a/app/lib/config.ts +++ b/app/lib/config.ts @@ -1,13 +1,14 @@ import * as fs from 'fs' import * as path from 'path' import * as yaml from 'js-yaml' -import { app } from 'electron' import { writeFile } from 'atomically' +export const configPath = path.join(process.env.CONFIG_DIRECTORY!, 'config.yaml') +const legacyConfigPath = path.join(process.env.CONFIG_DIRECTORY!, '../terminus', 'config.yaml') + + export function migrateConfig (): void { - const configPath = path.join(app.getPath('userData'), 'config.yaml') - const legacyConfigPath = path.join(app.getPath('userData'), '../terminus', 'config.yaml') if (fs.existsSync(legacyConfigPath) && ( !fs.existsSync(configPath) || fs.statSync(configPath).mtime < fs.statSync(legacyConfigPath).mtime @@ -19,7 +20,6 @@ export function migrateConfig (): void { export function loadConfig (): any { migrateConfig() - const configPath = path.join(app.getPath('userData'), 'config.yaml') if (fs.existsSync(configPath)) { return yaml.load(fs.readFileSync(configPath, 'utf8')) } else { @@ -27,9 +27,7 @@ export function loadConfig (): any { } } -const configPath = path.join(app.getPath('userData'), 'config.yaml') - export async function saveConfig (content: string): Promise { await writeFile(configPath, content, { encoding: 'utf8' }) await writeFile(configPath + '.backup', content, { encoding: 'utf8' }) -} +} \ No newline at end of file diff --git a/app/lib/index.ts b/app/lib/index.ts index ed736508ae..aa93f335d0 100644 --- a/app/lib/index.ts +++ b/app/lib/index.ts @@ -1,17 +1,21 @@ +import { app, ipcMain, Menu, dialog } from 'electron' + +// set defaults of environment variables +import 'dotenv/config' +process.env.TABBY_PLUGINS ??= '' +process.env.CONFIG_DIRECTORY ??= app.getPath('userData') + + import 'v8-compile-cache' import './portable' import 'source-map-support/register' import './sentry' import './lru' -import { app, ipcMain, Menu, dialog } from 'electron' import { parseArgs } from './cli' import { Application } from './app' import electronDebug = require('electron-debug') import { loadConfig } from './config' -if (!process.env.TABBY_PLUGINS) { - process.env.TABBY_PLUGINS = '' -} const argv = parseArgs(process.argv, process.cwd()) diff --git a/package.json b/package.json index 9ff0b4056b..39600f6416 100644 --- a/package.json +++ b/package.json @@ -115,5 +115,8 @@ "i18n:push": "crowdin push" }, "type": "module", - "private": true + "private": true, + "dependencies": { + "dotenv": "^16.3.1" + } } diff --git a/tabby-electron/src/services/platform.service.ts b/tabby-electron/src/services/platform.service.ts index 604cddc2c4..85ff48f69d 100644 --- a/tabby-electron/src/services/platform.service.ts +++ b/tabby-electron/src/services/platform.service.ts @@ -11,6 +11,7 @@ import { ElectronHostWindow } from './hostWindow.service' import { ShellIntegrationService } from './shellIntegration.service' import { ElectronHostAppService } from './hostApp.service' import { PlatformTheme } from '../../../tabby-core/src/api/platform' +import { configPath } from '../../../app/lib/config' const fontManager = require('fontmanager-redux') // eslint-disable-line /* eslint-disable block-scoped-var */ @@ -36,7 +37,7 @@ export class ElectronPlatformService extends PlatformService { private translate: TranslateService, ) { super() - this.configPath = path.join(electron.app.getPath('userData'), 'config.yaml') + this.configPath = configPath electron.ipcRenderer.on('host:display-metrics-changed', () => { this.zone.run(() => this.displayMetricsChanged.next()) diff --git a/yarn.lock b/yarn.lock index df6d38ddb3..66ee727e2e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2889,6 +2889,11 @@ dotenv-expand@^5.1.0: resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-5.1.0.tgz#3fbaf020bfd794884072ea26b1e9791d45a629f0" integrity sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA== +dotenv@^16.3.1: + version "16.3.1" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" + integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== + dotenv@^5.0.1: version "5.0.1" resolved "https://registry.npmjs.org/dotenv/-/dotenv-5.0.1.tgz"