Skip to content

Commit

Permalink
Local Environment: Add application menu on non MacOS on development (A…
Browse files Browse the repository at this point in the history
…utomattic#140)

* Local Environment: Add application menu on non MacOS

* Update: Make the menu available on development
  • Loading branch information
kozer authored Mar 14, 2024
1 parent 585467b commit 5a8e2cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ async function appBoot() {

setupIpc();
setupCustomProtocolHandler();
setupMenu();

mainWindow = createMainWindow();
setupMenu( mainWindow );
setupAuthCallbackHandler( mainWindow );
handleAuthOnStartup();
mainWindow.on( 'closed', () => ( mainWindow = null ) );
Expand Down
20 changes: 13 additions & 7 deletions src/menu.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { Menu, type MenuItemConstructorOptions, app } from 'electron';
import { Menu, type MenuItemConstructorOptions, app, BrowserWindow } from 'electron';
import { __ } from '@wordpress/i18n';
import { manualCheckForUpdates } from './updates';

export function setupMenu() {
// We only show a menu on macOS.
// Setting the application menu to null will remove it from all windows we create.
if ( process.platform !== 'darwin' ) {
export function setupMenu( window: BrowserWindow | null ) {
if ( ! window && process.platform !== 'darwin' ) {
Menu.setApplicationMenu( null );
return;
}

const crashTestMenuItems: MenuItemConstructorOptions[] = [
{
label: __( 'Test Hard Crash (dev only)' ),
Expand Down Expand Up @@ -96,5 +93,14 @@ export function setupMenu() {
},
] );

Menu.setApplicationMenu( menu );
if ( process.platform === 'darwin' ) {
Menu.setApplicationMenu( menu );
return;
}
// Make menu accessible in development for non-macOS platforms
if ( process.env.NODE_ENV === 'development' ) {
window?.setMenu( menu );
return;
}
Menu.setApplicationMenu( null );
}

0 comments on commit 5a8e2cd

Please sign in to comment.