SlideShare uma empresa Scribd logo
1 de 12
Baixar para ler offline
Remote Notifications
Integrace desktopu a webu v Javě – jednoduše a bez závislostí!




                                                         Josef Cacek
                                       Siemens IT Solutions and Services
                                                                   Brno
System Tray Icon


Remote Notifications            2
System Tray Icon
import java.awt.*;


if (SystemTray.isSupported()) {
    Image img = Toolkit.getDefaultToolkit().getImage("coffee.png");
    PopupMenu popup = // ... ;


    TrayIcon trayIcon = new TrayIcon(img, "My own tooltip", popup);
    trayIcon.setImageAutoSize(true);
    //trayIcon.addMouseListener(...);
    //The MOUSE_ENTERED and MOUSE_EXITED mouse events are not supported.


    SystemTray.getSystemTray().add(trayIcon);
    //...


    trayIcon.displayMessage("Title", "I like it.", TrayIcon.MessageType.INFO);
}




Remote Notifications                                                             3
Windows Sounds


Remote Notifications         4
Windows sounds
import java.awt.Toolkit;


Runnable sound =
    (Runnable) Toolkit.getDefaultToolkit().getDesktopProperty("win.sound.asterisk");


if (sound != null) {
    sound.run();
}


// "win.sound.*" properties:
//    default asterisk exclamation hand question
//    maximize minimize
//    menuCommand menuPopup
//    open close start exit
//    restoreDown restoreUp




Remote Notifications                                                                   5
HTTP server


Remote Notifications                 6
HTTP server

import com.sun.net.httpserver.*;


HttpServer httpServer = HttpServer.create(new InetSocketAddress(80), 0);
HttpHandler handler = new HttpHandler() {
 public void handle(HttpExchange exchange) throws IOException {
     InputStream is = exchange.getRequestBody();
     //... some logic here
     exchange.getResponseHeaders().add("Content-Type", "text/plain");
     exchange.sendResponseHeaders(200, 0); // status - SC_OK, contentLength - chunked
     OutputStreamWriter osw = new OutputStreamWriter(exchange.getResponseBody());
     osw.append("Hello world wide web!nQuery: " + exchange.getRequestURI().getQuery());


     is.close();
     osw.close();
 }

};
httpServer.createContext("/", handler);
httpServer.start();




Remote Notifications                                                                                 7
HTTP server

import com.sun.net.httpserver.*;


HttpServer httpServer = HttpServer.create(new InetSocketAddress(80), 0);
HttpHandler handler = new HttpHandler() {
     public void handle(HttpExchange exchange) throws IOException {
         InputStream is = exchange.getRequestBody();
         //... some logic here
         exchange.getResponseHeaders().add("Content-Type", "text/plain");
         exchange.sendResponseHeaders(200, 0); // status - SC_OK, contentLength - chunked
         OutputStreamWriter osw = new OutputStreamWriter(exchange.getResponseBody());
         osw.append("Hello world wide web!nQuery: " + exchange.getRequestURI().getQuery());


         is.close();
         osw.close();
     }
};
httpServer.createContext("/", handler);
httpServer.start();




Remote Notifications                                                                           8
Notifier
                       https://github.com/kwart/Notifier




