feat: globalize Magic Notes and improve runtime tools

This commit is contained in:
lofyer
2026-08-10 10:27:14 +08:00
parent 1a8e110866
commit 5ea022ad5c
47 changed files with 2442 additions and 1177 deletions
+27 -5
View File
@@ -19,7 +19,7 @@ export {
} from '../shared/application-settings-contracts'
export type { ApplicationSettings } from '../shared/application-settings-contracts'
const CURRENT_SETTINGS_VERSION = 2
const CURRENT_SETTINGS_VERSION = 3
const legacyStoredApplicationSettingsSchema = z
.object({
@@ -28,6 +28,14 @@ const legacyStoredApplicationSettingsSchema = z
})
.strict()
const versionTwoStoredApplicationSettingsSchema = z
.object({
version: z.literal(2),
checkUpdatesOnStartup: z.boolean(),
magicNotesEnabled: z.boolean()
})
.strict()
const storedApplicationSettingsSchema = applicationSettingsSchema
.extend({
version: z.literal(CURRENT_SETTINGS_VERSION)
@@ -40,7 +48,8 @@ type StoredApplicationSettings = z.infer<
export const defaultApplicationSettings: ApplicationSettings = {
checkUpdatesOnStartup: true,
magicNotesEnabled: false
magicNotesEnabled: false,
magicNoteCommentMode: 'immediate'
}
function isMissingFile(error: unknown): boolean {
@@ -93,6 +102,16 @@ export class ApplicationSettingsStore {
}
const result = storedApplicationSettingsSchema.safeParse(parsed)
if (!result.success) {
const versionTwoResult =
versionTwoStoredApplicationSettingsSchema.safeParse(parsed)
if (versionTwoResult.success) {
this.settings = {
...versionTwoResult.data,
version: CURRENT_SETTINGS_VERSION,
magicNoteCommentMode: 'immediate'
}
return this.settings
}
const legacyResult =
legacyStoredApplicationSettingsSchema.safeParse(parsed)
if (legacyResult.success) {
@@ -100,7 +119,8 @@ export class ApplicationSettingsStore {
version: CURRENT_SETTINGS_VERSION,
checkUpdatesOnStartup:
legacyResult.data.checkUpdatesOnStartup,
magicNotesEnabled: false
magicNotesEnabled: false,
magicNoteCommentMode: 'immediate'
}
return this.settings
}
@@ -130,7 +150,8 @@ export class ApplicationSettingsStore {
const stored = await this.loadStored()
return {
checkUpdatesOnStartup: stored.checkUpdatesOnStartup,
magicNotesEnabled: stored.magicNotesEnabled
magicNotesEnabled: stored.magicNotesEnabled,
magicNoteCommentMode: stored.magicNoteCommentMode
}
}
@@ -164,7 +185,8 @@ export class ApplicationSettingsStore {
this.settings = next
return {
checkUpdatesOnStartup: next.checkUpdatesOnStartup,
magicNotesEnabled: next.magicNotesEnabled
magicNotesEnabled: next.magicNotesEnabled,
magicNoteCommentMode: next.magicNoteCommentMode
}
})
this.updateQueue = operation.then(