Tighten CEF file dialog callback and GIO cleanup
- commit
- 163e508f7eb16335fc9505906b1aa59f87b05a8f
- author
- brice · · 2026-05-08 00:55 UTC
- parent
- f2194b1
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +17 -5
M internal/infrastructure/cef/file_dialog.go +17 -5
| @@ -108,7 +108,7 @@ func presentGTKFileDialog(wv *WebView, req cefFileDialogRequest, callback purece | |||
| 108 | 108 | Int32("mode", req.Mode). | |
| 109 | 109 | Msg("cef: GTK file dialog response received") | |
| 110 | 110 | if normalizedResponseID != int(gtk.ResponseAcceptValue) { | |
| 111 | - | logCEFFileDialog(wv).Debug().Msg("cef: file dialog cancelled") | |
| 111 | + | logCEFFileDialog(wv).Debug().Msg("cef: file dialog canceled") | |
| 112 | 112 | dispatchFileDialogResult(wv, callback, nil) | |
| 113 | 113 | return | |
| 114 | 114 | } | |
| @@ -196,6 +196,7 @@ func applyDefaultDialogPath(dialog *gtk.FileChooserNative, req cefFileDialogRequ | |||
| 196 | 196 | if req.Mode == purecef.FileDialogModeFileDialogSave { | |
| 197 | 197 | if dir := filepath.Dir(path); dir != "." && dir != "" { | |
| 198 | 198 | if folder := gio.FileNewForPath(dir); folder != nil { | |
| 199 | + | defer unrefGObjectPointer(folder.GoPointer()) | |
| 199 | 200 | _, _ = dialog.SetCurrentFolder(folder) | |
| 200 | 201 | } | |
| 201 | 202 | } | |
| @@ -207,6 +208,7 @@ func applyDefaultDialogPath(dialog *gtk.FileChooserNative, req cefFileDialogRequ | |||
| 207 | 208 | ||
| 208 | 209 | if info, err := os.Stat(path); err == nil && info.IsDir() { | |
| 209 | 210 | if folder := gio.FileNewForPath(path); folder != nil { | |
| 211 | + | defer unrefGObjectPointer(folder.GoPointer()) | |
| 210 | 212 | _, _ = dialog.SetCurrentFolder(folder) | |
| 211 | 213 | } | |
| 212 | 214 | return | |
| @@ -214,11 +216,13 @@ func applyDefaultDialogPath(dialog *gtk.FileChooserNative, req cefFileDialogRequ | |||
| 214 | 216 | ||
| 215 | 217 | if dir := filepath.Dir(path); dir != "." && dir != "" { | |
| 216 | 218 | if folder := gio.FileNewForPath(dir); folder != nil { | |
| 219 | + | defer unrefGObjectPointer(folder.GoPointer()) | |
| 217 | 220 | _, _ = dialog.SetCurrentFolder(folder) | |
| 218 | 221 | } | |
| 219 | 222 | } | |
| 220 | 223 | if req.Mode != purecef.FileDialogModeFileDialogOpenFolder { | |
| 221 | 224 | if file := gio.FileNewForPath(path); file != nil { | |
| 225 | + | defer unrefGObjectPointer(file.GoPointer()) | |
| 222 | 226 | _, _ = dialog.SetFile(file) | |
| 223 | 227 | } | |
| 224 | 228 | } | |
| @@ -353,7 +357,10 @@ func folderUploadPaths(wv *WebView, mode purecef.FileDialogMode, paths []string) | |||
| 353 | 357 | } | |
| 354 | 358 | info, err := os.Stat(folder) | |
| 355 | 359 | if err != nil || !info.IsDir() { | |
| 356 | - | logCEFFileDialog(wv).Warn().Err(err).Str("path", folder).Msg("cef: folder upload path expansion skipped; selected path is not a directory") | |
| 360 | + | logCEFFileDialog(wv).Warn(). | |
| 361 | + | Err(err). | |
| 362 | + | Str("path", folder). | |
| 363 | + | Msg("cef: folder upload path expansion skipped; selected path is not a directory") | |
| 357 | 364 | return paths | |
| 358 | 365 | } | |
| 359 | 366 | ||
| @@ -379,11 +386,16 @@ func folderUploadPaths(wv *WebView, mode purecef.FileDialogMode, paths []string) | |||
| 379 | 386 | return nil | |
| 380 | 387 | }) | |
| 381 | 388 | if walkErr != nil { | |
| 382 | - | logCEFFileDialog(wv).Warn().Err(walkErr).Str("folder", folder).Msg("cef: folder upload descendant enumeration failed; using selected directory path") | |
| 389 | + | logCEFFileDialog(wv).Warn(). | |
| 390 | + | Err(walkErr). | |
| 391 | + | Str("folder", folder). | |
| 392 | + | Msg("cef: folder upload descendant enumeration failed; using selected directory path") | |
| 383 | 393 | return paths | |
| 384 | 394 | } | |
| 385 | 395 | if len(files) == 0 { | |
| 386 | - | logCEFFileDialog(wv).Warn().Str("folder", folder).Msg("cef: folder upload descendant enumeration found no regular files; using selected directory path") | |
| 396 | + | logCEFFileDialog(wv).Warn(). | |
| 397 | + | Str("folder", folder). | |
| 398 | + | Msg("cef: folder upload descendant enumeration found no regular files; using selected directory path") | |
| 387 | 399 | return paths | |
| 388 | 400 | } | |
| 389 | 401 | ||
| @@ -445,11 +457,11 @@ func dispatchFileDialogResult(wv *WebView, callback purecef.FileDialogCallback, | |||
| 445 | 457 | ||
| 446 | 458 | func continueCEFFileDialogWithLogs(logger *zerolog.Logger, callback purecef.FileDialogCallback, filePaths ...string) { | |
| 447 | 459 | logger = nonNilCEFFileDialogLogger(logger) | |
| 448 | - | callbackPtr := rawCEFPointer(callback) | |
| 449 | 460 | if callback == nil { | |
| 450 | 461 | logger.Debug().Msg("cef: file dialog callback continuation skipped; callback is nil") | |
| 451 | 462 | return | |
| 452 | 463 | } | |
| 464 | + | callbackPtr := rawCEFPointer(callback) | |
| 453 | 465 | ||
| 454 | 466 | if len(filePaths) == 0 { | |
| 455 | 467 | logger.Debug().Uint64("callback_ptr", uint64(callbackPtr)).Msg("cef: invoking file dialog callback cancel") | |
| @@ -108,7 +108,7 @@ func presentGTKFileDialog(wv *WebView, req cefFileDialogRequest, callback purece | |||||
| 108 | Int32("mode", req.Mode). | 108 | Int32("mode", req.Mode). | ||
| 109 | Msg("cef: GTK file dialog response received") | 109 | Msg("cef: GTK file dialog response received") | ||
| 110 | if normalizedResponseID != int(gtk.ResponseAcceptValue) { | 110 | if normalizedResponseID != int(gtk.ResponseAcceptValue) { | ||
| 111 | - | logCEFFileDialog(wv).Debug().Msg("cef: file dialog cancelled") | 111 | + | logCEFFileDialog(wv).Debug().Msg("cef: file dialog canceled") |
| 112 | dispatchFileDialogResult(wv, callback, nil) | 112 | dispatchFileDialogResult(wv, callback, nil) | ||
| 113 | return | 113 | return | ||
| 114 | } | 114 | } | ||
| @@ -196,6 +196,7 @@ func applyDefaultDialogPath(dialog *gtk.FileChooserNative, req cefFileDialogRequ | |||||
| 196 | if req.Mode == purecef.FileDialogModeFileDialogSave { | 196 | if req.Mode == purecef.FileDialogModeFileDialogSave { | ||
| 197 | if dir := filepath.Dir(path); dir != "." && dir != "" { | 197 | if dir := filepath.Dir(path); dir != "." && dir != "" { | ||
| 198 | if folder := gio.FileNewForPath(dir); folder != nil { | 198 | if folder := gio.FileNewForPath(dir); folder != nil { | ||
| 199 | + | defer unrefGObjectPointer(folder.GoPointer()) | |||
| 199 | _, _ = dialog.SetCurrentFolder(folder) | 200 | _, _ = dialog.SetCurrentFolder(folder) | ||
| 200 | } | 201 | } | ||
| 201 | } | 202 | } | ||
| @@ -207,6 +208,7 @@ func applyDefaultDialogPath(dialog *gtk.FileChooserNative, req cefFileDialogRequ | |||||
| 207 | 208 | ||||
| 208 | if info, err := os.Stat(path); err == nil && info.IsDir() { | 209 | if info, err := os.Stat(path); err == nil && info.IsDir() { | ||
| 209 | if folder := gio.FileNewForPath(path); folder != nil { | 210 | if folder := gio.FileNewForPath(path); folder != nil { | ||
| 211 | + | defer unrefGObjectPointer(folder.GoPointer()) | |||
| 210 | _, _ = dialog.SetCurrentFolder(folder) | 212 | _, _ = dialog.SetCurrentFolder(folder) | ||
| 211 | } | 213 | } | ||
| 212 | return | 214 | return | ||
| @@ -214,11 +216,13 @@ func applyDefaultDialogPath(dialog *gtk.FileChooserNative, req cefFileDialogRequ | |||||
| 214 | 216 | ||||
| 215 | if dir := filepath.Dir(path); dir != "." && dir != "" { | 217 | if dir := filepath.Dir(path); dir != "." && dir != "" { | ||
| 216 | if folder := gio.FileNewForPath(dir); folder != nil { | 218 | if folder := gio.FileNewForPath(dir); folder != nil { | ||
| 219 | + | defer unrefGObjectPointer(folder.GoPointer()) | |||
| 217 | _, _ = dialog.SetCurrentFolder(folder) | 220 | _, _ = dialog.SetCurrentFolder(folder) | ||
| 218 | } | 221 | } | ||
| 219 | } | 222 | } | ||
| 220 | if req.Mode != purecef.FileDialogModeFileDialogOpenFolder { | 223 | if req.Mode != purecef.FileDialogModeFileDialogOpenFolder { | ||
| 221 | if file := gio.FileNewForPath(path); file != nil { | 224 | if file := gio.FileNewForPath(path); file != nil { | ||
| 225 | + | defer unrefGObjectPointer(file.GoPointer()) | |||
| 222 | _, _ = dialog.SetFile(file) | 226 | _, _ = dialog.SetFile(file) | ||
| 223 | } | 227 | } | ||
| 224 | } | 228 | } | ||
| @@ -353,7 +357,10 @@ func folderUploadPaths(wv *WebView, mode purecef.FileDialogMode, paths []string) | |||||
| 353 | } | 357 | } | ||
| 354 | info, err := os.Stat(folder) | 358 | info, err := os.Stat(folder) | ||
| 355 | if err != nil || !info.IsDir() { | 359 | if err != nil || !info.IsDir() { | ||
| 356 | - | logCEFFileDialog(wv).Warn().Err(err).Str("path", folder).Msg("cef: folder upload path expansion skipped; selected path is not a directory") | 360 | + | logCEFFileDialog(wv).Warn(). |
| 361 | + | Err(err). | |||
| 362 | + | Str("path", folder). | |||
| 363 | + | Msg("cef: folder upload path expansion skipped; selected path is not a directory") | |||
| 357 | return paths | 364 | return paths | ||
| 358 | } | 365 | } | ||
| 359 | 366 | ||||
| @@ -379,11 +386,16 @@ func folderUploadPaths(wv *WebView, mode purecef.FileDialogMode, paths []string) | |||||
| 379 | return nil | 386 | return nil | ||
| 380 | }) | 387 | }) | ||
| 381 | if walkErr != nil { | 388 | if walkErr != nil { | ||
| 382 | - | logCEFFileDialog(wv).Warn().Err(walkErr).Str("folder", folder).Msg("cef: folder upload descendant enumeration failed; using selected directory path") | 389 | + | logCEFFileDialog(wv).Warn(). |
| 390 | + | Err(walkErr). | |||
| 391 | + | Str("folder", folder). | |||
| 392 | + | Msg("cef: folder upload descendant enumeration failed; using selected directory path") | |||
| 383 | return paths | 393 | return paths | ||
| 384 | } | 394 | } | ||
| 385 | if len(files) == 0 { | 395 | if len(files) == 0 { | ||
| 386 | - | logCEFFileDialog(wv).Warn().Str("folder", folder).Msg("cef: folder upload descendant enumeration found no regular files; using selected directory path") | 396 | + | logCEFFileDialog(wv).Warn(). |
| 397 | + | Str("folder", folder). | |||
| 398 | + | Msg("cef: folder upload descendant enumeration found no regular files; using selected directory path") | |||
| 387 | return paths | 399 | return paths | ||
| 388 | } | 400 | } | ||
| 389 | 401 | ||||
| @@ -445,11 +457,11 @@ func dispatchFileDialogResult(wv *WebView, callback purecef.FileDialogCallback, | |||||
| 445 | 457 | ||||
| 446 | func continueCEFFileDialogWithLogs(logger *zerolog.Logger, callback purecef.FileDialogCallback, filePaths ...string) { | 458 | func continueCEFFileDialogWithLogs(logger *zerolog.Logger, callback purecef.FileDialogCallback, filePaths ...string) { | ||
| 447 | logger = nonNilCEFFileDialogLogger(logger) | 459 | logger = nonNilCEFFileDialogLogger(logger) | ||
| 448 | - | callbackPtr := rawCEFPointer(callback) | |||
| 449 | if callback == nil { | 460 | if callback == nil { | ||
| 450 | logger.Debug().Msg("cef: file dialog callback continuation skipped; callback is nil") | 461 | logger.Debug().Msg("cef: file dialog callback continuation skipped; callback is nil") | ||
| 451 | return | 462 | return | ||
| 452 | } | 463 | } | ||
| 464 | + | callbackPtr := rawCEFPointer(callback) | |||
| 453 | 465 | ||||
| 454 | if len(filePaths) == 0 { | 466 | if len(filePaths) == 0 { | ||
| 455 | logger.Debug().Uint64("callback_ptr", uint64(callbackPtr)).Msg("cef: invoking file dialog callback cancel") | 467 | logger.Debug().Uint64("callback_ptr", uint64(callbackPtr)).Msg("cef: invoking file dialog callback cancel") | ||