From 4d7d9ec2a67a4545ebabfad5fa0f298684b674c4 Mon Sep 17 00:00:00 2001 From: Will Chen Date: Tue, 8 Jul 2025 13:48:34 -0700 Subject: [PATCH] move auto-update to later (#603) otherwise on windows the settings path (which is based on userData) isn't available yet. --- src/main.ts | 47 +++++++++++++++++++++----------------------- src/main/settings.ts | 7 +++++-- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main.ts b/src/main.ts index eb37c99..14d321c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,6 +16,7 @@ import { handleDyadProReturn } from "./main/pro"; import { IS_TEST_BUILD } from "./ipc/utils/test_utils"; import { BackupManager } from "./backup_manager"; import { getDatabasePath, initializeDatabase } from "./db"; +import { UserSettings } from "./lib/schemas"; log.errorHandler.startCatching(); log.eventLogger.startLogging(); @@ -23,24 +24,6 @@ log.scope.labelPadding = false; const logger = log.scope("main"); -// Check settings before enabling auto-update -const settings = readSettings(); -if (settings.enableAutoUpdate) { - // Technically we could just pass the releaseChannel directly to the host, - // but this is more explicit and falls back to stable if there's an unknown - // release channel. - const postfix = settings.releaseChannel === "beta" ? "beta" : "stable"; - const host = `https://api.dyad.sh/v1/update/${postfix}`; - updateElectronApp({ - logger, - updateSource: { - type: UpdateSourceType.ElectronPublicUpdateService, - repo: "dyad-sh/dyad", - host, - }, - }); // additional configuration options available -} - // Load environment variables from .env file dotenv.config(); @@ -74,16 +57,30 @@ export async function onReady() { logger.error("Error initializing backup manager", e); } initializeDatabase(); - await onFirstRunMaybe(); + const settings = readSettings(); + await onFirstRunMaybe(settings); createWindow(); + + logger.info("Auto-update enabled=", settings.enableAutoUpdate); + if (settings.enableAutoUpdate) { + // Technically we could just pass the releaseChannel directly to the host, + // but this is more explicit and falls back to stable if there's an unknown + // release channel. + const postfix = settings.releaseChannel === "beta" ? "beta" : "stable"; + const host = `https://api.dyad.sh/v1/update/${postfix}`; + logger.info("Auto-update release channel=", postfix); + updateElectronApp({ + logger, + updateSource: { + type: UpdateSourceType.ElectronPublicUpdateService, + repo: "dyad-sh/dyad", + host, + }, + }); // additional configuration options available + } } -/** - * Is this the first run of Fiddle? If so, perform - * tasks that we only want to do in this case. - */ -export async function onFirstRunMaybe() { - const settings = readSettings(); +export async function onFirstRunMaybe(settings: UserSettings) { if (!settings.hasRunBefore) { await promptMoveToApplicationsFolder(); writeSettings({ diff --git a/src/main/settings.ts b/src/main/settings.ts index 0b29802..2f21208 100644 --- a/src/main/settings.ts +++ b/src/main/settings.ts @@ -4,6 +4,9 @@ import { getUserDataPath } from "../paths/paths"; import { UserSettingsSchema, type UserSettings, Secret } from "../lib/schemas"; import { safeStorage } from "electron"; import { v4 as uuidv4 } from "uuid"; +import log from "electron-log"; + +const logger = log.scope("settings"); // IF YOU NEED TO UPDATE THIS, YOU'RE PROBABLY DOING SOMETHING WRONG! // Need to maintain backwards compatibility! @@ -87,7 +90,7 @@ export function readSettings(): UserSettings { return validatedSettings; } catch (error) { - console.error("Error reading settings:", error); + logger.error("Error reading settings:", error); return DEFAULT_SETTINGS; } } @@ -124,7 +127,7 @@ export function writeSettings(settings: Partial): void { const validatedSettings = UserSettingsSchema.parse(newSettings); fs.writeFileSync(filePath, JSON.stringify(validatedSettings, null, 2)); } catch (error) { - console.error("Error writing settings:", error); + logger.error("Error writing settings:", error); } }