Skip to content

[Cleanup] Centralize getSettings() IPC calls into a shared store #343

@samzong

Description

@samzong

Problem

window.clawwork.getSettings() is called independently in 4 separate files, each fetching and parsing the full settings object on mount. There is no centralized cache — settings changes in one component do not propagate to others.

Location

Files:

  • packages/desktop/src/renderer/App.tsx:91 — reads sendShortcut, leftNavShortcut, rightPanelShortcut, devMode
  • packages/desktop/src/renderer/layouts/Settings/sections/GeneralSection.tsx:88 — reads notifications
  • packages/desktop/src/renderer/layouts/Settings/sections/SystemSection.tsx:26 — reads quickLaunch settings
  • packages/desktop/src/renderer/layouts/Settings/components/PairMobileDialog.tsx:71 — reads gateways config

Each component does:

useEffect(() => {
  window.clawwork.getSettings().then((settings) => {
    if (!settings) return;
    // parse specific fields...
  });
}, []);

Fix Approach

Create useSettingsStore (Zustand):

export const useSettingsStore = create<SettingsState>((set, get) => ({
  settings: null,
  loaded: false,
  load: async () => {
    const s = await window.clawwork.getSettings();
    set({ settings: s, loaded: true });
  },
  update: async (patch) => {
    await window.clawwork.updateSettings(patch);
    set((state) => ({ settings: { ...state.settings!, ...patch } }));
  },
}));
  • Call load() once in App.tsx on startup
  • Components read via selector: useSettingsStore((s) => s.settings?.notifications)
  • Mutations via update() propagate to all consumers

Verification

  1. Run pnpm check — must pass
  2. Change a setting, verify it takes effect immediately in all sections

Context

  • WG: UI & Design System
  • Priority: Medium
  • Estimated effort: ~1 hour

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/uiUI & Design System WGkind/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