diff --git a/actions/appSettings.tsx b/actions/appSettings.tsx index 764c4d0..020195c 100644 --- a/actions/appSettings.tsx +++ b/actions/appSettings.tsx @@ -23,7 +23,11 @@ const defaultAppSettings: AppSettings = { }; export async function getAppSettings(): Promise { - const location = await AppSettingsLocation(); + if (!process.env.GPTSCRIPT_SETTINGS_FILE) { + throw new Error('GPTSCRIPT_SETTINGS_FILE not set'); + } + + const location = process.env.GPTSCRIPT_SETTINGS_FILE; if (fs.existsSync(location)) { const AppSettings = fs.readFileSync(location, 'utf-8'); return JSON.parse(AppSettings) as AppSettings; @@ -32,24 +36,10 @@ export async function getAppSettings(): Promise { } export async function setAppSettings(AppSettings: AppSettings) { - const location = await AppSettingsLocation(); - fs.writeFileSync(location, JSON.stringify(AppSettings, null, 2)); -} - -export async function AppSettingsLocation(): Promise { - const homeDir = os.homedir(); - let configDir; - if (os.platform() === 'darwin') { - configDir = - process.env.XDG_CONFIG_HOME || - path.join(homeDir, 'Library', 'Application Support'); - } else if (os.platform() === 'win32') { - configDir = path.join(homeDir, 'AppData', 'Local'); - } else if (os.platform() === 'linux') { - configDir = process.env.XDG_CONFIG_HOME || path.join(homeDir, '.config'); - } else { - throw new Error('Unsupported platform'); + if (!process.env.GPTSCRIPT_SETTINGS_FILE) { + throw new Error('GPTSCRIPT_SETTINGS_FILE not set'); } - return path.join(configDir, 'acorn', 'settings.json'); + const location = process.env.GPTSCRIPT_SETTINGS_FILE; + fs.writeFileSync(location, JSON.stringify(AppSettings, null, 2)); } diff --git a/server/app.mjs b/server/app.mjs index a4064a3..b069c95 100644 --- a/server/app.mjs +++ b/server/app.mjs @@ -121,24 +121,6 @@ export const startAppServer = ({ dev, hostname, port, appDir }) => { }); }; -function appSettingsLocation() { - const homeDir = os.homedir(); - let configDir; - if (os.platform() === 'darwin') { - configDir = - process.env.XDG_CONFIG_HOME || - path.join(homeDir, 'Library', 'Application Support'); - } else if (os.platform() === 'win32') { - configDir = path.join(homeDir, 'AppData', 'Local'); - } else if (os.platform() === 'linux') { - configDir = process.env.XDG_CONFIG_HOME || path.join(homeDir, '.config'); - } else { - throw new Error('Unsupported platform'); - } - - return path.join(configDir, 'acorn', 'settings.json'); -} - const mount = async ( location, tool, @@ -153,7 +135,7 @@ const mount = async ( process.env.WORKSPACE_DIR ?? process.env.GPTSCRIPT_WORKSPACE_DIR; const THREADS_DIR = process.env.THREADS_DIR ?? path.join(WORKSPACE_DIR, 'threads'); - const settingsLocation = appSettingsLocation(); + const settingsLocation = process.env.GPTSCRIPT_SETTINGS_FILE; const settings = JSON.parse(fs.readFileSync(settingsLocation, 'utf8')); let script;