Bläddra i källkod

added possibility to set config file path in environment file

Nathaniel Walser 2 år sedan
förälder
incheckning
d70be3abf9
6 ändrade filer med 25 tillägg och 13 borttagningar
  1. 1 0
      .env
  2. 5 7
      app/lib/config.ts
  3. 8 4
      app/lib/index.ts
  4. 4 1
      package.json
  5. 2 1
      tabby-electron/src/services/platform.service.ts
  6. 5 0
      yarn.lock

+ 1 - 0
.env

@@ -0,0 +1 @@
+CONFIG_DIRECTORY="C:\Users\Nathaniel Walser\Desktop\tabby"

+ 5 - 7
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<void> {
     await writeFile(configPath, content, { encoding: 'utf8' })
     await writeFile(configPath + '.backup', content, { encoding: 'utf8' })
-}
+}

+ 8 - 4
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())
 

+ 4 - 1
package.json

@@ -115,5 +115,8 @@
     "i18n:push": "crowdin push"
   },
   "type": "module",
-  "private": true
+  "private": true,
+  "dependencies": {
+    "dotenv": "^16.3.1"
+  }
 }

+ 2 - 1
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())

+ 5 - 0
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"