]> khamidou — GitHub mirrors - electron.git/commitdiff
Fix menu-item using deprecated API
authorEran Tiktin <eran.t@mce-sys.com>
Sat, 21 Nov 2015 23:13:57 +0000 (01:13 +0200)
committerEran Tiktin <eran.t@mce-sys.com>
Sat, 21 Nov 2015 23:13:57 +0000 (01:13 +0200)
Some of the roles in menu-item use methods on BrowserWindow instead of
WebContents which outputs a deprecation warning.
I changed it to use the correct methods.

atom/browser/api/lib/menu-item.coffee

index 92e2283b417d57a372fc0597bb291ed604252600..57beb6ffdae37cd280a66e92c7427097b5a35bff 100644 (file)
@@ -13,6 +13,11 @@ rolesMap =
   minimize: 'minimize'
   close: 'close'
 
+# Maps methods that should be called directly on the BrowserWindow instance
+methodInBrowserWindow =
+  minimize: true
+  close: true
+
 class MenuItem
   @types = ['normal', 'separator', 'submenu', 'checkbox', 'radio']
 
@@ -42,8 +47,12 @@ class MenuItem
       # Manually flip the checked flags when clicked.
       @checked = !@checked if @type in ['checkbox', 'radio']
 
-      if @role and rolesMap[@role] and process.platform isnt 'darwin'
-        focusedWindow?[rolesMap[@role]]()
+      if @role and rolesMap[@role] and process.platform isnt 'darwin' and focusedWindow?
+        methodName = rolesMap[@role]
+        if methodInBrowserWindow[methodName]
+          focusedWindow[methodName]()
+        else
+          focusedWindow.webContents?[methodName]()
       else if typeof click is 'function'
         click this, focusedWindow
       else if typeof @selector is 'string'