Unverified 提交 4d7d9ec2 authored 作者: Will Chen's avatar Will Chen 提交者: GitHub

move auto-update to later (#603)

otherwise on windows the settings path (which is based on userData) isn't available yet.
上级 a1aee5c2
......@@ -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({
......
......@@ -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<UserSettings>): 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);
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论