Skip to content

ISSUE - 1369: BUG FIX: Settings page does not update active YOLO model after changing it in Model Manager#1371

Open
Takitxt wants to merge 2 commits into
AOSSIE-Org:mainfrom
Takitxt:fix-preferences-sync
Open

ISSUE - 1369: BUG FIX: Settings page does not update active YOLO model after changing it in Model Manager#1371
Takitxt wants to merge 2 commits into
AOSSIE-Org:mainfrom
Takitxt:fix-preferences-sync

Conversation

@Takitxt

@Takitxt Takitxt commented Jul 9, 2026

Copy link
Copy Markdown

Addressed Issues:

Fixes #(#1369)

Screenshots/Recordings:

Pictopy Before:

Pictopy.Before.mov

Pictopy After:

Pictopy.After.mov

Additional Notes:

TOTAL NUMBER OF FILES CHANGED : 4
TOTAL NUMBER OF LINES OF CODE WRITTEN : 38
NUMBER OF CHANGES AND DELETION MADE : 0

Problem Statement:

PictoPy lets users configure which YOLO model is used for object detection, from a dropdown in Settings.
To manage those models, Settings has a "Configure..." option that opens a separate Model Manager window.

Bug:
When a user downloaded a new model tier or changed the active tier inside Model Manager,
then closed that window and returned to Settings, the Settings dropdown did not reflect the change.
The user is in the need to refresh to see changes.

Expected behavior:

Closing Model Manager should instantly refresh Settings.

Reason for updating files:

Settings and Model Manager are not the same window layouts. They are different windows altogether with different rust commands.

In order to make a connection between the two so that they can communicate with each other, I have used emit() function.

FILE 1 CHANGES:

Name of File: frontend/src/pages/modelmanager/ModelManager.tsx
Screenshot 2026-07-09 at 10 19 33 PM

Line 74 to 89.

FILE 2 CHANGES:

Name of File: frontend/src/hooks/useUserPrefrences.tsx

Screenshot 2026-07-09 at 6 13 17 PM LINE: 105

FILE 3 CHANGES:

Name of File: frontend/src/settingsPage/components/UserPreferencesCard.tsx

Screenshot 2026-07-09 at 10 20 27 PM

LINE 94 - 113.

FILE 4 CHANGES:

Name of File: frontend/src-tauri/capabilities/ModelManager.tsx

Screenshot 2026-07-09 at 6 17 05 PM

LINE 6 - 8.

**It was done for the closing of the ModelManager window **

Conclusion:

My code does not throw any error or stop any api calls but i still want the moderator or mentor to go through my code and PR.

My solution fixes the bug issue - 1369

AI Usage Disclosure:

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.

Check one of the checkboxes below:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools: TODO

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Model Manager and Settings now stay in sync across windows, so model changes are reflected without manual refresh.
    • Preferences can now refresh automatically after related updates.
  • Bug Fixes

    • Closing the Model Manager now triggers an update event to keep the installed model list and active preferences current.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR expands Tauri permissions and adds cross-window synchronization between the Model Manager window and the Settings page. Closing Model Manager now emits a models-updated event, and the settings preferences card listens for it, refreshes model status, and refetches preferences.

Changes

Model Manager to Settings sync

Layer / File(s) Summary
Tauri window/event capability permissions
frontend/src-tauri/capabilities/model_manager.json
Expands permissions to include default event handling and window allow-close/allow-destroy alongside existing core permissions.
Model Manager emits models-updated on close
frontend/src/pages/ModelManager/ModelManager.tsx
Registers an onCloseRequested handler that emits a models-updated event via Tauri, with error logging and cleanup on unmount.
Preferences hook exposes refetch
frontend/src/hooks/useUserPreferences.tsx
Adds refetch to the hook's returned object for cross-window preference refresh.
Settings page listens and refreshes on models-updated
frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx
Listens for models-updated, fetches /models/status to update installedTiers, and calls refetch(), cleaning up the listener on unmount.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant ModelManagerWindow
  participant TauriEventBus
  participant SettingsPage
  participant Backend

  User->>ModelManagerWindow: Close window
  ModelManagerWindow->>TauriEventBus: emit("models-updated")
  TauriEventBus->>SettingsPage: deliver models-updated
  SettingsPage->>Backend: fetch /models/status
  Backend-->>SettingsPage: installed tiers data
  SettingsPage->>SettingsPage: refetch() preferences
Loading

Possibly related PRs

Suggested labels: TypeScript/JavaScript

Poem

A bunny hops from pane to pane,
with models-updated in its brain.
One window closes, one reruns,
and preferences sparkle like morning suns.
🐇

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: Settings now refreshes after changes in Model Manager.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added bug Something isn't working frontend good first issue Good for newcomers labels Jul 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx (1)

