# HG changeset patch # User David Barts # Date 1736710337 28800 # Node ID ca0fab758ff99c765fd289edff7f65df58d3fe28 # Parent a30deee457e302818e8d00e8dcc298c631db5846 Hopefully fix the race conditions that sometimes make it crash. diff -r a30deee457e3 -r ca0fab758ff9 build.xml --- a/build.xml Sun Jan 12 10:23:04 2025 -0800 +++ b/build.xml Sun Jan 12 11:32:17 2025 -0800 @@ -32,8 +32,8 @@ - - + + diff -r a30deee457e3 -r ca0fab758ff9 src/name/blackcap/clipman/Main.kt --- a/src/name/blackcap/clipman/Main.kt Sun Jan 12 10:23:04 2025 -0800 +++ b/src/name/blackcap/clipman/Main.kt Sun Jan 12 11:32:17 2025 -0800 @@ -60,34 +60,40 @@ var oldContents: PasteboardItem? = null while (true) { if (enabled) { - var contents = PasteboardItem.read() + var kontents: PasteboardItem? = null + inSynSwingThread { + kontents = PasteboardItem.read() + } + val contents = kontents if ((contents != null) && (contents != oldContents)) { val (plain, html) = when(contents) { is PasteboardItem.Plain -> Pair(contents.plain, null) is PasteboardItem.HTML -> Pair(null, contents.html) is PasteboardItem.RTF -> Pair(contents.plain, contents.html) } - val piv = if (html == null) { - PasteboardItemView("Plain text", ClipText(contents).apply { - contentType = "text/plain" - text = plain - font = Font(Font.MONOSPACED, Font.PLAIN, MONO_SIZE) - resize() - }) - } else { - val (dhtml, style) = preproc(html) - val hek = MyEditorKit().apply { - style.addStyleSheet(defaultStyleSheet) - styleSheet = style + inSynSwingThread { + val piv = if (html == null) { + PasteboardItemView("Plain text", ClipText(contents).apply { + contentType = "text/plain" + text = plain + font = Font(Font.MONOSPACED, Font.PLAIN, MONO_SIZE) + resize() + }) + } else { + val (dhtml, style) = preproc(html) + val hek = MyEditorKit().apply { + style.addStyleSheet(defaultStyleSheet) + styleSheet = style + } + PasteboardItemView("Styled text", ClipText(contents).apply { + editorKit = hek + text = dhtml + resize() + }) } - PasteboardItemView("Styled text", ClipText(contents).apply { - editorKit = hek - text = dhtml - resize() - }) + piv.searchable.addMouseListener(this) + Application.queue.add(QueueItem(contents, piv)) } - piv.searchable.addMouseListener(this) - Application.queue.add(QueueItem(contents, piv)) oldContents = contents } } @@ -140,22 +146,22 @@ } } - override fun mousePressed(e: MouseEvent) { - maybeShowPopup(e) - } + override fun mousePressed(e: MouseEvent) { + maybeShowPopup(e) + } - override fun mouseReleased(e: MouseEvent) { - maybeShowPopup(e) - } + override fun mouseReleased(e: MouseEvent) { + maybeShowPopup(e) + } - private fun maybeShowPopup(e: MouseEvent) { - if (e.isPopupTrigger()) { - Application.popupMenu.show(e.component, e.x, e.y) - } - } + private fun maybeShowPopup(e: MouseEvent) { + if (e.isPopupTrigger()) { + Application.popupMenu.show(e.component, e.x, e.y) + } + } - override fun mouseEntered(e: MouseEvent) { } - override fun mouseExited(e: MouseEvent) { } + override fun mouseEntered(e: MouseEvent) { } + override fun mouseExited(e: MouseEvent) { } } object Application {