Compare commits

...

3 Commits

Author SHA1 Message Date
syuilo
f9e2cd4088 Merge branch 'develop' into multi-server 2025-03-14 15:44:18 +09:00
syuilo
0929410d36 enhance(frontend): improve pref manager 2025-03-14 15:43:56 +09:00
syuilo
35a3acab42 init 2025-03-14 14:47:43 +09:00
3 changed files with 35 additions and 10 deletions

View File

@@ -91,6 +91,9 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkSwitch v-model="skipNoteRender">
<template #label>Enable note render skipping</template>
</MkSwitch>
<MkSwitch v-model="multiServer">
<template #label>Enable multi server</template>
</MkSwitch>
</div>
</MkFolder>
</SearchMarker>
@@ -142,6 +145,7 @@ const reportError = prefer.model('reportError');
const enableCondensedLine = prefer.model('enableCondensedLine');
const skipNoteRender = prefer.model('skipNoteRender');
const devMode = prefer.model('devMode');
const multiServer = prefer.model('experimental.multiServer');
watch(skipNoteRender, async () => {
await reloadAsk({ reason: i18n.ts.reloadToApplySetting, unison: true });

View File

@@ -355,4 +355,8 @@ export const PREF_DEF = {
sfxVolume: 1,
},
},
'experimental.multiServer': {
default: false,
},
} satisfies PreferencesDefinition;

View File

@@ -23,11 +23,10 @@ import { deepEqual } from '@/utility/deep-equal.js';
type PREF = typeof PREF_DEF;
type ValueOf<K extends keyof PREF> = PREF[K]['default'];
type Account = string; // <host>/<userId>
type Scope = Partial<{
server: string | null; // 将来のため
account: Account | null;
server: string | null; // host
account: string | null; // userId
device: string | null; // 将来のため
}>;
@@ -39,7 +38,7 @@ type PrefRecord<K extends keyof PREF> = [scope: Scope, value: ValueOf<K>, meta:
function parseScope(scope: Scope): {
server: string | null;
account: Account | null;
account: string | null;
device: string | null;
} {
return {
@@ -51,7 +50,7 @@ function parseScope(scope: Scope): {
function makeScope(scope: Partial<{
server: string | null;
account: Account | null;
account: string | null;
device: string | null;
}>): Scope {
const c = {} as Scope;
@@ -130,6 +129,10 @@ export class PreferencesManager {
return (PREF_DEF as PreferencesDefinition)[key].accountDependent === true;
}
private isServerDependentKey<K extends keyof PREF>(key: K): boolean {
return (PREF_DEF as PreferencesDefinition)[key].serverDependent === 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;
@@ -141,9 +144,19 @@ export class PreferencesManager {
this.rewriteRawState(key, value);
const record = this.getMatchedRecordOf(key);
if (parseScope(record[0]).account == null && this.isAccountDependentKey(key)) {
this.profile.preferences[key].push([makeScope({
account: `${host}/${$i!.id}`,
server: host,
account: $i!.id,
}), value, {}]);
this.save();
return;
}
if (parseScope(record[0]).server == null && this.isServerDependentKey(key)) {
this.profile.preferences[key].push([makeScope({
server: host,
}), value, {}]);
this.save();
return;
@@ -291,16 +304,19 @@ export class PreferencesManager {
if ($i == null) return records.find(([scope, v]) => parseScope(scope).account == null)!;
const accountOverrideRecord = records.find(([scope, v]) => parseScope(scope).account === `${host}/${$i!.id}`);
const accountOverrideRecord = records.find(([scope, v]) => parseScope(scope).server === host && parseScope(scope).account === $i!.id);
if (accountOverrideRecord) return accountOverrideRecord;
const serverOverrideRecord = records.find(([scope, v]) => parseScope(scope).server === host && parseScope(scope).account == null);
if (serverOverrideRecord) return serverOverrideRecord;
const record = records.find(([scope, v]) => parseScope(scope).account == null);
return record!;
}
public isAccountOverrided<K extends keyof PREF>(key: K): boolean {
if ($i == null) return false;
return this.profile.preferences[key].some(([scope, v]) => parseScope(scope).account === `${host}/${$i!.id}`) ?? false;
return this.profile.preferences[key].some(([scope, v]) => parseScope(scope).server === host && parseScope(scope).account === $i!.id) ?? false;
}
public setAccountOverride<K extends keyof PREF>(key: K) {
@@ -310,7 +326,8 @@ export class PreferencesManager {
const records = this.profile.preferences[key];
records.push([makeScope({
account: `${host}/${$i!.id}`,
server: host,
account: $i!.id,
}), this.s[key], {}]);
this.save();
@@ -322,7 +339,7 @@ export class PreferencesManager {
const records = this.profile.preferences[key];
const index = records.findIndex(([scope, v]) => parseScope(scope).account === `${host}/${$i!.id}`);
const index = records.findIndex(([scope, v]) => parseScope(scope).server === host && parseScope(scope).account === $i!.id);
if (index === -1) return;
records.splice(index, 1);