在OS X上创建类似窗口的菜单 [英] Create window-like menu on OS X

查看:85
本文介绍了在OS X上创建类似窗口的菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建类似

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?

推荐答案

首先,您需要阻止应用程序出现在任务栏中

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);
});

这篇关于在OS X上创建类似窗口的菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