Skip to content

[Cleanup] Extract repeated typeof IPC guard checks in useContextFolders #344

@samzong

Description

@samzong

Problem

useContextFolders.ts contains 7 separate typeof window.clawwork.xxx === 'function' checks for the same set of IPC methods:

Location

File: packages/desktop/src/renderer/components/ChatInput/useContextFolders.ts

// Line 17
if (typeof window.clawwork.unwatchContextFolder === 'function') { ... }
// Line 22
if (typeof window.clawwork.watchContextFolder === 'function') { ... }
// Line 35
if (typeof window.clawwork.unwatchContextFolder === 'function') { ... }
// Line 43
if (typeof window.clawwork.selectContextFolder !== 'function' || typeof window.clawwork.watchContextFolder !== 'function') { return; }
// Line 63
if (typeof window.clawwork.unwatchContextFolder === 'function') { ... }
// Line 82
if (typeof window.clawwork.listContextFiles !== 'function') { ... }

Fix Approach

Option A: Check once at the top of the hook:

const isContextFolderApiAvailable =
  typeof window.clawwork.unwatchContextFolder === 'function' &&
  typeof window.clawwork.watchContextFolder === 'function' &&
  typeof window.clawwork.selectContextFolder === 'function' &&
  typeof window.clawwork.listContextFiles === 'function';

Then use the single boolean in all branches.

Option B: If the API always exists (check preload types), remove all guards entirely and trust the TypeScript declarations.

Verification

  1. Run pnpm check — must pass
  2. Add a context folder, remove it, switch tasks — verify watch/unwatch still works

Context

  • WG: UI & Design System
  • Priority: Low (good first issue)
  • Estimated effort: ~10 minutes

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/uiUI & Design System WGgood first issueGood for newcomerskind/cleanupCategorizes issue or PR as related to code cleanup

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions