TidGi-Desktop/docs/internal/MenuSystem.md
lin onetwo 949c7b00bb
Fix/misc bug1 (#688)
* fix: possible error on wiki creation

* Add isSubWiki/mainWikiToLink and optimize tidgi.config

Introduce new syncable wiki fields (isSubWiki, mainWikiToLink) with schema, types, and defaults; add localization for an autofill note. Expose Database.readWikiConfig over IPC and implement readTidgiConfig usage. When updating workspaces, only write tidgi.config.json if syncable fields actually changed to avoid redundant O(n) disk writes. Update AddWorkspace UI to eagerly read tidgi.config.json (when enabled) to pre-fill form fields and show a helper note. Improve workspace hibernation logic: avoid hibernating page workspaces' servers when switching and prevent concurrent duplicate hibernation calls. Also update template submodule reference.

* Update ErrorDuringRelease.md

* Fix workspace config sync and sub-workspace settings

* adjust menu

* Add sub-workspace UI, view navigation & types

Expose view navigation helpers and types, add sub-workspace UI and related translations, and introduce provider registry types.

- Add canGoBack/canGoForward/goBack/goForward APIs to view service and IPC interface to allow navigating embedded views.
- Implement UI for sub-workspace management in EditWorkspace: list bound sub-workspaces, open sub-workspace settings, and select main workspace for sub-wikis. Add tests IDs and small UX tweaks (cancel button test id).
- Update SaveAndSyncOptions and SubWorkspaceRouting to reflect new sub-workspace flows and remove deprecated main workspace path field.
- Add provider registry interface that re-exports external API types and IPC descriptor (src/services/providerRegistry/interface.ts).
- Add ambient type declarations for @modelcontextprotocol SDK client transports.
- Improve test/e2e support: detect packaged e2e runs via --test-scenario arg in environment constants, update step definition to open edit workspace via the window service using WindowNames, and adjust feature file assertions for sub-wiki bindings.
- Add English and Simplified Chinese translation keys for sub-workspace UI strings.

These changes enable managing sub-workspaces from the Edit Workspace window, provide programmatic view navigation, and add types/interfaces required for integrating external provider tooling and tests.

* fix lint

* Add diagnostics, process monitoring, and menu improvements

Add process diagnostics and monitoring: introduce shared processInfo types, native.getProcessInfo and startProcessMonitoring (30s snapshots + logs), label the main Node process and give descriptive initial window titles; include renderer PIDs in view info and log view creation. Unified Developer Tools panel into a Process & View Diagnostics dialog that shows Node/renderer memory and wiki worker info (wiki.getWorkersInfo). Fix FileSystemAdaptor to pass old fileInfo to generateTiddlerFileInfo to avoid numeric suffixes when overwriting tiddlers. Menu and workspace changes: add a Sync menu and move git items there, simplify context menu generation, remove some developer menu items, and adjust createBackupMenuItems signature. Window and workspace improvements: add recreateUnlessWorkspaceID option and safer window close handling, restore hibernated flag when bringing workspace views up, and improve sub-workspace settings UI. Also add several i18n entries for the new diagnostics and UI text.

* Add renderer metrics; fix hibernation & menus

Collect and display renderer process metrics and harden workspace/window logic.

Highlights:
- Add new i18n keys for renderer PID/CPU/private memory (en and zh-Hans).
- Native service: check and throw on shell.openPath errors; gather per-renderer metrics (private/working set KB and cpu percent) via app.getAppMetrics() and webContents, and improve logging.
- Extend IRendererProcessInfo with private_KB, workingSet_KB and cpu_percent.
- DeveloperTools UI: show PID tooltip, private memory and CPU columns, sort renderers by memory, color-code values, and fix SquirrelTemp path/openPath call.
- Git/menu changes: consolidate backup/sync items to include AI option inline; only show sync for cloud workspaces with a git remote and authenticated user; always show local backup.
- Workspaces/view: prevent races when switching to a workspace by tracking hibernation as awaitable promises (Map), awaiting in-flight hibernations, and re-fetching workspace state before actions.
- View/window safety: add null/undefined checks for view.webContents in several handlers (setupViewEventHandlers, handleAttachToTidgiMiniWindow) to avoid operations on destroyed/closed webContents.

These changes improve diagnostics, prevent race conditions, and make menu behavior more consistent.

* fix: lint errors - remove unused WindowNames import, fix import order and indentation

* fix: address review comments - remove mainWikiToLink from syncable config (absolute path unsafe to sync), fix missing-field detection in syncableChanged, precompute viewsInfo Map in renderer table, use stable pid as row key

* fix: auto-expand SubWorkspaceRouting accordion when bound sub-wikis exist, so e2e test selectors are visible

* fix: update e2e test menu paths - git/sync items moved from Wiki menu to Sync menu

* fix: stabilize sync settings and e2e sync helper
2026-03-23 02:48:46 +08:00

52 lines
2.3 KiB
Markdown

# Menu System Overview
This document describes the menu registration and context menu system in TidGi-Desktop, including how right-click context menus and application menus are registered, how they are shared or separated, and the main extension points for workspace-related actions.
## Menu Registration Entry Points
### Application Menubar (Main Process)
- Registered via `src/services/menu/index.ts` using the `MenuService` class.
- Menus are built from a template and can be extended by calling `insertMenu` from various service modules (e.g., `workspaces/registerMenu.ts`, `windows/registerMenu.ts`).
- The menubar is rebuilt whenever new items are inserted.
### Context Menus (Webview & Workspace Icon)
- Webview right-click: Registered by `MenuService.initContextMenuForWindowWebContents`, which listens to the Electron `context-menu` event on each window's webContents.
- Workspace icon right-click: Handled in the renderer by `SortableWorkspaceSelectorButton.tsx`, which calls `getSimplifiedWorkspaceMenuTemplate` and triggers `window.remote.buildContextMenuAndPopup`.
- Both use the same menu template logic for workspace-related actions, ensuring consistency.
## Menu Template Structure
### getSimplifiedWorkspaceMenuTemplate
- Used for both context menu entry points.
- Provides frequently used workspace actions (AI, edit, git history, etc.) and a "Current Workspace" submenu with the full set of actions.
- Calls `getWorkspaceMenuTemplate` for the submenu.
### getWorkspaceMenuTemplate
- Returns the full set of actions for a workspace, including:
- Open workspace tiddler
- Open in new window
- Edit workspace
- View git history
- Open workspace folder (in file manager, editor, or Git GUI)
- Open in browser (if HTTP API enabled)
- Remove workspace
- Backup/Sync (if applicable)
- Restart/Reload (for main wikis)
- Back/Forward navigation (for main wikis)
## Extending the Menu
- To add new workspace actions, extend `getWorkspaceMenuTemplate`.
- To add global actions, use `MenuService.insertMenu` from any service module.
---
This design ensures that both the application menubar and all context menus remain consistent, extensible, and easy to maintain. For more details, see:
- `src/services/menu/index.ts`
- `src/services/workspaces/getWorkspaceMenuTemplate.ts`
- `src/pages/Main/WorkspaceIconAndSelector/SortableWorkspaceSelectorButton.tsx`