Remote Notifications                                       9
Notifier – server

     spustitelný JAR
       –   $java -jar Notifier.jar [port [defaultIcon [soundDesktopProperty]]
     výchozí nastavení
       –   port: 8811
       –   ikona: sun
       –   zvuk: win.sound.asterisk
     události
       –   jednoduchý klik – návrat k výchozí ikoně
       –   dvojklik – ukončení programu




Remote Notifications                                                              10
Notifier – klienti

     jakýkoliv běžný HTTP klient
       –   firefox http://localhost:8811/teddy-bear



     příkazová řádka
       –   wget -O - http://localhost:8811/warning
       –   curl -d "Build finished succesfully" http://localhost:8811/ok
       –   curl -d "%sname: %smessage" --connect-timeout 3 http://10.0.2.2:8811/bubble




Remote Notifications                                                                11
Zdrojové kódy ke stažení
       –   https://github.com/kwart/Notifier

     API dokumentace
       –   System Tray
           http://download.oracle.com/javase/6/docs/api/java/awt/SystemTray.html
       –   Windows Sounds
           http://download.oracle.com/javase/1.4.2/docs/guide/swing/1.4/w2k_props.html
       –   HTTP server
           http://download.oracle.com/javase/6/docs/jre/api/net/httpserver/spec/


     šablona prezentace od Chih-Hao Tsai http://technology.chtsai.org/impress/




Remote Notifications                                                                12

Mais conteúdo relacionado

Mais procurados

Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek MeetBringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
Robert Nyman
 
Pontos para criar_instancia_data guard_11g
Pontos para criar_instancia_data guard_11gPontos para criar_instancia_data guard_11g
Pontos para criar_instancia_data guard_11g
Leandro Santos
 
How to recognise that the user has just uninstalled your android app droidc...
How to recognise that the user has just uninstalled your android app   droidc...How to recognise that the user has just uninstalled your android app   droidc...
How to recognise that the user has just uninstalled your android app droidc...
Przemek Jakubczyk
 
Raspberry pi gaming 4 kids
Raspberry pi gaming 4 kidsRaspberry pi gaming 4 kids
Raspberry pi gaming 4 kids
Stephen Chin
 
The Mouse is mightier than the sword
The Mouse is mightier than the swordThe Mouse is mightier than the sword
The Mouse is mightier than the sword
Priyanka Aash
 
Hernan Ochoa - WCE Internals [RootedCON 2011]
Hernan Ochoa - WCE Internals [RootedCON 2011]Hernan Ochoa - WCE Internals [RootedCON 2011]
Hernan Ochoa - WCE Internals [RootedCON 2011]
RootedCON
 

Mais procurados (20)

Synack at ShmooCon 2015
Synack at ShmooCon 2015Synack at ShmooCon 2015
Synack at ShmooCon 2015
 
ng-conf 2017: Angular Mischief Maker Slides
ng-conf 2017: Angular Mischief Maker Slidesng-conf 2017: Angular Mischief Maker Slides
ng-conf 2017: Angular Mischief Maker Slides
 
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek MeetBringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
 
Mule ESB : ssh connector
Mule ESB : ssh connectorMule ESB : ssh connector
Mule ESB : ssh connector
 
Pontos para criar_instancia_data guard_11g
Pontos para criar_instancia_data guard_11gPontos para criar_instancia_data guard_11g
Pontos para criar_instancia_data guard_11g
 
Non stop random2b
Non stop random2bNon stop random2b
Non stop random2b
 
JCrete Embedded Java Workshop
JCrete Embedded Java WorkshopJCrete Embedded Java Workshop
JCrete Embedded Java Workshop
 
Alex Troush - IEx Cheat Sheet
Alex Troush - IEx Cheat Sheet Alex Troush - IEx Cheat Sheet
Alex Troush - IEx Cheat Sheet
 
How to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android appHow to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android app
 
How to recognise that the user has just uninstalled your android app droidc...
How to recognise that the user has just uninstalled your android app   droidc...How to recognise that the user has just uninstalled your android app   droidc...
How to recognise that the user has just uninstalled your android app droidc...
 
Raspberry pi gaming 4 kids
Raspberry pi gaming 4 kidsRaspberry pi gaming 4 kids
Raspberry pi gaming 4 kids
 
DevOps Braga #6
DevOps Braga #6DevOps Braga #6
DevOps Braga #6
 
Intro django
Intro djangoIntro django
Intro django
 
The Mouse is mightier than the sword
The Mouse is mightier than the swordThe Mouse is mightier than the sword
The Mouse is mightier than the sword
 
Laboratory exercise - Network security - Penetration testing
Laboratory exercise - Network security - Penetration testingLaboratory exercise - Network security - Penetration testing
Laboratory exercise - Network security - Penetration testing
 
Hernan Ochoa - WCE Internals [RootedCON 2011]
Hernan Ochoa - WCE Internals [RootedCON 2011]Hernan Ochoa - WCE Internals [RootedCON 2011]
Hernan Ochoa - WCE Internals [RootedCON 2011]
 
Zabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet MensZabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet Mens
 
Flash Messenger for MusicStar Switzerland
Flash Messenger for MusicStar SwitzerlandFlash Messenger for MusicStar Switzerland
Flash Messenger for MusicStar Switzerland
 
YCAM Workshop Part 3
YCAM Workshop Part 3YCAM Workshop Part 3
YCAM Workshop Part 3
 
T-DOSE 2015: Using Python, PHP, JQuery and Linux to visualize the heartrate a...
T-DOSE 2015: Using Python, PHP, JQuery and Linux to visualize the heartrate a...T-DOSE 2015: Using Python, PHP, JQuery and Linux to visualize the heartrate a...
T-DOSE 2015: Using Python, PHP, JQuery and Linux to visualize the heartrate a...
 

Semelhante a Remote Notifications

JavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the PlatformJavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the Platform
Robert Nyman
 
Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
 	Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W... 	Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
Robert Nyman
 
Fire & Ice: Making and Breaking macOS Firewalls
Fire & Ice: Making and Breaking macOS FirewallsFire & Ice: Making and Breaking macOS Firewalls
Fire & Ice: Making and Breaking macOS Firewalls
Priyanka Aash
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqela
jobandesther
 
WebAPIs & Apps - Mozilla London
WebAPIs & Apps - Mozilla LondonWebAPIs & Apps - Mozilla London
WebAPIs & Apps - Mozilla London
Robert Nyman
 

Semelhante a Remote Notifications (20)

soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Synack Shakacon OSX Malware Persistence
Synack Shakacon OSX Malware PersistenceSynack Shakacon OSX Malware Persistence
Synack Shakacon OSX Malware Persistence
 
JavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the PlatformJavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the Platform
 
Web Applications with Eclipse RT and Docker in the Cloud
Web Applications with Eclipse RT and Docker in the CloudWeb Applications with Eclipse RT and Docker in the Cloud
Web Applications with Eclipse RT and Docker in the Cloud
 
Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
 	Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W... 	Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
 
Fire & Ice: Making and Breaking macOS Firewalls
Fire & Ice: Making and Breaking macOS FirewallsFire & Ice: Making and Breaking macOS Firewalls
Fire & Ice: Making and Breaking macOS Firewalls
 
Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensions
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqela
 
Kadecot APIs overview
Kadecot APIs overviewKadecot APIs overview
Kadecot APIs overview
 
Building an inflight entertainment system controller in twisted
Building an inflight entertainment system controller in twistedBuilding an inflight entertainment system controller in twisted
Building an inflight entertainment system controller in twisted
 
5.node js
5.node js5.node js
5.node js
 
Build Automation 101
Build Automation 101Build Automation 101
Build Automation 101
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG
 
WebAPIs & Apps - Mozilla London
WebAPIs & Apps - Mozilla LondonWebAPIs & Apps - Mozilla London
WebAPIs & Apps - Mozilla London
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
Building a js widget
Building a js widgetBuilding a js widget
Building a js widget
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Remote Notifications

  • 1. Remote Notifications Integrace desktopu a webu v Javě – jednoduše a bez závislostí! Josef Cacek Siemens IT Solutions and Services Brno
  • 2. System Tray Icon Remote Notifications 2
  • 3. System Tray Icon import java.awt.*; if (SystemTray.isSupported()) { Image img = Toolkit.getDefaultToolkit().getImage("coffee.png"); PopupMenu popup = // ... ; TrayIcon trayIcon = new TrayIcon(img, "My own tooltip", popup); trayIcon.setImageAutoSize(true); //trayIcon.addMouseListener(...); //The MOUSE_ENTERED and MOUSE_EXITED mouse events are not supported. SystemTray.getSystemTray().add(trayIcon); //... trayIcon.displayMessage("Title", "I like it.", TrayIcon.MessageType.INFO); } Remote Notifications 3
  • 5. Windows sounds import java.awt.Toolkit; Runnable sound = (Runnable) Toolkit.getDefaultToolkit().getDesktopProperty("win.sound.asterisk"); if (sound != null) { sound.run(); } // "win.sound.*" properties: // default asterisk exclamation hand question // maximize minimize // menuCommand menuPopup // open close start exit // restoreDown restoreUp Remote Notifications 5
  • 7. HTTP server import com.sun.net.httpserver.*; HttpServer httpServer = HttpServer.create(new InetSocketAddress(80), 0); HttpHandler handler = new HttpHandler() { public void handle(HttpExchange exchange) throws IOException { InputStream is = exchange.getRequestBody(); //... some logic here exchange.getResponseHeaders().add("Content-Type", "text/plain"); exchange.sendResponseHeaders(200, 0); // status - SC_OK, contentLength - chunked OutputStreamWriter osw = new OutputStreamWriter(exchange.getResponseBody()); osw.append("Hello world wide web!nQuery: " + exchange.getRequestURI().getQuery()); is.close(); osw.close(); } }; httpServer.createContext("/", handler); httpServer.start(); Remote Notifications 7
  • 8. HTTP server import com.sun.net.httpserver.*; HttpServer httpServer = HttpServer.create(new InetSocketAddress(80), 0); HttpHandler handler = new HttpHandler() { public void handle(HttpExchange exchange) throws IOException { InputStream is = exchange.getRequestBody(); //... some logic here exchange.getResponseHeaders().add("Content-Type", "text/plain"); exchange.sendResponseHeaders(200, 0); // status - SC_OK, contentLength - chunked OutputStreamWriter osw = new OutputStreamWriter(exchange.getResponseBody()); osw.append("Hello world wide web!nQuery: " + exchange.getRequestURI().getQuery()); is.close(); osw.close(); } }; httpServer.createContext("/", handler); httpServer.start(); Remote Notifications 8
  • 9. Notifier https://github.com/kwart/Notifier Remote Notifications 9
  • 10. Notifier – server spustitelný JAR – $java -jar Notifier.jar [port [defaultIcon [soundDesktopProperty]] výchozí nastavení – port: 8811 – ikona: sun – zvuk: win.sound.asterisk události – jednoduchý klik – návrat k výchozí ikoně – dvojklik – ukončení programu Remote Notifications 10
  • 11. Notifier – klienti jakýkoliv běžný HTTP klient – firefox http://localhost:8811/teddy-bear příkazová řádka – wget -O - http://localhost:8811/warning – curl -d "Build finished succesfully" http://localhost:8811/ok – curl -d "%sname: %smessage" --connect-timeout 3 http://10.0.2.2:8811/bubble Remote Notifications 11
  • 12. Zdrojové kódy ke stažení – https://github.com/kwart/Notifier API dokumentace – System Tray http://download.oracle.com/javase/6/docs/api/java/awt/SystemTray.html – Windows Sounds http://download.oracle.com/javase/1.4.2/docs/guide/swing/1.4/w2k_props.html – HTTP server http://download.oracle.com/javase/6/docs/jre/api/net/httpserver/spec/ šablona prezentace od Chih-Hao Tsai http://technology.chtsai.org/impress/ Remote Notifications 12