# HG changeset patch # User David Barts # Date 1579374807 28800 # Node ID 70caa73e32f79ea6d7c5a42277db95cabb1ea005 # Parent 6fb94eae32fa27b0b3375a7b79ed9a5e8174f1f0 Stop it from spinning on non-textual clipboard data. diff -r 6fb94eae32fa -r 70caa73e32f7 src/name/blackcap/clipman/Main.kt --- 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()) {