Skip to content

[v2, darwin] Fix updating menus - #4057

Merged
leaanthony merged 1 commit into
masterfrom
feature/darwin-fix-menu-updates
Feb 10, 2025
Merged

leaanthony merged 1 commit into
masterfrom
feature/darwin-fix-menu-updates

Conversation

@stffabi

@stffabi stffabi commented Feb 10, 2025 •

Copy link
Copy Markdown
Contributor

Fixes #4053

Summary by CodeRabbit

  • Bug Fixes

    • Fixed macOS menu updating issues for smoother application interactions.
  • New Features

    • Enabled external configuration for the minimum macOS version.
    • Enhanced the Mac App Store guide to support app names containing spaces.
  • Documentation

    • Updated the changelog with recent fixes and enhancements.
    • Removed outdated documentation references and upgraded to Go 1.23.

@stffabi
stffabi requested a review from leaanthony February 10, 2025 09:03
@coderabbitai

coderabbitai Bot commented Feb 10, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request refactors the macOS menu update process in the darwin package. The Window struct now contains an applicationMenu field, and the original menu-setting logic in SetApplicationMenu has been replaced by storing the menu and invoking a new UpdateApplicationMenu method. This method creates a new menu via NewNSMenu and applies it using C.SetAsApplicationMenu. Additionally, the changelog has been updated to document fixes to MacOS menu updates, remove an outdated module name reference, adjust a guide script for app names with spaces, and specify an external macOS minimum version along with an upgrade to Go 1.23.

Changes

File Change Summary
v2/.../darwin/window.go Added applicationMenu *menu.Menu to Window. Modified SetApplicationMenu to store the menu and call a new method UpdateApplicationMenu, which creates a new menu with NewNSMenu and sets it using C.SetAsApplicationMenu.
website/.../changelog.mdx Added a new changelog entry under "Fixed" for MacOS menu update issues, removed an outdated documentation reference regarding go.mod, updated the Mac App Store guide script for app names with spaces, introduced external macOS minimum version setting, and upgraded to Go 1.23.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Window
    participant NSMenu as NewNSMenu
    participant C as C API

    Caller->>Window: Call SetApplicationMenu(menu)
    Window->>Window: Store menu in applicationMenu
    Window->>Window: Call UpdateApplicationMenu()
    Window->>NSMenu: Create new menu (NewNSMenu)
    NSMenu-->>Window: Return new Menu instance
    Window->>C: Set new menu via SetAsApplicationMenu
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix menu update behavior when changing disabled property (#4053) ❓ Refactored update flow, but no explicit reinstatement of the removed call; impact on disabled property update remains unclear.

Poem

I'm a bunny in the code, hopping with delight,
New fields and functions make my menus shine bright.
I nibble on bugs and munch on refined change,
Escaping old paths in a hop over range.
With ASCII wiggles and a carrot's cheer,
This rabbit codes happily through each new premier!
🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
v2/internal/frontend/desktop/darwin/window.go (1)

301-308: Consider adding error handling

While the implementation is good, consider adding error handling for potential edge cases:

  1. Error handling for NewNSMenu failure
  2. Validation of menu processing results

Example error handling:

 func (w *Window) UpdateApplicationMenu() {
+    var err error
     mainMenu := NewNSMenu(w.context, "")
+    if mainMenu == nil {
+        log.Printf("Failed to create main menu")
+        return
+    }
     if w.applicationMenu != nil {
-        processMenu(mainMenu, w.applicationMenu)
+        if err = processMenu(mainMenu, w.applicationMenu); err != nil {
+            log.Printf("Failed to process menu: %v", err)
+            return
+        }
     }
     C.SetAsApplicationMenu(w.context, mainMenu.nsmenu)
     C.UpdateApplicationMenu(w.context)
 }
website/src/pages/changelog.mdx (1)

36-36: Fix macOS spelling in changelog

The operating system name should be "macOS" instead of "MacOS" to align with Apple's branding.

-Fixed updating menus on MacOS by [@stffabi](https://github.com/stffabi)
+Fixed updating menus on macOS by [@stffabi](https://github.com/stffabi)
🧰 Tools
🪛 LanguageTool

[grammar] ~36-~36: The operating system from Apple is written “macOS”.
Context: .../leaanthony) - Fixed updating menus on MacOS by [@stffabi](https://github.com/stffab...

(MAC_OS)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bedebe0 and 733cd24.

📒 Files selected for processing (2)
  • v2/internal/frontend/desktop/darwin/window.go (2 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
website/src/pages/changelog.mdx

[grammar] ~36-~36: The operating system from Apple is written “macOS”.
Context: .../leaanthony) - Fixed updating menus on MacOS by [@stffabi](https://github.com/stffab...

(MAC_OS)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (2)
v2/internal/frontend/desktop/darwin/window.go (2)

33-37: LGTM: Added applicationMenu field to Window struct

The addition of the applicationMenu field to store the menu state is a good design choice, allowing for better state management and menu updates.


296-299: LGTM: Improved menu update logic

The refactored SetApplicationMenu method now properly separates concerns by:

  1. Storing the menu state
  2. Delegating the actual menu update to UpdateApplicationMenu

This makes the code more maintainable and easier to understand.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying wails with  Cloudflare Pages  Cloudflare Pages

Latest commit: 733cd24
Status: ✅  Deploy successful!
Preview URL: https://c77daaed.wails.pages.dev
Branch Preview URL: https://feature-darwin-fix-menu-upda.wails.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Menu not updating when changing disabled property and calling runtime.MenuUpdateApplicationMenu

2 participants