Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
import { useCallback, useEffect, useState } from "react";
|
|
import {
|
|
AGENT_GUI_PROVIDER_RAIL_PREFERENCES_EVENT,
|
|
agentGUIProviderRailOrderStorageKey,
|
|
parseAgentGUIProviderRailPreferences,
|
|
serializeAgentGUIProviderRailPreferences,
|
|
type AgentGUIProviderRailPreferences
|
|
} from "../model/agentGuiProviderRailOrder";
|
|
|
|
function readAgentGUIProviderRailPreferences(
|
|
storageKey: string
|
|
): AgentGUIProviderRailPreferences {
|
|
return parseAgentGUIProviderRailPreferences(
|
|
globalThis.localStorage?.getItem(storageKey)
|
|
);
|
|
}
|
|
|
|
export function useAgentGUIProviderRailPreferences(): {
|
|
persistPreferences: (preferences: AgentGUIProviderRailPreferences) => void;
|
|
preferences: AgentGUIProviderRailPreferences;
|
|
} {
|
|
const storageKey = agentGUIProviderRailOrderStorageKey();
|
|
const [preferences, setPreferences] =
|
|
useState<AgentGUIProviderRailPreferences>(() =>
|
|
readAgentGUIProviderRailPreferences(storageKey)
|
|
);
|
|
|
|
useEffect(() => {
|
|
const refreshPreferences = () => {
|
|
setPreferences(readAgentGUIProviderRailPreferences(storageKey));
|
|
};
|
|
const handleStorage = (event: StorageEvent) => {
|
|
if (event.key === storageKey) {
|
|
refreshPreferences();
|
|
}
|
|
};
|
|
globalThis.addEventListener?.("storage", handleStorage);
|
|
globalThis.addEventListener?.(
|
|
AGENT_GUI_PROVIDER_RAIL_PREFERENCES_EVENT,
|
|
refreshPreferences
|
|
);
|
|
return () => {
|
|
globalThis.removeEventListener?.("storage", handleStorage);
|
|
globalThis.removeEventListener?.(
|
|
AGENT_GUI_PROVIDER_RAIL_PREFERENCES_EVENT,
|
|
refreshPreferences
|
|
);
|
|
};
|
|
}, [storageKey]);
|
|
|
|
const persistPreferences = useCallback(
|
|
(nextPreferences: AgentGUIProviderRailPreferences) => {
|
|
setPreferences(nextPreferences);
|
|
globalThis.localStorage?.setItem(
|
|
storageKey,
|
|
serializeAgentGUIProviderRailPreferences(nextPreferences)
|
|
);
|
|
globalThis.dispatchEvent?.(
|
|
new Event(AGENT_GUI_PROVIDER_RAIL_PREFERENCES_EVENT)
|
|
);
|
|
},
|
|
[storageKey]
|
|
);
|
|
|
|
return { persistPreferences, preferences };
|
|
}
|