94-106: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract shared fetch logic to eliminate duplication.

The new event-listener effect duplicates the model-status fetch and setInstalledTiers logic already in the mount effect (lines 44–80). The existing version has more robust handling (AbortController, error states, loading states); the new one omits those, creating divergent behavior for the same operation. Extract a shared fetchAndUpdateInstalledTiers helper to keep them consistent.

♻️ Proposed refactor: shared fetch helper
+  const fetchAndUpdateInstalledTiers = async (signal?: AbortSignal) => {
+    const res = await fetch(`${BACKEND_URL}/models/status`, signal ? { signal } : undefined);
+    if (!res.ok) throw new Error(`Failed to load models (${res.status})`);
+    const data: ModelStatusResponse = await res.json();
+    if (data.success && data.data) {
+      setInstalledTiers(getInstalledModelTiers(data.data));
+    }
+  };
+
   useEffect(() => {
     const controller = new AbortController();
-    const fetchModelStatus = async () => {
-      try {
-        const res = await fetch(`${BACKEND_URL}/models/status`, {
-          signal: controller.signal,
-        });
-        if (!res.ok) {
-          throw new Error(`Failed to load models (${res.status})`);
-        }
-        const data: ModelStatusResponse = await res.json();
-        if (controller.signal.aborted) return;
-        if (data.success && data.data) {
-          setInstalledTiers(getInstalledModelTiers(data.data));
-          setTierFetchError(null);
-        } else {
-          setTierFetchError('Failed to load models');
-        }
-      } catch (err) {
+    const fetchModelStatus = async () => {
+      try {
+        await fetchAndUpdateInstalledTiers(controller.signal);
         setTierFetchError(null);
+      } catch (err) {
         // ... existing error handling
       } finally { ... }
     };
     // ...
   }, []);

   useEffect(() => {
     const unlistenPromise = listen('models-updated', async () => {
       try {
-        const res = await fetch(`${BACKEND_URL}/models/status`);
-        if (res.ok) {
-          const data: ModelStatusResponse = await res.json();
-          if (data.success && data.data) {
-            setInstalledTiers(getInstalledModelTiers(data.data));
-          }
-        }
+        await fetchAndUpdateInstalledTiers();
       } catch (err) {
         console.error('Failed to refresh model status', err);
       }
       refetch();
     });
     // ...
   }, [refetch]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx` around
lines 94 - 106, The models-updated listener in UserPreferencesCard duplicates
the same model-status fetch and setInstalledTiers flow already handled in the
mount effect. Extract that logic into a shared fetchAndUpdateInstalledTiers
helper used by both the initial load effect and the listen callback, and keep
the existing AbortController/loading/error handling from the mount path
consistent in the shared implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/src/pages/ModelManager/ModelManager.tsx`:
- Around line 74-87: The on-close flow in ModelManager’s useEffect is racing
window teardown because the onCloseRequested callback awaits
emit('models-updated') without preventing the default close. Update the handler
to call event.preventDefault() first, then await the emit, and only after that
explicitly destroy the current window using the existing getCurrentWindow() flow
so Settings reliably receives the event; keep the cleanup/unlisten logic
unchanged.

In `@frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx`:
- Line 107: The `refetch()` call in `UserPreferencesCard` is a floating promise
and may reject without being handled. Update the callback that triggers
`refetch()` to either await the promise or explicitly handle its rejection with
a catch path, using the `refetch` function in `UserPreferencesCard` so failures
from `getUserPreferences` do not become unhandled promise rejections.

---

Nitpick comments:
In `@frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx`:
- Around line 94-106: The models-updated listener in UserPreferencesCard
duplicates the same model-status fetch and setInstalledTiers flow already
handled in the mount effect. Extract that logic into a shared
fetchAndUpdateInstalledTiers helper used by both the initial load effect and the
listen callback, and keep the existing AbortController/loading/error handling
from the mount path consistent in the shared implementation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 98191bcf-9041-49bf-9e05-a6613004cc51

📥 Commits

Reviewing files that changed from the base of the PR and between ffc0d48 and 2a1a0d6.

📒 Files selected for processing (4)
  • frontend/src-tauri/capabilities/model_manager.json
  • frontend/src/hooks/useUserPreferences.tsx
  • frontend/src/pages/ModelManager/ModelManager.tsx
  • frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx

Comment thread frontend/src/pages/ModelManager/ModelManager.tsx
Comment thread frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx Outdated
@Takitxt Takitxt changed the title ISSUE - 1369: BUG FIX. ISSUE - 1369: BUG FIX: Settings page does not update active YOLO model after changing it in Model Manager Jul 9, 2026
@Takitxt

Takitxt commented Jul 9, 2026

Copy link
Copy Markdown
Author

@rohan-pandeyy Can you go through my PR for issue number 1369.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working frontend good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant