interfaceMode.ts 589 B

1234567891011121314
  1. export type InterfaceMode = 'chat' | 'bots'
  2. const KEY = 'hermes-yaoyao:interface-mode'
  3. export function savedInterfacePath(): '/chat' | '/conversations' {
  4. try { return localStorage.getItem(KEY) === 'chat' ? '/chat' : '/conversations' }
  5. catch { return '/conversations' }
  6. }
  7. export function rememberInterfacePath(path: string): void {
  8. const mode: InterfaceMode | undefined = /^\/conversations(?:\/|$)/.test(path) ? 'bots'
  9. : /^\/chat(?:\/|$)/.test(path) ? 'chat' : undefined
  10. if (!mode) return
  11. try { localStorage.setItem(KEY, mode) } catch { /* storage may be unavailable */ }
  12. }