Skip to content

Commit

Permalink
added possibility to set config file path in environment file
Browse files Browse the repository at this point in the history
  • Loading branch information
nwalser committed Sep 30, 2023
1 parent 422df52 commit d70be3a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_DIRECTORY="C:\Users\Nathaniel Walser\Desktop\tabby"
12 changes: 5 additions & 7 deletions app/lib/config.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,17 +20,14 @@ 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 {
return {}
}
}

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' })
}
}

Check failure on line 33 in app/lib/config.ts

View workflow job for this annotation

GitHub Actions / Lint

Newline required at end of file but not found
12 changes: 8 additions & 4 deletions app/lib/index.ts
Original file line number Diff line number Diff line change
@@ -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())

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,8 @@
"i18n:push": "crowdin push"
},
"type": "module",
"private": true
"private": true,
"dependencies": {
"dotenv": "^16.3.1"
}
}
3 changes: 2 additions & 1 deletion tabby-electron/src/services/platform.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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())
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d70be3a

Please sign in to comment.