Skip to content

Commit 4a25626

Browse files
committed
Cache HTML documents to avoid expensive updates (could fix #15)
1 parent 46d7b09 commit 4a25626

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

tray-util/src/main/scala/com/github/opengrabeso/loctio/HtmlPanel.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ class HtmlPanel(baseUri: String) extends Panel {
2727
}
2828
}
2929

30-
def html: String = throw new UnsupportedOperationException("HTML document is write only")
30+
private var htmlValue: String = ""
31+
32+
def html: String = htmlValue
3133
def html_=(text: String): Unit = {
32-
val is = new ByteArrayInputStream(text.getBytes(Charset.forName("UTF-8")))
33-
val url = baseUri
34-
peer.setDocument(is, url + "/")
34+
// avoid loading the document unless necessary, as loading is quite slow
35+
if (htmlValue != text) {
36+
htmlValue = text
37+
val is = new ByteArrayInputStream(text.getBytes(Charset.forName("UTF-8")))
38+
val url = baseUri
39+
peer.setDocument(is, url + "/")
40+
}
3541
}
3642
}

tray-util/src/main/scala/com/github/opengrabeso/loctio/Start.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,10 @@ object Start extends SimpleSwingApplication {
428428
assert(SwingUtilities.isEventDispatchThread)
429429
state = s
430430
val text = if (state.isEmpty) appName else state
431-
icon.setToolTip(text)
431+
// setting tooltip is a system call, it might be quite slow, avoid it unless necessary
432+
if (text != icon.getToolTip) {
433+
icon.setToolTip(text)
434+
}
432435
}
433436
}
434437

0 commit comments

Comments
 (0)