Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry when shellnotifyicon fails #3710

Merged
merged 8 commits into from
Sep 2, 2024

Conversation

DeltaLaboratory
Copy link

@DeltaLaboratory DeltaLaboratory commented Aug 27, 2024

Description

Fixes #3693
I choose 4 for retry and 2 second for delay, no real reason

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Windows
  • macOS
  • Linux

Test Configuration

Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced the system tray icon setup with a retry mechanism, allowing the application to handle temporary failures more gracefully.
  • Bug Fixes

    • Added a changelog entry addressing a critical system tray startup issue on Windows, preventing unexpected application crashes.

Copy link
Contributor

coderabbitai bot commented Aug 27, 2024

Walkthrough

The changes in the systemtray_windows.go file introduce a retry mechanism in the run method of the windowsSystemTray struct. This enhancement allows the method to attempt adding a notification icon up to six times, with a 500-millisecond pause between attempts. This approach addresses potential transient failures when the shell is not available.

Changes

Files Change Summary
v3/pkg/application/systemtray_windows.go Implemented a retry logic in the run method for adding a notification icon, allowing up to six retries with a 500-millisecond delay. Also, included an import statement for the time package.
mkdocs-website/docs/en/changelog.md Added a new entry for version v3.0.0-alpha.6, documenting the fix for the system tray startup panic on Windows.

Assessment against linked issues

Objective Addressed Explanation
Retry mechanism for ShellNotifyIcon failures (#3693)
Allow developer to handle errors related to ShellNotifyIcon (#3693)

Poem

🐰 In the tray where icons play,
A little retry saves the day!
With hops and jumps, we won’t despair,
For every fail, we’ll try with care.
So here’s to code, robust and bright,
A toast to fixes, let’s take flight! 🎉


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 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.

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.
Early access features: disabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: Anthropic claims that the new Claude model has stronger code understanding and code generation capabilities than their previous models. Note: Our default code review model was also updated late last week. Please compare the quality of the reviews between the two models by toggling the early access feature.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 88c9017 and 51fd0b2.

Files selected for processing (1)
  • v3/pkg/application/systemtray_windows.go (2 hunks)

for retries := range 4 {
if !w32.ShellNotifyIcon(w32.NIM_ADD, &nid) {
if retries == 3 {
panic(syscall.GetLastError())
Copy link
Contributor

@coderabbitai coderabbitai bot Aug 27, 2024

Choose a reason for hiding this comment

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

Consider alternative error handling instead of panic.

Using panic for error handling may not be ideal in production code. Consider returning an error or using a more graceful error handling mechanism.

Suggested changes:

Modify the function signature to return an error and handle the error appropriately:

-func (s *windowsSystemTray) run() {
+func (s *windowsSystemTray) run() error {
	// existing code...

	for retries := range 4 {
		if !w32.ShellNotifyIcon(w32.NIM_ADD, &nid) {
			if retries == 3 {
-				panic(syscall.GetLastError())
+				return fmt.Errorf("ShellNotifyIcon failed after %d retries: %w", retries+1, syscall.GetLastError())
			}
			time.Sleep(2 * time.Second)
			continue
		}
		break
	}

	// existing code...
}

-	s.run()
+	if err := s.run(); err != nil {
+		log.Fatalf("Failed to run system tray: %v", err)
+	}

Committable suggestion was skipped due to low confidence.

Copy link
Member

Choose a reason for hiding this comment

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

@DeltaLaboratory - I think this is a valid comment from the rabbit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Author

@DeltaLaboratory DeltaLaboratory Aug 28, 2024

Choose a reason for hiding this comment

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

@leaanthony I think this is a good idea, but in the current codebase how can we modify this to allow user to handle error?
maybe like:

func (s *SystemTray) Run() error {
	s.impl = newSystemTrayImpl(s)

	if s.attachedWindow.Window != nil {
		// Setup listener
		s.attachedWindow.Window.On(events.Common.WindowLostFocus, func(event *WindowEvent) {
			s.attachedWindow.Window.Hide()
			// Special handler for Windows
			if runtime.GOOS == "windows" {
				// We don't do this unless the window has already been shown
				if s.attachedWindow.hasBeenShown == false {
					return
				}
				s.attachedWindow.justClosed = true
				go func() {
					time.Sleep(s.attachedWindow.Debounce)
					s.attachedWindow.justClosed = false
				}()
			}
		})
	}

	return InvokeSyncWithError(s.impl.run)
}

Copy link
Member

Choose a reason for hiding this comment

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

Pushed an update.

v3/pkg/application/systemtray_windows.go Outdated Show resolved Hide resolved
@leaanthony
Copy link
Member

Thanks for taking the time to open this. It would be better to use smaller sleeps and a higher number of attempts. I'm concerned this is a blocking operation so it would be better to minimise the delay here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 51fd0b2 and 6cdfe2a.

Files selected for processing (1)
  • v3/pkg/application/systemtray_windows.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • v3/pkg/application/systemtray_windows.go

@DeltaLaboratory
Copy link
Author

I checked out some Windows startup times and noticed there's usually about a 3-second gap between when programs start loading and when the desktop is ready to go. So, I adjusted the settings to wait 500 milliseconds and try 6 times.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6cdfe2a and 00a835e.

Files selected for processing (1)
  • v3/pkg/application/systemtray_windows.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • v3/pkg/application/systemtray_windows.go

@leaanthony
Copy link
Member

Thanks 🙏 Please could you add an entry to the changelog located at mkdocs-website/docs/changelog.md? Thanks!

@DeltaLaboratory
Copy link
Author

added changelog

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 00a835e and 8108b05.

Files selected for processing (1)
  • mkdocs-website/docs/en/changelog.md (1 hunks)
Additional comments not posted (1)
mkdocs-website/docs/en/changelog.md (1)

26-26: Changelog Entry Review

The new changelog entry for the fix related to the system tray startup issue on Windows is correctly formatted and placed under the Fixed section for the current unreleased version. The entry clearly links to the issue and credits the contributor, which is in line with the project's documentation standards.

The changelog entry is approved as it meets the project standards and provides the necessary information.

@DeltaLaboratory
Copy link
Author

hello, is there anything blocking this merge?

@leaanthony
Copy link
Member

leaanthony commented Sep 1, 2024

Just time :-) I think it would be better to use globalApplication.fatal with a decent error message than using panic. Thoughts?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8108b05 and 6ac9018.

Files selected for processing (1)
  • mkdocs-website/docs/en/changelog.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • mkdocs-website/docs/en/changelog.md

Copy link

sonarqubecloud bot commented Sep 2, 2024

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6ac9018 and 197f0e3.

Files selected for processing (1)
  • v3/pkg/application/systemtray_windows.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • v3/pkg/application/systemtray_windows.go

@leaanthony leaanthony merged commit 2460b57 into wailsapp:v3-alpha Sep 2, 2024
14 of 15 checks passed
@DeltaLaboratory DeltaLaboratory deleted the fix/tray-icon-retry branch September 2, 2024 14:02
leaanthony added a commit that referenced this pull request Sep 4, 2024
* add retry mechanism for create shell notification icon

* add retry mechanism for create shell notification icon

* adjust delay and attempts

* added changelog

* Use application fatal handler instead of panic

---------

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
leaanthony added a commit that referenced this pull request Sep 12, 2024
* add retry mechanism for create shell notification icon

* add retry mechanism for create shell notification icon

* adjust delay and attempts

* added changelog

* Use application fatal handler instead of panic

---------

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
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.

2 participants