mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-21 20:29:03 +08:00
feat: refresh frontend data after MCP mutations
This commit is contained in:
+30
@@ -140,6 +140,36 @@ function MainContent(): React.JSX.Element {
|
||||
}
|
||||
}, [isIosDevice])
|
||||
|
||||
useEffect(() => {
|
||||
const api = (window as any).api
|
||||
if (!api || typeof api.onDataUpdated !== "function") return
|
||||
|
||||
let disposed = false
|
||||
let unlisten: (() => void) | null = null
|
||||
|
||||
api
|
||||
.onDataUpdated((payload: { category?: string; source?: string }) => {
|
||||
const detail = {
|
||||
category: payload?.category || "all",
|
||||
source: payload?.source || "tauri",
|
||||
}
|
||||
window.dispatchEvent(new CustomEvent("ss:data-updated", { detail }))
|
||||
})
|
||||
.then((fn: () => void) => {
|
||||
if (disposed) {
|
||||
fn()
|
||||
return
|
||||
}
|
||||
unlisten = fn
|
||||
})
|
||||
.catch(() => void 0)
|
||||
|
||||
return () => {
|
||||
disposed = true
|
||||
if (unlisten) unlisten()
|
||||
}
|
||||
}, [])
|
||||
|
||||
const applySyncStrategy = async (strategy: "keep_local" | "keep_remote") => {
|
||||
const api = (window as any).api
|
||||
if (!api) return
|
||||
|
||||
@@ -17,6 +17,11 @@ export interface settingChange {
|
||||
oldValue: any
|
||||
}
|
||||
|
||||
export interface dataUpdatedEvent {
|
||||
category?: "events" | "students" | "reasons" | "all"
|
||||
source?: string
|
||||
}
|
||||
|
||||
export type settingsKey =
|
||||
| "is_wizard_completed"
|
||||
| "log_level"
|
||||
@@ -228,6 +233,11 @@ const api = {
|
||||
callback(event.payload)
|
||||
})
|
||||
},
|
||||
onDataUpdated: (callback: (payload: dataUpdatedEvent) => void): Promise<UnlistenFn> => {
|
||||
return listen<dataUpdatedEvent>("ss:data-updated", (event) => {
|
||||
callback(event.payload || {})
|
||||
})
|
||||
},
|
||||
|
||||
// Logger
|
||||
queryLogs: (
|
||||
|
||||
Reference in New Issue
Block a user