Create window-like menu on OS X

[亡魂溺海] 提交于 2019-11-29 14:55:20

问题


I'd like to create a same sort of tray menu like this application. Because it is on the list of applications that use node-webkit/nw.js, I think it's possible. I have looked through all the documentation and couldn't find anything on how to achieve that. Searching Google also wasn't really fruitful.

Maybe one of you guys has done this before and could send me in the right direction?


回答1:


First you need to prevent app appear in taskbar

{
    "name": "My App",
    "version": "1.0.0",
    "main": "app.html",
    "window": {
        "show": false,
        "show_in_taskbar": false
    }
}

Then you need to create tray (top bar) menu: (example from his source)

tray = new app.node.gui.Tray({
    title: '',
    icon: 'assets/css/images/menu_icon.png',
    alticon: 'assets/css/images/menu_alticon.png',
    iconsAreTemplates: false
});

Then need create hidden window and show it on click in tray:

// create window
var params = {toolbar: app.devMode, frame: false, transparent: true, resizable: false, show: false};
window = app.node.gui.Window.open('templates/panel.html', params);

function showPopup (x, y) {
  window.on('document-end', function()
    window.moveTo(x - (window.window.width / 2) - 6, y);
    window.show();
    window.focus();
  });
}

// show panel when click in tray
tray.on('click', function (evt) {
  showPopup(evt.x, evt.y);
});


来源:https://stackoverflow.com/questions/28768476/create-window-like-menu-on-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!