diff --git a/client/cmd/dexc-desktop/app.go b/client/cmd/dexc-desktop/app.go
index 53fa48f034..9eadd673c4 100644
--- a/client/cmd/dexc-desktop/app.go
+++ b/client/cmd/dexc-desktop/app.go
@@ -379,6 +379,31 @@ func closeAllWindows() {
}
}
+// bindJSFunctions exports functions callable in the frontend
+func bindJSFunctions(w webview.WebView) {
+ w.Bind("isWebview", func() bool {
+ return true
+ })
+
+ w.Bind("openUrl", func(url string) {
+ var err error
+ switch runtime.GOOS {
+ case "linux":
+ err = exec.Command("xdg-open", url).Start()
+ break
+ case "windows":
+ err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
+ break
+ case "darwin":
+ err = exec.Command("open", url).Start()
+ break
+ }
+ if err != nil {
+ log.Errorf(err.Error())
+ }
+ })
+}
+
func runWebview(url string) {
w := webview.New(true)
defer w.Destroy()
@@ -389,6 +414,7 @@ func runWebview(url string) {
w.SetSize(width, height, webview.HintNone)
w.Navigate(url)
+ bindJSFunctions(w)
w.Run()
}
diff --git a/client/webserver/site/src/html/wallets.tmpl b/client/webserver/site/src/html/wallets.tmpl
index fba58bb7b3..a7a4313e15 100644
--- a/client/webserver/site/src/html/wallets.tmpl
+++ b/client/webserver/site/src/html/wallets.tmpl
@@ -770,7 +770,7 @@
|
- …
+ …
|
@@ -812,7 +812,7 @@
diff --git a/client/webserver/site/src/js/app.ts b/client/webserver/site/src/js/app.ts
index 66784b1650..91c0aaebdd 100644
--- a/client/webserver/site/src/js/app.ts
+++ b/client/webserver/site/src/js/app.ts
@@ -98,6 +98,7 @@ export default class Application {
popupNotes: HTMLElement
popupTmpl: HTMLElement
noteReceivers: Record void>[]
+ isWebview: boolean
constructor () {
this.notes = []
@@ -151,6 +152,9 @@ export default class Application {
// use user current locale set by backend
intl.setLocale()
+
+ const w = window as any
+ this.isWebview = (w.isWebview !== undefined)
}
/**
@@ -276,6 +280,11 @@ export default class Application {
// Bind the tooltips.
this.bindTooltips(this.main)
+
+ if (this.isWebview) {
+ // Bind webview URL handlers
+ this.bindUrlHandlers(this.main)
+ }
}
bindTooltips (ancestor: HTMLElement) {
@@ -297,6 +306,19 @@ export default class Application {
})
}
+ bindUrlHandlers (ancestor: HTMLElement) {
+ ancestor.addEventListener('click', function (event: MouseEvent) {
+ if (event === null || event.target === null) return
+
+ const target = event.target as HTMLElement
+ if (target.matches('a[target=_blank]')) {
+ const url = target.getAttribute('href')
+ const w = window as any
+ w.openUrl(url)
+ }
+ }, false)
+ }
+
/* attachHeader attaches the header element, which unlike the main element,
* isn't replaced during page navigation.
*/
diff --git a/client/webserver/site/src/js/wallets.ts b/client/webserver/site/src/js/wallets.ts
index 6df9de4512..7dc3895cec 100644
--- a/client/webserver/site/src/js/wallets.ts
+++ b/client/webserver/site/src/js/wallets.ts
@@ -1061,7 +1061,7 @@ export default class WalletsPage extends BasePage {
tmpl.status.textContent = intl.prep(ticketStatusTranslationKeys[status])
tmpl.hashStart.textContent = tx.hash.slice(0, 6)
tmpl.hashEnd.textContent = tx.hash.slice(-6)
- Doc.bind(tmpl.detailsLink, 'click', () => window.open(coinLink(tx.hash), '_blank'))
+ tmpl.detailsLinkUrl.setAttribute('href', coinLink(tx.hash))
}
}
@@ -1186,7 +1186,7 @@ export default class WalletsPage extends BasePage {
if (tspend.value > 0) tmpl.value.textContent = Doc.formatFourSigFigs(tspend.value / ui.conventional.conversionFactor)
else Doc.hide(tmpl.value)
tmpl.hash.textContent = tspend.hash
- Doc.bind(tmpl.explorerLink, 'click', () => window.open(coinLink(tspend.hash), '_blank'))
+ tmpl.explorerLink.setAttribute('href', coinLink(tspend.hash))
}
const setTKeyPolicy = async (key: string, policy: string) => {