From 2a1a0d6dc35c67674f48e778f82eb2ccb66172b0 Mon Sep 17 00:00:00 2001 From: Taki Date: Thu, 9 Jul 2026 16:18:16 +0530 Subject: [PATCH 1/2] ISSUE - 1369: BUG FIX. --- .../src-tauri/capabilities/model_manager.json | 6 +++- frontend/src/hooks/useUserPreferences.tsx | 7 ++++ .../src/pages/ModelManager/ModelManager.tsx | 25 +++++++++++++ .../components/UserPreferencesCard.tsx | 36 ++++++++++++++++++- 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/frontend/src-tauri/capabilities/model_manager.json b/frontend/src-tauri/capabilities/model_manager.json index caec085d3..901612534 100644 --- a/frontend/src-tauri/capabilities/model_manager.json +++ b/frontend/src-tauri/capabilities/model_manager.json @@ -1,5 +1,9 @@ { "identifier": "model-manager-capabilities", "windows": ["model-manager"], - "permissions": ["core:window:default", "core:app:allow-version"] + "permissions": ["core:window:default", + "core:app:allow-version", + "core:event:default", + "core:window:allow-close", + "core:window:allow-destroy"] } diff --git a/frontend/src/hooks/useUserPreferences.tsx b/frontend/src/hooks/useUserPreferences.tsx index 1f5d2779b..420e37e5b 100644 --- a/frontend/src/hooks/useUserPreferences.tsx +++ b/frontend/src/hooks/useUserPreferences.tsx @@ -99,6 +99,13 @@ export const useUserPreferences = () => { updateYoloModelSize, toggleGpuAcceleration, + + // ISSUE - 1369: Exposed so other Tauri windows (e.g. Model Manager) can access it and + // refresh the preferences after making changes inside Model-Manager Window. + refetch: preferencesQuery.refetch, + + + // Mutation state (for use in UI, e.g., disabling buttons) isUpdating: updatePreferencesMutation.isPending, }; diff --git a/frontend/src/pages/ModelManager/ModelManager.tsx b/frontend/src/pages/ModelManager/ModelManager.tsx index d3513b964..5287cd985 100644 --- a/frontend/src/pages/ModelManager/ModelManager.tsx +++ b/frontend/src/pages/ModelManager/ModelManager.tsx @@ -7,6 +7,10 @@ import { Download, Cloud } from 'lucide-react'; import { usePictoQuery } from '@/hooks/useQueryExtension'; import { fetchModelStatus } from '@/api/api-functions'; +// ISSUE - 1369: Importing emit and getCurrentWindow for the connection between settings and model manager. +import { getCurrentWindow } from '@tauri-apps/api/window'; +import { emit } from '@tauri-apps/api/event'; + const TABS: TabConfig[] = [ { id: 'Installed', label: 'Installed', icon: Download }, { id: 'Available', label: 'Available', icon: Cloud }, @@ -63,6 +67,27 @@ export const ModelManager: React.FC = () => { } }, [statusData, downloadingTiers, installedJustNow]); + +// ISSUE - 1369: Model Manager runs in its own Tauri window, separate from the Settings. + // They don't share React/query state. When the Model Manager closes, + // it emits 'models-updated' so Settings can get notified.. + useEffect(() => { + const unlistenPromise = getCurrentWindow().onCloseRequested(async () => { + try { + await emit('models-updated'); + } catch (err) { + console.error('Failed to emit models-updated', err); + } + + }); + + return () => { + unlistenPromise.then((unlisten) => unlisten()); + }; +}, []); + + + const handleTabChange = (newTab: string) => { if (activeTab === 'Available' && newTab !== 'Available') { setInstalledJustNow(new Set()); diff --git a/frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx b/frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx index bcf18fe4b..120144c0c 100644 --- a/frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx +++ b/frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx @@ -11,7 +11,11 @@ import { DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Button } from '@/components/ui/button'; + + import { invoke } from '@tauri-apps/api/core'; +import { listen } from '@tauri-apps/api/event'; + import { useUserPreferences } from '@/hooks/useUserPreferences'; import SettingsCard from './SettingsCard'; @@ -28,7 +32,7 @@ import { * Component for managing user preferences in settings */ const UserPreferencesCard: React.FC = () => { - const { preferences, updateYoloModelSize, toggleGpuAcceleration } = + const { preferences, updateYoloModelSize, toggleGpuAcceleration, refetch } = useUserPreferences(); const [installedTiers, setInstalledTiers] = useState([]); const [loadingTiers, setLoadingTiers] = useState(true); @@ -82,6 +86,36 @@ const UserPreferencesCard: React.FC = () => { }; }, []); + + + // ISSUE - 1369: Model Manager runs in its own Tauri window and doesn't share state with + // Settings. It emits 'models-updated' when it closes; refresh both the + // installed-tiers list and the active preference here in response. + 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)); + } + } + } catch (err) { + console.error('Failed to refresh model status', err); + } + refetch(); + }); + + return () => { + unlistenPromise.then((unlisten) => unlisten()); + }; + }, [refetch]); + + + + + return ( Date: Thu, 9 Jul 2026 22:16:03 +0530 Subject: [PATCH 2/2] Code after coderabbit corrections --- frontend/src/pages/ModelManager/ModelManager.tsx | 4 +++- .../src/pages/SettingsPage/components/UserPreferencesCard.tsx | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/ModelManager/ModelManager.tsx b/frontend/src/pages/ModelManager/ModelManager.tsx index 5287cd985..329d01cdf 100644 --- a/frontend/src/pages/ModelManager/ModelManager.tsx +++ b/frontend/src/pages/ModelManager/ModelManager.tsx @@ -72,12 +72,14 @@ export const ModelManager: React.FC = () => { // They don't share React/query state. When the Model Manager closes, // it emits 'models-updated' so Settings can get notified.. useEffect(() => { - const unlistenPromise = getCurrentWindow().onCloseRequested(async () => { + const unlistenPromise = getCurrentWindow().onCloseRequested(async (event) => { + event.preventDefault(); try { await emit('models-updated'); } catch (err) { console.error('Failed to emit models-updated', err); } + await getCurrentWindow().destroy(); }); diff --git a/frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx b/frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx index 120144c0c..80921c7a4 100644 --- a/frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx +++ b/frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx @@ -104,7 +104,7 @@ const UserPreferencesCard: React.FC = () => { } catch (err) { console.error('Failed to refresh model status', err); } - refetch(); + refetch().catch(console.error); }); return () => {