Feature: Traditional menu actions in desktop application (#5892)

* 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: 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! 📷🐛

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

* 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

* 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! 📷🐛

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

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

* 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

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Kevin Nadro
2025-03-26 13:03:44 -05:00
committed by GitHub
parent d27b8871bc
commit bb983021b1
19 changed files with 1211 additions and 23 deletions

View File

@ -10,6 +10,7 @@ import {
nativeTheme,
desktopCapturer,
systemPreferences,
Menu,
screen,
} from 'electron'
import path from 'path'
@ -27,11 +28,26 @@ import {
getPathOrUrlFromArgs,
parseCLIArgs,
} from './commandLineArgs'
import * as packageJSON from '../package.json'
import {
buildAndSetMenuForFallback,
buildAndSetMenuForModelingPage,
buildAndSetMenuForProjectPage,
enableMenu,
disableMenu,
} from './menu'
let mainWindow: BrowserWindow | null = null
// Preemptive code, GC may delete a menu while a user is using it as seen in VSCode
// as seen on https://github.com/microsoft/vscode/issues/55347
let oldMenus: Menu[] = []
const scheduleMenuGC = () => {
setTimeout(() => {
oldMenus = []
}, 10000)
}
// Check the command line arguments for a project path
const args = parseCLIArgs(process.argv)
@ -215,6 +231,8 @@ app.on('ready', (event, data) => {
if (mainWindow) return
// Create the mainWindow
mainWindow = createWindow()
// Set menu application to null to avoid default electron menu
Menu.setApplicationMenu(null)
})
// For now there is no good reason to separate these out to another file(s)
@ -386,6 +404,43 @@ ipcMain.handle('find_machine_api', () => {
})
})
// Given the route create the new context menu
// internal menu state will be reset since it creates a new one from
// the initial state
ipcMain.handle('create-menu', (event, data) => {
const page = data.page
if (!(page === 'project' || page === 'modeling' || page === 'fallback')) {
return
}
// Store old menu in our array to avoid GC to collect the menu and crash
const oldMenu = Menu.getApplicationMenu()
if (oldMenu) {
oldMenus.push(oldMenu)
}
if (page === 'project' && mainWindow) {
buildAndSetMenuForProjectPage(mainWindow)
} else if (page === 'modeling' && mainWindow) {
buildAndSetMenuForModelingPage(mainWindow)
} else if (page === 'fallback' && mainWindow) {
buildAndSetMenuForFallback(mainWindow)
}
scheduleMenuGC()
})
ipcMain.handle('enable-menu', (event, data) => {
const menuId = data.menuId
enableMenu(menuId)
})
ipcMain.handle('disable-menu', (event, data) => {
const menuId = data.menuId
disableMenu(menuId)
})
export function getAutoUpdater(): AppUpdater {
// Using destructuring to access autoUpdater due to the CommonJS module of 'electron-updater'.
// It is a workaround for ESM compatibility issues, see https://github.com/electron-userland/electron-builder/issues/7976.