Feature: Traditional menu actions in desktop application part II (#6030)

* chore: skeleton for building and creating menus. Need electron to renderer interface to dynamically set the menu

* chore: skeleton typing for communication between nodes and web side

* chore: more skeleton for the different roles within the menu options, need more type safety

* chore: adding more skeleton and templates of what the menus could be

* chore: implemented first pass for helpRole links

* fix: syntax issue stopped the build step

* feature: loading different menus based on your page

* feature: Home page file role implemented

* chore: handling the build workflow for the signin page

* fix: moving edit actionst to the edit menu

* chore: adding preferences to the file role

* chore: redoing help roles based on the question mark widget

* fix: auto fmt

* chore: examples of accelerator strings for Menu.MenuItems keyboard shortcuts!

* chore: oddly specific toggle API for disabling MenuItems from JS. No rules!

* fix: do not implement a custom label disable thingy, use id on menu and use the native APIga

* fix: auto fmt

* fix: adding some typechecks and auto fmt fixes

* fix: trying to fix custom type?

* fix: nvm we back, the lsp on my editor borked for a second

* fix: adding one more level to the custom type for the labels

* chore: cleaning up type definitions to read easier

* fix: resolving yarn lint errors

* chore: adding file sign out

* chore: adding more file bar actions

* chore: ready for PR draft

* fix: preemptive GC collectoin bug fix if somehow a user interacts with a menu while it is being GCed

* fix: linking the OG source

* fix: set application menu to null to avoid default electron menu

* chore: trying to add more typescript

* chore: BIG workflow changes... better typing, less IPC junk

* fix: remapping the icp functions to the cb option select...

* chore: all og events are rehooked up with new workflow pattern

* feat: adding more options to the native bar!

* fix: todo

* chore: cleaning up some menus and adding more

* fix: desktop vs browser and lint errors

* fix: typescript did not like sample electorn JS code for the basic templates with isMac conditionals...

* fix: PR clean up

* fix: more PR cleanup

* A snapshot a day keeps the bugs away! 📷🐛

* fix: added the new help menu to the default sign in and modeling page

* fix: disabled two menu actions within sign in page since they will not do anything.

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* fix: mergining main, auto fixes

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* fix: saving off progress found an IPC on/off bug thanks electron!

* fix: fixed ipc renderer off/remove listener bug

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* chore: skeleton layout for the file menu in the modeling page.

* fix: adding types

* A snapshot a day keeps the bugs away! 📷🐛

* fix: more skeleton

* feat: adding file preferences project settings

* feat: adding share current part link to file menu

* fix: report a bug to refresha and report a bug

* fix: new type for webContents send payload that does not brick TS

* fix: removing import file from url since it is not working in the command palette for manual user input

* fix: removing old comment

* chore: adding user default units

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* fix: trying to create a new file but I don't think this the correct workflow...

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* fix: disabling create a file and folder until we get it properly implemented at the commad bar level

* fix: hooking up more commands

* fix: auto fixes

* chore: adding standard views

* chore: adding some E2E tests.

* chore: added E2E tests for each file menu

* fix: auto fixes

* chore: adding more edit role E2E tests

* chore: e2e test

* chore: adding help role e2e test

* A snapshot a day keeps the bugs away! 📷🐛

* chore: e2e test for all the menu options you can interact with in the frontend

* chore: hooking up more menu actions

* chore: adding pane actions

* fix: mac only menu fix and added start sketch

* chore: big edit for state management and command registration

* fix: auto fixes, tsc

* fix: codespell typo

* chore: implementing E2E tests for the menus since we cleared them.

* chore: file export current part e2e test

* chore: added all file role tests in modeling page

* chore: modeling page edit e2e tests

* chore: implemented view e2e test for modeling page

* chore: add all design e2e playright tests

* fix: auto linter,fmt

* chore: added modeling help role e2e tests

* fix: ugh this function isn't available in electron evalulate

* fix: new default project name

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
This commit is contained in:
Kevin Nadro
2025-04-04 08:39:02 -05:00
committed by GitHub
parent f1e95156ea
commit 449b43792b
13 changed files with 3161 additions and 33 deletions

View File

@ -1,7 +1,10 @@
import { useEffect } from 'react'
import { NetworkHealthState } from '@src/hooks/useNetworkStatus'
import { isDesktop } from '@src/lib/isDesktop'
import type { WebContentSendPayload } from '@src/menu/channels'
import type { ToolbarModeName } from '@src/lib/toolbar'
import { reportRejection } from '@src/lib/trap'
import { useCommandBarState } from '@src/machines/commandBarMachine'
import type { MenuLabels, WebContentSendPayload } from '@src/menu/channels'
import { useEffect } from 'react'
export function useMenuListener(
callback: (data: WebContentSendPayload) => void
@ -23,3 +26,70 @@ export function useMenuListener(
}
}, [])
}
// Enable disable menu actions specifically based on if you are in the modeling mode of sketching or modeling.
// This is a similar behavior of the command bar which disables action if you are in sketch mode
export function useSketchModeMenuEnableDisable(
currentMode: ToolbarModeName,
overallState: NetworkHealthState,
isExecuting: boolean,
isStreamReady: boolean,
menus: { menuLabel: MenuLabels; commandName?: string; groupId?: string }[]
) {
const commandBarState = useCommandBarState()
const commands = commandBarState.context.commands
useEffect(() => {
const onDesktop = isDesktop()
if (!onDesktop) {
// NO OP for web
return
}
// Same exact logic as the command bar
const disableAllButtons =
(overallState !== NetworkHealthState.Ok &&
overallState !== NetworkHealthState.Weak) ||
isExecuting ||
!isStreamReady
// Enable or disable each menu based on the state of the application.
menus.forEach(({ menuLabel, commandName, groupId }) => {
// If someone goes wrong, disable all the buttons! Engine cannot take this request
if (disableAllButtons) {
window.electron.disableMenu(menuLabel).catch(reportRejection)
return
}
if (commandName && groupId) {
// If your menu is tied to a command bar action, see if the command exists in the command bar
const foundCommand = commands.find((command) => {
return command.name === commandName && command.groupId === groupId
})
if (!foundCommand) {
window.electron.disableMenu(menuLabel).catch(reportRejection)
} else {
if (currentMode === 'sketching') {
window.electron.disableMenu(menuLabel).catch(reportRejection)
} else if (currentMode === 'modeling') {
window.electron.enableMenu(menuLabel).catch(reportRejection)
}
}
} else {
// menu is not tied to a command bar, do the sketch mode check
if (currentMode === 'sketching') {
window.electron.disableMenu(menuLabel).catch(reportRejection)
} else if (currentMode === 'modeling') {
window.electron.enableMenu(menuLabel).catch(reportRejection)
}
}
})
return () => {
if (!onDesktop) {
// NO OP for web
return
}
}
}, [currentMode, commands])
}