04-29 02:46
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

[WebApp / Node Webkit] Example 6 - Tray Icon 본문

Programming/Web App

[WebApp / Node Webkit] Example 6 - Tray Icon

cinema4dr12 2016. 1. 30. 21:55


이번 글에서는 System Tray Menu를 생성하는 방법을 알아보도록 하겠다. Tray Icon은 Windows의 경우 하단 Task Bar에 Mac OS의 경우 상단에 존재하는 Icon을 의미한다.

Codes

index.html:

<!DOCTYPE html> <html> <head> <title>Context Menu</title> </head> <body style="width: 100%; height: 100%;"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <p>Tray menu.</p> <script> // create node-webkit gui var gui = require('nw.gui'); // create a tray icon var tray = new gui.Tray({ title: "Tray Icon", icon: "img/icon.png" }); // give it a menu var menu = new gui.Menu(); menu.append(new gui.MenuItem({ type: 'checkbox', label: 'tray icon 1', click: function() { console.log("Tray icon 1 clicked."); } })); menu.append(new gui.MenuItem({ type: 'checkbox', label: 'tray icon 2', click: function() { console.log("Tray icon 2 clicked."); } })); menu.append(new gui.MenuItem({ type: 'separator' })); menu.append(new gui.MenuItem({ type: 'checkbox', label: 'Quit', click: function() { gui.App.quit(); } })); tray.menu = menu; // docment started $(document).ready(function() { console.log('App has started.'); }); </script> </body> </html>


// create node-webkit gui
var gui = require('nw.gui');


Node Webkit GUI 라이브러리를 불러온다.


// create a tray icon
var tray = new gui.Tray({
    title: "Tray Icon",
    icon: "./img/icon.png"
});


Tray Icon을 생성한다.


// give it a menu
var menu = new gui.Menu();
menu.append(new gui.MenuItem({
    type: 'checkbox',
    label: 'tray icon',
    click: function() {
        console.log("Tray menu item clicked.");
    }
}));


Tray Icon 클릭 시 제공되는 메뉴를 생성한다.


tray.menu = menu;


Tray에 Menu를 등록한다. 다음은 Tray Icon을 제거하는 코드이다.


// Remove the tray
tray.remove();
tray = null;


Results

Mac OS의 경우 다음과 같이 실행된다. (상단 Task Bar를 주목하도록 한다.)


Windows의 다음과 같이 실행될 것이다.


 

Tray Icon은 다음 이미지를 다운받아 사용한다: 

icon.zip


Comments