Repository navigation
🐛 fix: update dialog hyperlinks opening in Electron window - #616
Conversation
Added a click handler for markdown links to open them in system browser.
Summary of ChangesHello @uarix, 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! 此拉取请求旨在修复一个关键的用户体验问题,即当用户点击更新弹窗中发布的 GitHub 超链接时,链接会在 Electron 应用程序内部打开,导致用户无法正常浏览外部内容并可能被困在更新页面。通过引入一个事件处理机制,现在所有此类链接都将被正确地重定向到用户的系统默认浏览器中打开,从而提供更流畅和预期的交互体验。 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
|
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where clicking hyperlinks in the update dialog's release notes would open within the Electron window instead of the system browser, causing users to get stuck on the update page.
Key Changes
- Added click event handler to the markdown container to intercept link clicks
- Implemented
handleMarkdownClickfunction that prevents default behavior and useswindow.open(href, '_blank')to trigger the main window'ssetWindowOpenHandlerconfiguration
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (target.tagName?.toUpperCase() === "A") { | ||
| event.preventDefault(); | ||
| const href = target.getAttribute("href"); | ||
| if (href) { |
There was a problem hiding this comment.
The href attribute obtained from the link should be validated before opening to prevent potential XSS attacks through javascript: or data: URLs. Consider adding validation to only allow http:// and https:// protocols, similar to the check in main-window.ts:
if (href && (href.startsWith("https://") || href.startsWith("http://"))) {
window.open(href, "_blank");
}| if (href) { | |
| if (href && (href.startsWith("https://") || href.startsWith("http://"))) { |
| const handleMarkdownClick = (event: MouseEvent) => { | ||
| const target = event.target as HTMLElement; | ||
| // 检查是否点击的是链接 | ||
| if (target.tagName?.toUpperCase() === "A") { | ||
| event.preventDefault(); | ||
| const href = target.getAttribute("href"); | ||
| if (href) { | ||
| window.open(href, "_blank"); | ||
| } | ||
| } | ||
| }; |
There was a problem hiding this comment.
当前实现只检查 event.target 是否为 <a> 标签。如果链接内嵌了其他 HTML 元素(例如 <a><strong>text</strong></a>),点击 <strong> 元素时 event.target 将是 <strong> 而不是 <a>,导致链接点击失效。
建议使用 element.closest('a') 从事件目标向上查找最近的 <a> 标签,这样可以更可靠地处理所有内嵌元素的链接点击,使代码更健壮。
const handleMarkdownClick = (event: MouseEvent) => {
const target = event.target as HTMLElement;
// 从事件目标向上遍历,查找最近的 <a> 标签
const anchor = target.closest('a');
// 如果找到了 <a> 标签并且它有 href 属性
if (anchor?.href) {
// 阻止默认的导航行为
event.preventDefault();
// 使用 window.open 在用户的默认浏览器中打开链接
window.open(anchor.href, '_blank');
}
};
修复了点击更新弹窗中的 Github 超链接会在 Electron 窗口内直接跳转,导致用户被困在更新页面的问题。
这个 PR 在 UpdateApp.vue 的 Markdown 容器中增加了点击处理逻辑来拦截链接,使用 window.open(href, '_blank') 从而触发主窗口现有的 setWindowOpenHandler 配置,调用系统浏览器来打开这些 URL。