Electron.NET icon indicating copy to clipboard operation
Electron.NET copied to clipboard

macOS menu support

Open GregorBiswanger opened this issue 8 years ago • 5 comments

The Menu API needs an other Menu implementation for the macOS: https://electron.atom.io/docs/api/menu/#notes-on-macos-application-menu

GregorBiswanger avatar Oct 24 '17 15:10 GregorBiswanger

Is this still needed? I'll do this.

rakista112 avatar Oct 01 '20 00:10 rakista112

Hi, yes that would be great!

Here is a video tutorial on how to code at Electron.NET: https://youtu.be/Po-saU_Z6Ws

GregorBiswanger avatar Oct 01 '20 07:10 GregorBiswanger

Yeah, I'm following it right now

rakista112 avatar Oct 04 '20 11:10 rakista112

@GregorBiswanger making menus for Mac doesn't seem to need modifications to API. I made this menu using our existing API. Screen Shot 2020-10-06 at 10 19 03 AM

You just have to format the menu according to official Electron's Menu. Just follow the ones with the isMac boolean check.

Here's the code I used.

var menu = new MenuItem[]
            {
                new MenuItem
                {
                    Label = "Prefix",
                    Submenu = new MenuItem[]
                    {
                        new MenuItem { Role = MenuRole.about },
                        new MenuItem { Type = MenuType.separator },
                        new MenuItem { Role = MenuRole.services },
                        new MenuItem { Type = MenuType.separator },
                        new MenuItem { Role = MenuRole.hide },
                        new MenuItem { Role = MenuRole.hideothers },
                        new MenuItem { Type = MenuType.separator },
                        new MenuItem { Role = MenuRole.quit }
                    }
                },
                new MenuItem
                {
                    Label = "MacTest",
                    Submenu = new MenuItem[]
                    {
                        new MenuItem { Label = "Do nothing."}
                    }
                },
                new MenuItem
                {
                    Label = "View",
                    Submenu = new MenuItem[]
                    {
                        new MenuItem { Role = MenuRole.reload },
                        new MenuItem { Role = MenuRole.toggledevtools }
                    }
                }
            };

            Electron.Menu.SetApplicationMenu(menu);

rakista112 avatar Oct 06 '20 02:10 rakista112

Can confirm that it works fine.

The only weird thing is that in MacOS there is no "quit" option so cmd+Q doesn't work out of the gates.

cosmo0 avatar Mar 16 '21 22:03 cosmo0