refactor
This commit is contained in:
parent
9876ff9a7a
commit
8593aa1418
|
@ -7,25 +7,25 @@ import { v4 as uuid } from 'uuid';
|
||||||
import type { PreferencesProfile, StorageProvider } from '@/preferences/manager.js';
|
import type { PreferencesProfile, StorageProvider } from '@/preferences/manager.js';
|
||||||
import { cloudBackup } from '@/preferences/utility.js';
|
import { cloudBackup } from '@/preferences/utility.js';
|
||||||
import { miLocalStorage } from '@/local-storage.js';
|
import { miLocalStorage } from '@/local-storage.js';
|
||||||
import { isSameCond, ProfileManager } from '@/preferences/manager.js';
|
import { isSameCond, PreferencesManager } from '@/preferences/manager.js';
|
||||||
import { store } from '@/store.js';
|
import { store } from '@/store.js';
|
||||||
import { $i } from '@/account.js';
|
import { $i } from '@/account.js';
|
||||||
import { misskeyApi } from '@/utility/misskey-api.js';
|
import { misskeyApi } from '@/utility/misskey-api.js';
|
||||||
|
|
||||||
const TAB_ID = uuid();
|
const TAB_ID = uuid();
|
||||||
|
|
||||||
function createProfileManager(storageProvider: StorageProvider) {
|
function createPrefManager(storageProvider: StorageProvider) {
|
||||||
let profile: PreferencesProfile;
|
let profile: PreferencesProfile;
|
||||||
|
|
||||||
const savedProfileRaw = miLocalStorage.getItem('preferences');
|
const savedProfileRaw = miLocalStorage.getItem('preferences');
|
||||||
if (savedProfileRaw == null) {
|
if (savedProfileRaw == null) {
|
||||||
profile = ProfileManager.newProfile();
|
profile = PreferencesManager.newProfile();
|
||||||
miLocalStorage.setItem('preferences', JSON.stringify(profile));
|
miLocalStorage.setItem('preferences', JSON.stringify(profile));
|
||||||
} else {
|
} else {
|
||||||
profile = ProfileManager.normalizeProfile(JSON.parse(savedProfileRaw));
|
profile = PreferencesManager.normalizeProfile(JSON.parse(savedProfileRaw));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ProfileManager(profile, storageProvider);
|
return new PreferencesManager(profile, storageProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
const syncGroup = 'default';
|
const syncGroup = 'default';
|
||||||
|
@ -104,7 +104,7 @@ const storageProvider: StorageProvider = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const prefer = createProfileManager(storageProvider);
|
export const prefer = createPrefManager(storageProvider);
|
||||||
|
|
||||||
let latestSyncedAt = Date.now();
|
let latestSyncedAt = Date.now();
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ function syncBetweenTabs() {
|
||||||
if (latestTab === TAB_ID) return;
|
if (latestTab === TAB_ID) return;
|
||||||
if (latestAt <= latestSyncedAt) return;
|
if (latestAt <= latestSyncedAt) return;
|
||||||
|
|
||||||
prefer.rewriteProfile(ProfileManager.normalizeProfile(JSON.parse(miLocalStorage.getItem('preferences')!)));
|
prefer.rewriteProfile(PreferencesManager.normalizeProfile(JSON.parse(miLocalStorage.getItem('preferences')!)));
|
||||||
|
|
||||||
latestSyncedAt = Date.now();
|
latestSyncedAt = Date.now();
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ export type PreferencesDefinition = Record<string, {
|
||||||
serverDependent?: boolean;
|
serverDependent?: boolean;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export class ProfileManager {
|
export class PreferencesManager {
|
||||||
private storageProvider: StorageProvider;
|
private storageProvider: StorageProvider;
|
||||||
public profile: PreferencesProfile;
|
public profile: PreferencesProfile;
|
||||||
public cloudReady: Promise<void>;
|
public cloudReady: Promise<void>;
|
||||||
|
|
Loading…
Reference in New Issue