From d70be3abf98d1db4874bfbbdcc460221808d84f4 Mon Sep 17 00:00:00 2001 From: Nathaniel Walser Date: Sat, 30 Sep 2023 21:05:57 +0200 Subject: [PATCH 1/3] 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 00000000..52314824 --- /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 ef86d0a9..9dd5c729 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 ed736508..aa93f335 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 9ff0b405..39600f64 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 604cddc2..85ff48f6 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 df6d38dd..66ee727e 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" From d1a837b11d881aa44f1bacf17a95f6e2c13b2cf0 Mon Sep 17 00:00:00 2001 From: Nathaniel Walser Date: Sat, 30 Sep 2023 21:30:25 +0200 Subject: [PATCH 2/3] fixed linting error and removed value from .env file --- .env | 2 +- app/lib/config.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 52314824..beb35b3d 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -CONFIG_DIRECTORY="C:\Users\Nathaniel Walser\Desktop\tabby" \ No newline at end of file +# CONFIG_DIRECTORY="CONFIG_FILE_PATH" \ No newline at end of file diff --git a/app/lib/config.ts b/app/lib/config.ts index 9dd5c729..150c7d48 100644 --- a/app/lib/config.ts +++ b/app/lib/config.ts @@ -30,4 +30,4 @@ export function loadConfig (): any { 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 +} From bd31db9c56995171385b45d3df35567e3842fb52 Mon Sep 17 00:00:00 2001 From: Nathaniel Walser Date: Tue, 3 Oct 2023 08:06:16 +0200 Subject: [PATCH 3/3] renamed env variable to TABBY_CONFIG_DIRECTORY --- .env | 2 +- app/lib/config.ts | 4 ++-- app/lib/index.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.env b/.env index beb35b3d..1fa250ae 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -# CONFIG_DIRECTORY="CONFIG_FILE_PATH" \ No newline at end of file +# TABBY_CONFIG_DIRECTORY="PATH_TO_DIRECTORY" \ No newline at end of file diff --git a/app/lib/config.ts b/app/lib/config.ts index 150c7d48..e317fd07 100644 --- a/app/lib/config.ts +++ b/app/lib/config.ts @@ -4,8 +4,8 @@ import * as yaml from 'js-yaml' 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 const configPath = path.join(process.env.TABBY_CONFIG_DIRECTORY!, 'config.yaml') +const legacyConfigPath = path.join(process.env.TABBY_CONFIG_DIRECTORY!, '../terminus', 'config.yaml') export function migrateConfig (): void { diff --git a/app/lib/index.ts b/app/lib/index.ts index aa93f335..c98757b2 100644 --- a/app/lib/index.ts +++ b/app/lib/index.ts @@ -3,7 +3,7 @@ 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') +process.env.TABBY_CONFIG_DIRECTORY ??= app.getPath('userData') import 'v8-compile-cache'