MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / UseConfirmModal

Function UseConfirmModal

tsunami/app/hooks.go:286–332  ·  view source on GitHub ↗

UseConfirmModal returns a boolean indicating if the modal is open and a function to trigger it

()

Source from the content-addressed store, hash-verified

284
285// UseConfirmModal returns a boolean indicating if the modal is open and a function to trigger it
286func UseConfirmModal() (modalOpen bool, triggerConfirm func(config ModalConfig)) {
287 isOpen := UseLocal(false)
288
289 trigger := func(config ModalConfig) {
290 if isOpen.Get() {
291 log.Printf("warning: UseConfirmModal trigger called while modal is already open")
292 if config.OnResult != nil {
293 go func() {
294 defer func() {
295 util.PanicHandler("UseConfirmModal callback goroutine", recover())
296 }()
297 time.Sleep(10 * time.Millisecond)
298 config.OnResult(false)
299 }()
300 }
301 return
302 }
303 isOpen.Set(true)
304
305 // Create modal config for backend
306 modalId := uuid.New().String()
307 backendConfig := rpctypes.ModalConfig{
308 ModalId: modalId,
309 ModalType: "confirm",
310 Icon: config.Icon,
311 Title: config.Title,
312 Text: config.Text,
313 OkText: config.OkText,
314 CancelText: config.CancelText,
315 }
316
317 // Show modal and wait for result in a goroutine
318 go func() {
319 defer func() {
320 util.PanicHandler("UseConfirmModal goroutine", recover())
321 }()
322 resultChan := engine.GetDefaultClient().ShowModal(backendConfig)
323 result := <-resultChan
324 isOpen.Set(false)
325 if config.OnResult != nil {
326 config.OnResult(result)
327 }
328 }()
329 }
330
331 return isOpen.Get(), trigger
332}
333

Callers 1

app.goFile · 0.92

Calls 7

PanicHandlerFunction · 0.92
GetDefaultClientFunction · 0.92
ShowModalMethod · 0.80
UseLocalFunction · 0.70
GetMethod · 0.45
SetMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected