mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 11:20:07 +08:00
* feat: open popup url in external browser * fix: allow google auth popup internal * feat: add functionality(including settings) to open links in external browser for webviews * fix: set useragent globally * fix: remove setUserAgent in webview * fix: set Chrome version to newest
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { session, shell, webContents } from 'electron'
|
|
|
|
/**
|
|
* init the useragent of the webview session
|
|
* remove the CherryStudio and Electron from the useragent
|
|
*/
|
|
export function initSessionUserAgent() {
|
|
const wvSession = session.fromPartition('persist:webview')
|
|
const newChromeVersion = '135.0.7049.96'
|
|
const originUA = wvSession.getUserAgent()
|
|
const newUA = originUA
|
|
.replace(/CherryStudio\/\S+\s/, '')
|
|
.replace(/Electron\/\S+\s/, '')
|
|
.replace(/Chrome\/\d+\.\d+\.\d+\.\d+/, `Chrome/${newChromeVersion}`)
|
|
|
|
wvSession.setUserAgent(newUA)
|
|
}
|
|
|
|
/**
|
|
* WebviewService handles the behavior of links opened from webview elements
|
|
* It controls whether links should be opened within the application or in an external browser
|
|
*/
|
|
export function setOpenLinkExternal(webviewId: number, isExternal: boolean) {
|
|
const webview = webContents.fromId(webviewId)
|
|
if (!webview) return
|
|
|
|
webview.setWindowOpenHandler(({ url }) => {
|
|
if (isExternal) {
|
|
shell.openExternal(url)
|
|
return { action: 'deny' }
|
|
} else {
|
|
return { action: 'allow' }
|
|
}
|
|
})
|
|
}
|