fix(desktop): open external links in system browser (#39820)

This commit is contained in:
Luke Parker 2026-07-31 18:02:11 +10:00 committed by GitHub
commit 2039c90c06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 242 additions and 258 deletions

View file

@ -6,7 +6,6 @@ import { AppBaseProviders, AppInterface } from "@/app"
import { type Platform, PlatformProvider } from "@/context/platform"
import { dict as en } from "@/i18n/en"
import { dict as zh } from "@/i18n/zh"
import { handleNotificationClick } from "@/utils/notification-click"
import { authFromToken } from "@/utils/server"
import pkg from "../package.json"
import { ServerConnection } from "./context/server"
@ -54,7 +53,7 @@ const setStorage = (key: string, value: string | null) => {
const readDefaultServerUrl = () => getStorage(DEFAULT_SERVER_URL_KEY)
const writeDefaultServerUrl = (url: string | null) => setStorage(DEFAULT_SERVER_URL_KEY, url)
const notify: Platform["notify"] = async (title, description, href) => {
const notify: Platform["notify"] = async (title, description, onClick) => {
if (!("Notification" in window)) return
const permission =
@ -73,21 +72,17 @@ const notify: Platform["notify"] = async (title, description, href) => {
})
notification.onclick = () => {
handleNotificationClick(href)
window.focus()
onClick?.()
notification.close()
}
}
const openLink: Platform["openLink"] = (url) => {
window.open(url, "_blank")
}
const back: Platform["back"] = () => {
window.history.back()
}
const forward: Platform["forward"] = () => {
window.history.forward()
const openExternal: Platform["openExternal"] = (value) => {
if (!URL.canParse(value)) return
const url = new URL(value)
if (url.protocol !== "http:" && url.protocol !== "https:" && url.protocol !== "mailto:") return
window.open(url.href, "_blank", "noopener,noreferrer")
}
const restart: Platform["restart"] = async () => {
@ -122,9 +117,7 @@ const clearAuthToken = () => {
const platform: Platform = {
platform: "web",
version: pkg.version,
openLink,
back,
forward,
openExternal,
restart,
notify,
getDefaultServer: async () => {