fix race conditions and bugs in pref-migrate.ts

This commit is contained in:
Hazelnoot 2025-06-07 20:25:18 -04:00
parent 4085c8a4f1
commit e3668be8f4

View file

@ -20,9 +20,11 @@ export function migrateOldSettings() {
os.waiting(i18n.ts.settingsMigrating);
store.loaded.then(async () => {
misskeyApi('i/registry/get', { scope: ['client'], key: 'themes' }).catch(() => []).then((themes: Theme[]) => {
if (themes.length > 0) {
prefer.commit('themes', themes);
prefer.suppressReload();
await misskeyApi('i/registry/get', { scope: ['client'], key: 'themes' }).catch(() => []).then(themes => {
if (Array.isArray(themes) && themes.length > 0) {
prefer.commit('themes', themes as Theme[]);
}
});
@ -34,7 +36,7 @@ export function migrateOldSettings() {
})));
prefer.commit('deck.profile', deckStore.s.profile);
misskeyApi('i/registry/keys', {
await misskeyApi('i/registry/keys', {
scope: ['client', 'deck', 'profiles'],
}).then(async keys => {
const profiles: DeckProfile[] = [];
@ -42,16 +44,18 @@ export function migrateOldSettings() {
const deck = await misskeyApi('i/registry/get', {
scope: ['client', 'deck', 'profiles'],
key: key,
});
}).catch(() => null);
if (deck) {
profiles.push({
id: uuid(),
name: key,
columns: deck.columns,
layout: deck.layout,
columns: (deck as DeckProfile).columns,
layout: (deck as DeckProfile).layout,
});
}
}
prefer.commit('deck.profiles', profiles);
});
}).catch(() => null);
prefer.commit('lightTheme', ColdDeviceStorage.get('lightTheme'));
prefer.commit('darkTheme', ColdDeviceStorage.get('darkTheme'));
@ -165,9 +169,6 @@ export function migrateOldSettings() {
prefer.commit('warnMissingAltText', store.s.warnMissingAltText);
//#endregion
window.setTimeout(() => {
unisonReload();
}, 10000);
//#region Hybrid migrations
prefer.commit('fontSize', miLocalStorage.getItem('fontSize') ?? '0');
prefer.commit('useSystemFont', miLocalStorage.getItem('useSystemFont') != null);
@ -178,5 +179,7 @@ export function migrateOldSettings() {
prefer.commit('neverShowLocalOnlyInfo', miLocalStorage.getItem('neverShowLocalOnlyInfo') != null);
//#endregion
prefer.allowReload();
unisonReload();
});
}