♿ move config to userData for permissions
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
|
import { app } from 'electron'
|
||||||
import { join, basename } from 'path'
|
import { join, basename } from 'path'
|
||||||
import { homedir } from 'os'
|
import { homedir } from 'os'
|
||||||
import { readFileSync, writeFileSync, mkdirSync } from 'fs'
|
import { readFileSync, writeFileSync, mkdirSync, existsSync, copyFileSync } from 'fs'
|
||||||
|
|
||||||
export interface RecentProject {
|
export interface RecentProject {
|
||||||
path: string
|
path: string
|
||||||
@@ -14,12 +15,19 @@ export interface GlobalConfig {
|
|||||||
recentProjects?: RecentProject[]
|
recentProjects?: RecentProject[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const CONFIG_DIR = join(homedir(), '.hohoff')
|
const CONFIG_DIR = app.getPath('userData')
|
||||||
const CONFIG_FILE = join(CONFIG_DIR, 'config.json')
|
const CONFIG_FILE = join(CONFIG_DIR, 'config.json')
|
||||||
|
|
||||||
|
// Migrate config from legacy ~/.hohoff location on first run
|
||||||
|
const LEGACY_CONFIG_FILE = join(homedir(), '.hohoff', 'config.json')
|
||||||
|
|
||||||
let _config: GlobalConfig = {}
|
let _config: GlobalConfig = {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!existsSync(CONFIG_FILE) && existsSync(LEGACY_CONFIG_FILE)) {
|
||||||
|
mkdirSync(CONFIG_DIR, { recursive: true })
|
||||||
|
copyFileSync(LEGACY_CONFIG_FILE, CONFIG_FILE)
|
||||||
|
}
|
||||||
const raw = JSON.parse(readFileSync(CONFIG_FILE, 'utf-8'))
|
const raw = JSON.parse(readFileSync(CONFIG_FILE, 'utf-8'))
|
||||||
// Migrate old string[] recentProjects to RecentProject[]
|
// Migrate old string[] recentProjects to RecentProject[]
|
||||||
if (Array.isArray(raw.recentProjects) && typeof raw.recentProjects[0] === 'string') {
|
if (Array.isArray(raw.recentProjects) && typeof raw.recentProjects[0] === 'string') {
|
||||||
@@ -33,7 +41,7 @@ try {
|
|||||||
export const getConfigDir = (): string => CONFIG_DIR
|
export const getConfigDir = (): string => CONFIG_DIR
|
||||||
|
|
||||||
export const getDraftRoot = (): string =>
|
export const getDraftRoot = (): string =>
|
||||||
_config.projectPath ?? process.env.DRAFT_PATH ?? join(homedir(), 'Documents', 'hohoff-draft')
|
_config.projectPath ?? process.env.DRAFT_PATH ?? join(app.getPath('documents'), 'Hohoff')
|
||||||
|
|
||||||
export const getApiKey = (): string | undefined =>
|
export const getApiKey = (): string | undefined =>
|
||||||
_config.apiKey ?? process.env.ANTHROPIC_API_KEY
|
_config.apiKey ?? process.env.ANTHROPIC_API_KEY
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user