1
0
Fork 0
mirror of https://github.com/paricafe/misskey.git synced 2025-03-22 16:59:24 -05:00

fix(frontend): fix type errors

This commit is contained in:
syuilo 2025-03-12 20:17:54 +09:00
parent 35a4544477
commit 3129fcf164
4 changed files with 28 additions and 17 deletions
packages/frontend/src

View file

@ -4,10 +4,10 @@
*/
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 { 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 { $i } from '@/account.js';
import { misskeyApi } from '@/utility/misskey-api.js';

View file

@ -9,7 +9,8 @@ import type { Theme } from '@/theme.js';
import type { SoundType } from '@/utility/sound.js';
import type { Plugin } from '@/plugin.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';
/** サウンド設定 */
@ -324,8 +325,4 @@ export const PREF_DEF = {
sfxVolume: 1,
},
},
} satisfies Record<string, {
default: any;
accountDependent?: boolean;
serverDependent?: boolean;
}>;
} satisfies PreferencesDefinition;

View file

@ -84,6 +84,12 @@ export type StorageProvider = {
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 {
private storageProvider: StorageProvider;
public profile: PreferencesProfile;
@ -118,6 +124,10 @@ export class ProfileManager {
// 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>) {
const v = JSON.parse(JSON.stringify(value)); // deep copy 兼 vueのプロキシ解除
this.r[key].value = this.s[key] = v;
@ -129,7 +139,7 @@ export class ProfileManager {
this.rewriteRawState(key, value);
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({
account: `${host}/${$i!.id}`,
}), value, {}]);
@ -186,9 +196,10 @@ export class ProfileManager {
private genStates() {
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);
states[key] = record[1];
(states[key] as any) = record[1];
}
return states;
@ -196,7 +207,8 @@ export class ProfileManager {
private async fetchCloudValues() {
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);
if (record[2].sync) {
needs.push({
@ -208,7 +220,8 @@ export class ProfileManager {
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);
if (record[2].sync && Object.hasOwn(cloudValues, key) && cloudValues[key] !== undefined) {
const cloudValue = cloudValues[key];
@ -290,7 +303,7 @@ export class ProfileManager {
public setAccountOverride<K extends keyof PREF>(key: K) {
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;
const records = this.profile.preferences[key];
@ -303,7 +316,7 @@ export class ProfileManager {
public clearAccountOverride<K extends keyof PREF>(key: K) {
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];
@ -377,7 +390,8 @@ export class ProfileManager {
public rewriteProfile(profile: PreferencesProfile) {
this.profile = profile;
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]);
}

View file

@ -4,7 +4,7 @@
*/
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 { copyToClipboard } from '@/utility/copy-to-clipboard.js';
import { i18n } from '@/i18n.js';