Skip to content

Commit b672cab

Browse files
committed
[OSX] make 'show' event optional
Conflicts: src/api/menu/menu.h src/api/menu/menu.js src/api/menu/menu_delegate_mac.mm
1 parent 3a2d954 commit b672cab

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

src/api/menu/menu.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace nwapi {
3030
Menu::Menu(int id,
3131
const base::WeakPtr<DispatcherHost>& dispatcher_host,
3232
const base::DictionaryValue& option)
33-
: Base(id, dispatcher_host, option) {
33+
: enable_show_event_(false), Base(id, dispatcher_host, option) {
3434
Create(option);
3535
}
3636

@@ -63,6 +63,8 @@ void Menu::Call(const std::string& method,
6363
arguments.GetInteger(1, &y);
6464
Popup(x, y, content::Shell::FromRenderViewHost(
6565
dispatcher_host()->render_view_host()));
66+
} else if (method == "EnableShowEvent") {
67+
arguments.GetBoolean(0, &enable_show_event_);
6668
} else {
6769
NOTREACHED() << "Invalid call to Menu method:" << method
6870
<< " arguments:" << arguments;

src/api/menu/menu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ class Menu : public Base {
101101
ui::NwMenuModel* model() { return menu_model_.get(); }
102102
#endif
103103

104+
bool enable_show_event() { return enable_show_event_; }
105+
protected:
106+
bool enable_show_event_;
107+
104108
private:
105109
friend class MenuItem;
106110
friend class Tray;

src/api/menu/menu.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2020

2121
var v8_util = process.binding('v8_util');
22+
var EventEmitter = process.EventEmitter;
23+
2224

2325
function Menu(option) {
2426
if (typeof option != 'object')
@@ -70,9 +72,26 @@ Menu.prototype.popup = function(x, y) {
7072
}
7173

7274
if (require('os').platform() === 'darwin'){
75+
Menu.prototype.on = Menu.prototype.addListener = function(ev, callback) {
76+
if (ev == 'show') {
77+
nw.callObjectMethod(this, 'EnableShowEvent', [ true ]);
78+
}
79+
// Call parent.
80+
EventEmitter.prototype.addListener.apply(this, arguments);
81+
}
82+
83+
Menu.prototype.removeListener = function(ev, callback) {
84+
// Call parent.
85+
EventEmitter.prototype.removeListener.apply(this, arguments);
86+
if (ev == 'show' && EventEmitter.listenerCount(this, 'show') === 0) {
87+
nw.callObjectMethod(this, 'EnableShowEvent', [ false ]);
88+
}
89+
}
90+
7391
Menu.prototype.createMacBuiltin = function (app_name, options) {
7492
var appleMenu = new Menu(),
7593
options = options || {};
94+
7695
appleMenu.append(new exports.MenuItem({
7796
label: nw.getNSStringFWithFixup("IDS_ABOUT_MAC", app_name),
7897
selector: "orderFrontStandardAboutPanel:"

src/api/menu/menu_delegate_mac.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ - (BOOL)menuHasKeyEquivalent:(NSMenu *)menu forEvent:(NSEvent *)event target:(id
3939
}
4040

4141
- (void)menuNeedsUpdate:(NSMenu*)menu {
42+
4243
if (!nwmenu_->enable_show_event() || nwmenu_->dispatcher_host()->run_loop())
4344
return;
4445

@@ -50,6 +51,9 @@ - (void)menuNeedsUpdate:(NSMenu*)menu {
5051
// if ([event type] != NSSystemDefined || [event subtype] == 8)
5152
// return;
5253

54+
if (!nwmenu_->enable_show_event())
55+
return;
56+
5357
base::ListValue args;
5458
base::RunLoop run_loop;
5559
nwmenu_->dispatcher_host()->set_run_loop(&run_loop);

0 commit comments

Comments
 (0)