@tastic/hud 0.8.3 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +12 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.js +187 -160
- package/dist/index.mjs +166 -140
- package/package.json +4 -3
- package/src/BaseSettingsDialog.tsx +12 -27
- package/src/ConfirmDialog.tsx +9 -6
- package/src/UpdateDialog.tsx +28 -0
- package/src/index.ts +1 -0
- package/src/useUpdateConfirmBridge.ts +30 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { UpdateManifest } from '@rific/updater'
|
|
2
|
+
import { useCallback, useRef, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
// Bridges @rific/updater's async onConfirm: (manifest) => Promise<boolean> into plain render
|
|
5
|
+
// state a ConfirmDialog can drive: `manifest` is the pending update to show (or null when there's
|
|
6
|
+
// nothing to confirm), and `respond` both resolves the promise onConfirm handed back to useUpdater
|
|
7
|
+
// and clears `manifest` so the dialog closes. Internal - not exported from index.ts. Shared by
|
|
8
|
+
// UpdateDialog and BaseSettingsDialog's own manual-check flow, so each only owns its own
|
|
9
|
+
// useUpdater() instance (see BaseSettingsDialog's comment on why that instance can't be shared).
|
|
10
|
+
export function useUpdateConfirmBridge() {
|
|
11
|
+
const [manifest, setManifest] = useState<UpdateManifest | null>(null)
|
|
12
|
+
const resolveRef = useRef<((confirmed: boolean) => void) | null>(null)
|
|
13
|
+
|
|
14
|
+
const onConfirm = useCallback(
|
|
15
|
+
(next: UpdateManifest) =>
|
|
16
|
+
new Promise<boolean>((resolve) => {
|
|
17
|
+
resolveRef.current = resolve
|
|
18
|
+
setManifest(next)
|
|
19
|
+
}),
|
|
20
|
+
[]
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const respond = useCallback((confirmed: boolean) => {
|
|
24
|
+
setManifest(null)
|
|
25
|
+
resolveRef.current?.(confirmed)
|
|
26
|
+
resolveRef.current = null
|
|
27
|
+
}, [])
|
|
28
|
+
|
|
29
|
+
return { manifest, onConfirm, respond }
|
|
30
|
+
}
|