🖥️프론트엔드/Electron.js

Electron - Tray 생성 및 클릭 이벤트, Tray 아이콘 변경

Janger 2022. 3. 28. 10:08
728x90
const { app, BrowserWindow, Menu, Tray } = require('electron');


let tray = null
app.whenReady().then(() => {
  tray = new Tray('./icon1.png');

    var contextMenu = Menu.buildFromTemplate([
        { label: 'Hello world!', click:  function(){
            console.log('Hello world!');
            tray.setImage('./icon2.png');
        } },
        { label: 'Quit', click:  function(){
            app.quit();
        } }
    ]);
    tray.setContextMenu(contextMenu);
})

 

Tray 생성 및 클릭 이벤트, Tray 아이콘 변경

 

출처: 

https://www.electronjs.org/docs/latest/api/tray

 

Tray | Electron

Add icons and context menus to the system's notification area.

www.electronjs.org

https://stackoverflow.com/questions/43689286/how-to-update-tray-icon

 

How to update tray icon

In Electron, it is possible to create a tray icon by using new Tray(image), for example: let iconPath = path.join(__dirname, 'icon.png'); appIcon = new Tray(iconPath); As stated in the documentat...

stackoverflow.com

 

728x90