fix: properly open link on macos#11
Conversation
Summary of ChangesHello @skynet2, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where links were not opening correctly, particularly on macOS, by implementing a robust cross-platform solution. It introduces a new utility function that intelligently selects the correct command to open a URL based on the operating system, thereby enhancing the application's compatibility and user experience across Windows, macOS, and Linux environments. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #11 +/- ##
==========================================
- Coverage 24.09% 23.58% -0.52%
==========================================
Files 9 10 +1
Lines 415 424 +9
==========================================
Hits 100 100
- Misses 314 323 +9
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request refactors the logic for opening a browser URL into a new utility function, utils.OpenBrowser, which correctly handles different operating systems including macOS, Linux, and Windows. This is a positive change that improves modularity and fixes the issue with opening links on macOS. My review includes suggestions to enhance error handling by wrapping errors with more context, which will improve debuggability.
| if err = utils.OpenBrowser(targetUrl); err != nil { | ||
| i.ShowAlert() | ||
| return errors.Wrap(err, "failed to open url") | ||
| return err |
There was a problem hiding this comment.
The error returned from utils.OpenBrowser is now returned directly. The previous implementation wrapped the error with "failed to open url", which provides valuable context for debugging. It would be best to restore this error wrapping to maintain clear error messages.
| return err | |
| return errors.Wrap(err, "failed to open url") |
| func OpenBrowser(url string) error { | ||
| switch runtime.GOOS { | ||
| case "windows": | ||
| return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() | ||
| case "darwin": | ||
| return exec.Command("open", url).Start() | ||
| case "linux": | ||
| return exec.Command("xdg-open", url).Start() | ||
| default: | ||
| return errors.Newf("unsupported platform: %s", runtime.GOOS) | ||
| } | ||
| } |
There was a problem hiding this comment.
This is a great utility function. To make it more robust and provide better diagnostics, consider wrapping the errors from cmd.Start() with context about the operating system. This will make the function more self-contained and easier to debug if it's used elsewhere.
| func OpenBrowser(url string) error { | |
| switch runtime.GOOS { | |
| case "windows": | |
| return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() | |
| case "darwin": | |
| return exec.Command("open", url).Start() | |
| case "linux": | |
| return exec.Command("xdg-open", url).Start() | |
| default: | |
| return errors.Newf("unsupported platform: %s", runtime.GOOS) | |
| } | |
| } | |
| func OpenBrowser(url string) error { | |
| var cmd *exec.Cmd | |
| switch runtime.GOOS { | |
| case "windows": | |
| cmd = exec.Command("rundll32", "url.dll,FileProtocolHandler", url) | |
| case "darwin": | |
| cmd = exec.Command("open", url) | |
| case "linux": | |
| cmd = exec.Command("xdg-open", url) | |
| default: | |
| return errors.Newf("unsupported platform: %s", runtime.GOOS) | |
| } | |
| if err := cmd.Start(); err != nil { | |
| return errors.Wrapf(err, "failed to open browser on %s", runtime.GOOS) | |
| } | |
| return nil | |
| } |
Closes #10