feat(p11): temps réel complet (watcher checkout principal + topic settings)
P11-A — branche du checkout principal modifiée hors Arboretum : - fs-watcher: pin « permanent » non évinçable (pinRepo/unpinRepo, repoPins dans evictIfNeeded) - worktree-manager: armMainCheckoutWatchers() + arm/désarm sur addRepo/découverte/removeRepo/hidden - index.ts: armMainCheckoutWatchers() dans runDaemon → git checkout CLI sur le principal → worktree_update <500ms sans watch client P11-B — réglages en temps réel : - protocole additif: type SettingsBroadcast (source unique, réutilisé par SettingsResponse), topic 'settings', message settings_update (validés parseClientMessage + gateway) - core/settings-bus.ts (EventEmitter) ; routes/settings émet après PATCH ; gateway relaie aux abonnés 'settings' - web: ws-client subscribeSettings + routage ; store settings applySettings/startRealtime ; AppShell abonne globalement ; SettingsView re-sync des drafts scalaires sans écraser une saisie en cours - tests: protocol (topic settings) + fs-watcher (pinRepo non évincé) ; acceptance-p11.mjs (checkout principal <500ms + settings_update)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import type { ServerInfo, SettingsResponse, UpdateSettingsRequest } from '@arboretum/shared';
|
||||
import type { ServerInfo, SettingsBroadcast, SettingsResponse, UpdateSettingsRequest } from '@arboretum/shared';
|
||||
import { api } from '../lib/api';
|
||||
import { wsClient } from '../lib/ws-client';
|
||||
|
||||
// Réglages serveur (découverte des dépôts, infos serveur).
|
||||
// Les préférences purement client (langue) restent gérées par l'i18n/localStorage.
|
||||
@@ -15,18 +16,33 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
const purgeDays = ref(0);
|
||||
const loaded = ref(false);
|
||||
const saving = ref(false);
|
||||
let unsubscribe: (() => void) | null = null;
|
||||
|
||||
/** Applique le sous-objet `settings` (utilisé par GET/PATCH ET par le push WS settings_update). */
|
||||
function applySettings(s: SettingsBroadcast): void {
|
||||
scanRoots.value = s.scanRoots;
|
||||
scanIntervalMin.value = s.scanIntervalMin;
|
||||
claudeBinPath.value = s.claudeBinPath;
|
||||
claudeHome.value = s.claudeHome;
|
||||
retentionDays.value = s.retentionDays;
|
||||
purgeDays.value = s.purgeDays;
|
||||
}
|
||||
|
||||
function apply(res: SettingsResponse): void {
|
||||
server.value = res.server;
|
||||
scanRoots.value = res.settings.scanRoots;
|
||||
scanIntervalMin.value = res.settings.scanIntervalMin;
|
||||
claudeBinPath.value = res.settings.claudeBinPath;
|
||||
claudeHome.value = res.settings.claudeHome;
|
||||
retentionDays.value = res.settings.retentionDays;
|
||||
purgeDays.value = res.settings.purgeDays;
|
||||
applySettings(res.settings);
|
||||
loaded.value = true;
|
||||
}
|
||||
|
||||
// P11 — temps réel : un PATCH /settings d'un autre client/onglet rafraîchit le store ici.
|
||||
function startRealtime(): void {
|
||||
unsubscribe ??= wsClient.subscribeSettings((e) => applySettings(e.settings));
|
||||
}
|
||||
function stopRealtime(): void {
|
||||
unsubscribe?.();
|
||||
unsubscribe = null;
|
||||
}
|
||||
|
||||
async function fetch(): Promise<void> {
|
||||
apply(await api.get<SettingsResponse>('/api/v1/settings'));
|
||||
}
|
||||
@@ -40,5 +56,5 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
}
|
||||
}
|
||||
|
||||
return { server, scanRoots, scanIntervalMin, claudeBinPath, claudeHome, retentionDays, purgeDays, loaded, saving, fetch, save };
|
||||
return { server, scanRoots, scanIntervalMin, claudeBinPath, claudeHome, retentionDays, purgeDays, loaded, saving, fetch, save, startRealtime, stopRealtime };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user