Skip to content

Commit 3177a07

Browse files
committed
Use Option to simplify logic
1 parent 544acd7 commit 3177a07

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

desktop/src/main/scala/org/talkingpuffin/ui/util/DesktopUtil.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.talkingpuffin.util.Loggable
1212
object DesktopUtil extends Loggable {
1313
private case class Browse(uri: String)
1414

15-
private val browser = actorOf(new Actor() {
15+
private lazy val browser = actorOf(new Actor() {
1616
def receive = {
1717
case browse: Browse => {
1818
info("Before desktop.browse")
@@ -22,16 +22,15 @@ object DesktopUtil extends Loggable {
2222
}
2323
}).start()
2424

25-
private val trayIcon: TrayIcon = SystemTray.isSupported match {
26-
case true =>
25+
private lazy val trayIcon: Option[TrayIcon] =
26+
if (SystemTray.isSupported) {
2727
val icon = new TrayIcon(new ImageIcon(getClass.getResource("/TalkingPuffin_16.png")).getImage,Main.title)
2828
SystemTray.getSystemTray.add(icon)
29-
icon
30-
case _ => null
31-
}
29+
Some(icon)
30+
} else None
3231

3332
def browse(uri: String) = if (Desktop.isDesktopSupported) browser ! Browse(uri)
3433

35-
def notify(message: String, header: String) = if (SystemTray.isSupported)
36-
trayIcon.displayMessage(header, message, TrayIcon.MessageType.INFO)
34+
def notify(message: String, header: String) =
35+
trayIcon.foreach(_.displayMessage(header, message, TrayIcon.MessageType.INFO))
3736
}

0 commit comments

Comments
 (0)