mirror of
https://github.com/getpaseo/paseo.git
synced 2026-12-04 06:06:26 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
876f6d53a8 |
@@ -239,7 +239,7 @@ describe("desktop-settings", () => {
|
||||
expect(persisted.settings.daemon.manageBuiltInDaemon).toBe(false);
|
||||
});
|
||||
|
||||
it("does not rewrite existing settings while reading them", async () => {
|
||||
it("does not rewrite migrated settings while reading them", async () => {
|
||||
const userDataPath = await createTempUserDataDir();
|
||||
directories.add(userDataPath);
|
||||
const raw = JSON.stringify({
|
||||
@@ -253,6 +253,7 @@ describe("desktop-settings", () => {
|
||||
},
|
||||
migrations: {
|
||||
legacyRendererSettingsImported: false,
|
||||
daemonStopOnQuitDefaultApplied: true,
|
||||
},
|
||||
});
|
||||
await writeFile(settingsFilePath(userDataPath), raw);
|
||||
@@ -265,7 +266,7 @@ describe("desktop-settings", () => {
|
||||
expect(persisted).toBe(raw);
|
||||
});
|
||||
|
||||
it("resets the pre-existing keep-running default so the daemon stops with the app", async () => {
|
||||
it("persists the stop-on-quit migration on the first read", async () => {
|
||||
const userDataPath = await createTempUserDataDir();
|
||||
directories.add(userDataPath);
|
||||
await writeFile(
|
||||
@@ -276,7 +277,7 @@ describe("desktop-settings", () => {
|
||||
releaseChannel: "stable",
|
||||
daemon: { manageBuiltInDaemon: true, keepRunningAfterQuit: true },
|
||||
},
|
||||
migrations: { legacyRendererSettingsImported: true },
|
||||
futureSetting: { value: 7 },
|
||||
}),
|
||||
);
|
||||
const store = createDesktopSettingsStore({ userDataPath });
|
||||
@@ -284,6 +285,12 @@ describe("desktop-settings", () => {
|
||||
const settings = await store.get();
|
||||
|
||||
expect(settings.daemon.keepRunningAfterQuit).toBe(false);
|
||||
const persisted = JSON.parse(await readFile(settingsFilePath(userDataPath), "utf8"));
|
||||
expect(persisted).toMatchObject({
|
||||
settings: { daemon: { manageBuiltInDaemon: true, keepRunningAfterQuit: false } },
|
||||
migrations: { daemonStopOnQuitDefaultApplied: true },
|
||||
futureSetting: { value: 7 },
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps an explicit keep-running choice across restarts", async () => {
|
||||
|
||||
@@ -238,12 +238,9 @@ function hasLegacyRendererOwnedPatch(patch: DesktopSettingsPatch): boolean {
|
||||
return patch.releaseChannel !== undefined || patch.daemon?.manageBuiltInDaemon !== undefined;
|
||||
}
|
||||
|
||||
function coerceDocument(input: unknown): PersistedDesktopSettingsDocument {
|
||||
const document = PersistedDocumentSchema.parse(input);
|
||||
if (document.migrations.daemonStopOnQuitDefaultApplied) {
|
||||
return document;
|
||||
}
|
||||
|
||||
function applyDaemonStopOnQuitDefault(
|
||||
document: PersistedDesktopSettingsDocument,
|
||||
): PersistedDesktopSettingsDocument {
|
||||
return {
|
||||
...document,
|
||||
settings: {
|
||||
@@ -283,45 +280,39 @@ export function createDesktopSettingsStore({
|
||||
cachedDocument = document;
|
||||
}
|
||||
|
||||
async function loadDocumentUnlocked(): Promise<PersistedDesktopSettingsDocument> {
|
||||
async function loadDocumentUnlocked({
|
||||
recoverUnreadable = false,
|
||||
} = {}): Promise<PersistedDesktopSettingsDocument> {
|
||||
if (cachedDocument) {
|
||||
return cachedDocument;
|
||||
}
|
||||
|
||||
let raw: string;
|
||||
let document: PersistedDesktopSettingsDocument;
|
||||
try {
|
||||
raw = await readFile(filePath, "utf8");
|
||||
const raw = await readFile(filePath, "utf8");
|
||||
document = PersistedDocumentSchema.parse(JSON.parse(raw));
|
||||
} catch (error) {
|
||||
if (!isNodeError(error) || error.code !== "ENOENT") {
|
||||
if (!recoverUnreadable && (!isNodeError(error) || error.code !== "ENOENT")) {
|
||||
throw error;
|
||||
}
|
||||
const document = buildDefaultDocument();
|
||||
await writeDocument(document);
|
||||
return document;
|
||||
const defaults = buildDefaultDocument();
|
||||
await writeDocument(defaults);
|
||||
return defaults;
|
||||
}
|
||||
const document = coerceDocument(JSON.parse(raw));
|
||||
|
||||
if (!document.migrations.daemonStopOnQuitDefaultApplied) {
|
||||
const migrated = applyDaemonStopOnQuitDefault(document);
|
||||
await writeDocument(migrated);
|
||||
return migrated;
|
||||
}
|
||||
|
||||
cachedDocument = document;
|
||||
return document;
|
||||
}
|
||||
|
||||
async function initializeLegacyRendererMigrationUnlocked(): Promise<PersistedDesktopSettingsDocument> {
|
||||
try {
|
||||
return await loadDocumentUnlocked();
|
||||
} catch {
|
||||
const document = buildDefaultDocument();
|
||||
await writeDocument(document);
|
||||
return document;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
async get(): Promise<DesktopSettings> {
|
||||
const document = await enqueueOperation(async () => {
|
||||
if (cachedDocument) {
|
||||
return cachedDocument;
|
||||
}
|
||||
return loadDocumentUnlocked();
|
||||
});
|
||||
const document = await enqueueOperation(() => loadDocumentUnlocked());
|
||||
return toDesktopSettings(document.settings);
|
||||
},
|
||||
|
||||
@@ -346,7 +337,7 @@ export function createDesktopSettingsStore({
|
||||
|
||||
async migrateLegacyRendererSettings(legacySettings: unknown): Promise<DesktopSettings> {
|
||||
return enqueueOperation(async () => {
|
||||
const current = await initializeLegacyRendererMigrationUnlocked();
|
||||
const current = await loadDocumentUnlocked({ recoverUnreadable: true });
|
||||
if (current.migrations.legacyRendererSettingsImported) {
|
||||
return toDesktopSettings(current.settings);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user