summaryrefslogtreecommitdiff
path: root/packages/frontend/src/preferences
diff options
context:
space:
mode:
authorsyuilo <4439005+syuilo@users.noreply.github.com>2025-03-12 20:17:54 +0900
committersyuilo <4439005+syuilo@users.noreply.github.com>2025-03-12 20:17:54 +0900
commit3129fcf164369ecd1ed7fd26e17e0806ada4e435 (patch)
tree804d84439b7f6156981f98d446f694fab979b3e4 /packages/frontend/src/preferences
parentadd todo (diff)
downloadsharkey-3129fcf164369ecd1ed7fd26e17e0806ada4e435.tar.gz
sharkey-3129fcf164369ecd1ed7fd26e17e0806ada4e435.tar.bz2
sharkey-3129fcf164369ecd1ed7fd26e17e0806ada4e435.zip
fix(frontend): fix type errors
Diffstat (limited to 'packages/frontend/src/preferences')
-rw-r--r--packages/frontend/src/preferences/def.ts9
-rw-r--r--packages/frontend/src/preferences/manager.ts (renamed from packages/frontend/src/preferences/profile.ts)30
-rw-r--r--packages/frontend/src/preferences/utility.ts2
3 files changed, 26 insertions, 15 deletions
diff --git a/packages/frontend/src/preferences/def.ts b/packages/frontend/src/preferences/def.ts
index b75b99d6b5..47d0ab5cbc 100644
--- a/packages/frontend/src/preferences/def.ts
+++ b/packages/frontend/src/preferences/def.ts
@@ -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;
diff --git a/packages/frontend/src/preferences/profile.ts b/packages/frontend/src/preferences/manager.ts
index 2ac4e58d14..9866227d93 100644
--- a/packages/frontend/src/preferences/profile.ts
+++ b/packages/frontend/src/preferences/manager.ts
@@ -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]);
}
diff --git a/packages/frontend/src/preferences/utility.ts b/packages/frontend/src/preferences/utility.ts
index fc6eff5f49..c37dbcf96b 100644
--- a/packages/frontend/src/preferences/utility.ts
+++ b/packages/frontend/src/preferences/utility.ts
@@ -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';