fix(frontend): fix type errors
This commit is contained in:
parent
35a4544477
commit
3129fcf164
|
@ -4,10 +4,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
import type { PreferencesProfile, StorageProvider } from '@/preferences/profile.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/profile.js';
|
import { isSameCond, ProfileManager } 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';
|
||||||
|
|
|
@ -9,7 +9,8 @@ import type { Theme } from '@/theme.js';
|
||||||
import type { SoundType } from '@/utility/sound.js';
|
import type { SoundType } from '@/utility/sound.js';
|
||||||
import type { Plugin } from '@/plugin.js';
|
import type { Plugin } from '@/plugin.js';
|
||||||
import type { DeviceKind } from '@/utility/device-kind.js';
|
import type { DeviceKind } from '@/utility/device-kind.js';
|
||||||
import type { Column, DeckProfile } from '@/deck.js';
|
import type { DeckProfile } from '@/deck.js';
|
||||||
|
import type { PreferencesDefinition } from './manager.js';
|
||||||
import { DEFAULT_DEVICE_KIND } from '@/utility/device-kind.js';
|
import { DEFAULT_DEVICE_KIND } from '@/utility/device-kind.js';
|
||||||
|
|
||||||
/** サウンド設定 */
|
/** サウンド設定 */
|
||||||
|
@ -324,8 +325,4 @@ export const PREF_DEF = {
|
||||||
sfxVolume: 1,
|
sfxVolume: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} satisfies Record<string, {
|
} satisfies PreferencesDefinition;
|
||||||
default: any;
|
|
||||||
accountDependent?: boolean;
|
|
||||||
serverDependent?: boolean;
|
|
||||||
}>;
|
|
||||||
|
|
|
@ -84,6 +84,12 @@ export type StorageProvider = {
|
||||||
cloudSet: <K extends keyof PREF>(ctx: { key: K; cond: Cond; value: ValueOf<K>; }) => Promise<void>;
|
cloudSet: <K extends keyof PREF>(ctx: { key: K; cond: Cond; value: ValueOf<K>; }) => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type PreferencesDefinition = Record<string, {
|
||||||
|
default: any;
|
||||||
|
accountDependent?: boolean;
|
||||||
|
serverDependent?: boolean;
|
||||||
|
}>;
|
||||||
|
|
||||||
export class ProfileManager {
|
export class ProfileManager {
|
||||||
private storageProvider: StorageProvider;
|
private storageProvider: StorageProvider;
|
||||||
public profile: PreferencesProfile;
|
public profile: PreferencesProfile;
|
||||||
|
@ -118,6 +124,10 @@ export class ProfileManager {
|
||||||
// TODO: 定期的にクラウドの値をフェッチ
|
// TODO: 定期的にクラウドの値をフェッチ
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isAccountDependentKey<K extends keyof PREF>(key: K): boolean {
|
||||||
|
return (PREF_DEF as PreferencesDefinition)[key].accountDependent === true;
|
||||||
|
}
|
||||||
|
|
||||||
private rewriteRawState<K extends keyof PREF>(key: K, value: ValueOf<K>) {
|
private rewriteRawState<K extends keyof PREF>(key: K, value: ValueOf<K>) {
|
||||||
const v = JSON.parse(JSON.stringify(value)); // deep copy 兼 vueのプロキシ解除
|
const v = JSON.parse(JSON.stringify(value)); // deep copy 兼 vueのプロキシ解除
|
||||||
this.r[key].value = this.s[key] = v;
|
this.r[key].value = this.s[key] = v;
|
||||||
|
@ -129,7 +139,7 @@ export class ProfileManager {
|
||||||
this.rewriteRawState(key, value);
|
this.rewriteRawState(key, value);
|
||||||
|
|
||||||
const record = this.getMatchedRecordOf(key);
|
const record = this.getMatchedRecordOf(key);
|
||||||
if (parseCond(record[0]).account == null && PREF_DEF[key].accountDependent) {
|
if (parseCond(record[0]).account == null && this.isAccountDependentKey(key)) {
|
||||||
this.profile.preferences[key].push([makeCond({
|
this.profile.preferences[key].push([makeCond({
|
||||||
account: `${host}/${$i!.id}`,
|
account: `${host}/${$i!.id}`,
|
||||||
}), value, {}]);
|
}), value, {}]);
|
||||||
|
@ -186,9 +196,10 @@ export class ProfileManager {
|
||||||
|
|
||||||
private genStates() {
|
private genStates() {
|
||||||
const states = {} as { [K in keyof PREF]: ValueOf<K> };
|
const states = {} as { [K in keyof PREF]: ValueOf<K> };
|
||||||
for (const key in PREF_DEF) {
|
for (const _key in PREF_DEF) {
|
||||||
|
const key = _key as keyof PREF;
|
||||||
const record = this.getMatchedRecordOf(key);
|
const record = this.getMatchedRecordOf(key);
|
||||||
states[key] = record[1];
|
(states[key] as any) = record[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return states;
|
return states;
|
||||||
|
@ -196,7 +207,8 @@ export class ProfileManager {
|
||||||
|
|
||||||
private async fetchCloudValues() {
|
private async fetchCloudValues() {
|
||||||
const needs = [] as { key: keyof PREF; cond: Cond; }[];
|
const needs = [] as { key: keyof PREF; cond: Cond; }[];
|
||||||
for (const key in PREF_DEF) {
|
for (const _key in PREF_DEF) {
|
||||||
|
const key = _key as keyof PREF;
|
||||||
const record = this.getMatchedRecordOf(key);
|
const record = this.getMatchedRecordOf(key);
|
||||||
if (record[2].sync) {
|
if (record[2].sync) {
|
||||||
needs.push({
|
needs.push({
|
||||||
|
@ -208,7 +220,8 @@ export class ProfileManager {
|
||||||
|
|
||||||
const cloudValues = await this.storageProvider.cloudGets({ needs });
|
const cloudValues = await this.storageProvider.cloudGets({ needs });
|
||||||
|
|
||||||
for (const key in PREF_DEF) {
|
for (const _key in PREF_DEF) {
|
||||||
|
const key = _key as keyof PREF;
|
||||||
const record = this.getMatchedRecordOf(key);
|
const record = this.getMatchedRecordOf(key);
|
||||||
if (record[2].sync && Object.hasOwn(cloudValues, key) && cloudValues[key] !== undefined) {
|
if (record[2].sync && Object.hasOwn(cloudValues, key) && cloudValues[key] !== undefined) {
|
||||||
const cloudValue = cloudValues[key];
|
const cloudValue = cloudValues[key];
|
||||||
|
@ -290,7 +303,7 @@ export class ProfileManager {
|
||||||
|
|
||||||
public setAccountOverride<K extends keyof PREF>(key: K) {
|
public setAccountOverride<K extends keyof PREF>(key: K) {
|
||||||
if ($i == null) return;
|
if ($i == null) return;
|
||||||
if (PREF_DEF[key].accountDependent) throw new Error('already account-dependent');
|
if (this.isAccountDependentKey(key)) throw new Error('already account-dependent');
|
||||||
if (this.isAccountOverrided(key)) return;
|
if (this.isAccountOverrided(key)) return;
|
||||||
|
|
||||||
const records = this.profile.preferences[key];
|
const records = this.profile.preferences[key];
|
||||||
|
@ -303,7 +316,7 @@ export class ProfileManager {
|
||||||
|
|
||||||
public clearAccountOverride<K extends keyof PREF>(key: K) {
|
public clearAccountOverride<K extends keyof PREF>(key: K) {
|
||||||
if ($i == null) return;
|
if ($i == null) return;
|
||||||
if (PREF_DEF[key].accountDependent) throw new Error('cannot clear override for this account-dependent property');
|
if (this.isAccountDependentKey(key)) throw new Error('cannot clear override for this account-dependent property');
|
||||||
|
|
||||||
const records = this.profile.preferences[key];
|
const records = this.profile.preferences[key];
|
||||||
|
|
||||||
|
@ -377,7 +390,8 @@ export class ProfileManager {
|
||||||
public rewriteProfile(profile: PreferencesProfile) {
|
public rewriteProfile(profile: PreferencesProfile) {
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
const states = this.genStates();
|
const states = this.genStates();
|
||||||
for (const key in states) {
|
for (const _key in states) {
|
||||||
|
const key = _key as keyof PREF;
|
||||||
this.rewriteRawState(key, states[key]);
|
this.rewriteRawState(key, states[key]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ref, watch } from 'vue';
|
import { ref, watch } from 'vue';
|
||||||
import type { PreferencesProfile } from './profile.js';
|
import type { PreferencesProfile } from './manager.js';
|
||||||
import type { MenuItem } from '@/types/menu.js';
|
import type { MenuItem } from '@/types/menu.js';
|
||||||
import { copyToClipboard } from '@/utility/copy-to-clipboard.js';
|
import { copyToClipboard } from '@/utility/copy-to-clipboard.js';
|
||||||
import { i18n } from '@/i18n.js';
|
import { i18n } from '@/i18n.js';
|
||||||
|
|
Loading…
Reference in New Issue