diff src/name/blackcap/clipman/Main.kt @ 3:70caa73e32f7

Stop it from spinning on non-textual clipboard data.
author David Barts <n5jrn@me.com>
date Sat, 18 Jan 2020 11:13:27 -0800
parents be282c48010a
children debe0413280f
line wrap: on
line diff
--- a/src/name/blackcap/clipman/Main.kt	Sat Jan 18 10:58:45 2020 -0800
+++ b/src/name/blackcap/clipman/Main.kt	Sat Jan 18 11:13:27 2020 -0800
@@ -54,36 +54,34 @@
         while (true) {
             if (enabled) {
                 var contents = PasteboardItem.read()
-                if (contents == null) {
-                    LOGGER.log(Level.WARNING, "unable to read clipboard")
-                    continue
-                }
-                newContents = when (contents) {
-                    is PasteboardItem.Plain -> contents.plain
-                    is PasteboardItem.HTML -> contents.plain
-                }
-                if (oldContents != newContents) {
-                    var widget: JComponent = when(contents) {
-                        is PasteboardItem.Plain -> JTextPane().apply {
-                            contentType = "text/plain"
-                            toolTipText = "Plain text"
-                            text = contents.plain
-                            font = Font(Font.MONOSPACED, Font.PLAIN, 14)
-                            border = stdBorder
-                            autoSize(600)
-                            setEditable(false)
+                if (contents != null) {
+                    newContents = when (contents) {
+                        is PasteboardItem.Plain -> contents.plain
+                        is PasteboardItem.HTML -> contents.plain
+                    }
+                    if (oldContents != newContents) {
+                        var widget: JComponent = when(contents) {
+                            is PasteboardItem.Plain -> JTextPane().apply {
+                                contentType = "text/plain"
+                                toolTipText = "Plain text"
+                                text = contents.plain
+                                font = Font(Font.MONOSPACED, Font.PLAIN, 14)
+                                border = stdBorder
+                                autoSize(600)
+                                setEditable(false)
+                            }
+                            is PasteboardItem.HTML -> JTextPane().apply {
+                                contentType = "text/html"
+                                toolTipText = "Styled text"
+                                text = scrub(contents.html)
+                                border = stdBorder
+                                autoSize(600)
+                                setEditable(false)
+                            }
                         }
-                        is PasteboardItem.HTML -> JTextPane().apply {
-                            contentType = "text/html"
-                            toolTipText = "Styled text"
-                            text = scrub(contents.html)
-                            border = stdBorder
-                            autoSize(600)
-                            setEditable(false)
-                        }
+                        queue.add(QueueItem(widget, contents))
+                        oldContents = newContents
                     }
-                    queue.add(QueueItem(widget, contents))
-                    oldContents = newContents
                 }
             }
             if (Thread.interrupted()) {