mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
app: gracefully handle Windows clipboard read errors
Signed-off-by: Jeff Williams <info@anvil-editor.net>
This commit is contained in:
committed by
Elias Naur
parent
30dc7ff294
commit
3eab806940
+12
-2
@@ -699,7 +699,13 @@ func (w *window) ReadClipboard() {
|
|||||||
w.readClipboard()
|
w.readClipboard()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) readClipboard() error {
|
func (w *window) readClipboard() (cerr error) {
|
||||||
|
defer func() {
|
||||||
|
if cerr != nil {
|
||||||
|
w.processDataEvent("")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if err := windows.OpenClipboard(w.hwnd); err != nil {
|
if err := windows.OpenClipboard(w.hwnd); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -714,13 +720,17 @@ func (w *window) readClipboard() error {
|
|||||||
}
|
}
|
||||||
defer windows.GlobalUnlock(mem)
|
defer windows.GlobalUnlock(mem)
|
||||||
content := gowindows.UTF16PtrToString((*uint16)(unsafe.Pointer(ptr)))
|
content := gowindows.UTF16PtrToString((*uint16)(unsafe.Pointer(ptr)))
|
||||||
|
w.processDataEvent(content)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *window) processDataEvent(content string) {
|
||||||
w.ProcessEvent(transfer.DataEvent{
|
w.ProcessEvent(transfer.DataEvent{
|
||||||
Type: "application/text",
|
Type: "application/text",
|
||||||
Open: func() io.ReadCloser {
|
Open: func() io.ReadCloser {
|
||||||
return io.NopCloser(strings.NewReader(content))
|
return io.NopCloser(strings.NewReader(content))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) Configure(options []Option) {
|
func (w *window) Configure(options []Option) {
|
||||||
|
|||||||
Reference in New Issue
Block a user