From 26e8a5186a14f2cc59e0d1c7e26ab2894c130f1d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 3 Dec 2022 08:06:48 +0530 Subject: [PATCH] Avoid extra roundtrip when only reading clipboard mime types --- tools/cmd/clipboard/read.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/cmd/clipboard/read.go b/tools/cmd/clipboard/read.go index 72baa1525..59872e836 100644 --- a/tools/cmd/clipboard/read.go +++ b/tools/cmd/clipboard/read.go @@ -287,14 +287,19 @@ func run_get_loop(opts *Options, args []string) (err error) { if err != nil { return err } - requested_mimes[o.remote_mime_type] = o if o.remote_mime_type == "." { o.started = true o.add_data(utils.UnsafeStringToBytes(strings.Join(available_mimes, "\n"))) o.all_data_received = true + } else { + requested_mimes[o.remote_mime_type] = o } } - lp.QueueWriteString(encode(map[string]string{"type": "read"}, strings.Join(utils.Keys(requested_mimes), " "))) + if len(requested_mimes) > 0 { + lp.QueueWriteString(encode(map[string]string{"type": "read"}, strings.Join(utils.Keys(requested_mimes), " "))) + } else { + lp.Quit(0) + } default: return fmt.Errorf("Failed to read list of available data types in the clipboard with error: %w", error_from_status(metadata["status"])) }