Skip to content

Instantly share code, notes, and snippets.

@brianhsu
Created March 27, 2011 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianhsu/888923 to your computer and use it in GitHub Desktop.
Save brianhsu/888923 to your computer and use it in GitHub Desktop.
A Plurk Notifier.
import org.eclipse.swt.SWT
import org.eclipse.swt.graphics.Image
import org.eclipse.swt.widgets.{List => _, _}
import org.eclipse.swt.events._
import org.bone.splurk.bot._
object ScalaIRCPopup extends SWTSystemTray
{
object PlurkNotifier extends Thread
{
val username = "brianhsu" // Set your username here.
val password = " " // Set your password here.
val apiKey = " " // Set your API Key here.
val plurkBot = new PlurkBot(apiKey)
def getUserName(userID: Long) = plurkBot.Profile.getPublicProfile(userID).userInfo.nickName
override def run() {
plurkBot.Users.login (username, password)
plurkBot.startBot {
case NewPlurk(plurk) =>
val userName = getUserName(plurk.userID)
val message = "%s 有新的噗:%s" format(userName, plurk.contentRaw)
println(message)
setTooltip(message, plurk.plurkURL)
case NewResponse(plurk, user, response) =>
val userName = getUserName(user.userID)
val message = "%s 有新的回應:%s" format(userName, response.contentRaw)
println(message)
setTooltip(message, plurk.plurkURL)
}
}
}
def main (args: Array[String])
{
PlurkNotifier.start()
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep()
}
}
display.dispose()
}
}
trait SWTSystemTray {
implicit def runnableFromFun (func: () => Any) = new Runnable {
override def run (){func()}
}
val display = new Display()
val shell = new Shell(display)
var url: String = null
val tooltip = {
val tray = display.getSystemTray()
val item = new TrayItem (tray, SWT.NONE);
val image = new Image (display, "plurk-icon.png");
val tooltip = new ToolTip (shell, SWT.BALLOON);
item.setImage(image);
item.setToolTip(tooltip);
tooltip.addSelectionListener(new SelectionListener() {
override def widgetDefaultSelected(e: SelectionEvent) {}
override def widgetSelected(e: SelectionEvent) {
Runtime.getRuntime().exec("firefox " + url)
}
})
tooltip
}
def setTooltip (message: String, url: String)
{
this.url = url
display.syncExec { () =>
tooltip.setVisible (false)
tooltip.setText("[Plurk] " + message);
tooltip.setVisible (true)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment