also looking at this
fix(app): a settings.json this build cannot read no longer loops the app
#46
4 files
+130
-22
| @@ -8,12 +8,11 @@ import { homedir } from 'node:os' | ||
| 8 | 8 | import { join } from 'node:path' |
| 9 | 9 | import process from 'node:process' |
| 10 | 10 | import { loadConfig } from './config' |
| 11 | import { isEngineId } from './engine' | |
| 12 | 11 | import { allEngines, selectedEngine } from './engines' |
| 13 | 12 | import { formatDuration, truncate } from './format' |
| 14 | 13 | import { MessagesAccessError, MessagesDb } from './messages-db' |
| 15 | 14 | import { AppleScriptSender } from './sender' |
| 16 | import { cleanToken, DATA_DIR, DATABASE_PATH, readSettings, readToken, settingsEnv, tokenLooksValid, writeSettings, writeToken } from './settings' | |
| 15 | import { cleanToken, coerceSettings, DATA_DIR, DATABASE_PATH, readSettings, readToken, settingsEnv, tokenLooksValid, writeSettings, writeToken } from './settings' | |
| 17 | 16 | import { checkLicenseKey, describeLicense, isLicensed, normalizeKey, portalUrl, PRICING_URL, readLicenseKey, readLicenseState, RECHECK_MS, writeLicenseKey, writeLicenseState } from './license' |
| 18 | 17 | import { SignIn } from './sign-in' |
| 19 | 18 | import { SqliteStore } from './sqlite-store' |
| @@ -614,16 +613,20 @@ export async function startDesktopAgent(options: { version: string }): Promise<D | ||
| 614 | 613 | return json(engineResult()) |
| 615 | 614 | |
| 616 | 615 | case '/api/settings': { |
| 617 | if (Array.isArray(body.allowed)) | |
| 618 | settings.allowed = body.allowed.map(String).map((s: string) => s.trim()).filter(Boolean) | |
| 619 | if (typeof body.engine === 'string' && isEngineId(body.engine)) | |
| 620 | settings.engine = body.engine | |
| 621 | if (typeof body.paused === 'boolean') | |
| 622 | settings.paused = body.paused | |
| 623 | if (typeof body.openAtLogin === 'boolean') { | |
| 624 | settings.openAtLogin = body.openAtLogin | |
| 625 | setOpenAtLogin(body.openAtLogin) | |
| 626 | } | |
| 616 | // The four fields the popover can send, checked by the same tests the | |
| 617 | // read path uses. Anything absent or unusable keeps what is set now, | |
| 618 | // so this stays a partial update. | |
| 619 | settings = coerceSettings({ | |
| 620 | allowed: body.allowed, | |
| 621 | engine: body.engine, | |
| 622 | paused: body.paused, | |
| 623 | openAtLogin: body.openAtLogin, | |
| 624 | }, settings) | |
| 625 | // Rewritten whenever the popover sent the field, not only when the | |
| 626 | // value changed: someone toggling it back and forth is how a login | |
| 627 | // item left pointing at an old install gets repaired. | |
| 628 | if (typeof body.openAtLogin === 'boolean') | |
| 629 | setOpenAtLogin(settings.openAtLogin) | |
| 627 | 630 | writeSettings(settings) |
| 628 | 631 | settings = readSettings() |
| 629 | 632 | config = loadConfig(settingsEnv(settings)) |