1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-10-31 00:17:42 +02:00

Fixing external link click and workaround the export archive/csv problem

This commit is contained in:
Jesús Espino
2021-04-29 15:31:17 +02:00
parent 441deb82ca
commit 58776dd94d
5 changed files with 45 additions and 1 deletions

View File

@@ -4,6 +4,8 @@ import (
"fmt"
"log"
"net"
"os/exec"
"runtime"
"github.com/google/uuid"
"github.com/mattermost/focalboard/server/server"
@@ -62,6 +64,24 @@ func runServer(port int) (*server.Server, error) {
}
func openBrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
log.Fatal(err)
}
}
func main() {
debug := true
w := webview.New(debug)
@@ -84,6 +104,15 @@ func main() {
w.Init(script)
w.Navigate(fmt.Sprintf("http://localhost:%d", port))
w.Bind("openInNewBrowser", openBrowser)
w.Init(`
document.addEventListener('click', function (e) {
let a = e.target.closest('a[target="_blank"]');
if (a) {
openInNewBrowser(a.getAttribute('href'));
}
});
`)
w.Run()
server.Shutdown()
}

View File

@@ -34,6 +34,11 @@ class Archiver {
link.click()
// TODO: Review if this is needed in the future, this is to fix the problem with linux webview links
if ((window as any).openInNewBrowser) {
(window as any).openInNewBrowser(link.href)
}
// TODO: Remove or reuse link
}

View File

@@ -75,6 +75,11 @@ const SidebarUserMenu = React.memo((props: Props) => {
name={intl.formatMessage({id: 'Sidebar.about', defaultMessage: 'About Focalboard'})}
onClick={async () => {
window.open('https://www.focalboard.com?utm_source=webapp', '_blank')
// TODO: Review if this is needed in the future, this is to fix the problem with linux webview links
if ((window as any).openInNewBrowser) {
(window as any).openInNewBrowser('https://www.focalboard.com?utm_source=webapp')
}
}}
/>
</Menu>

View File

@@ -35,6 +35,11 @@ class CsvExporter {
link.click()
// TODO: Review if this is needed in the future, this is to fix the problem with linux webview links
if ((window as any).openInNewBrowser) {
(window as any).openInNewBrowser(encodedUri)
}
// TODO: Remove or reuse link
}

View File

@@ -49,7 +49,7 @@ class Utils {
static htmlFromMarkdown(text: string): string {
// HACKHACK: Somehow, marked doesn't encode angle brackets
const renderer = new marked.Renderer()
renderer.link = (href, title, contents) => `<a target="_blank" rel="noreferrer" href="${href}" title="${title || ''}" onclick="event.stopPropagation();">${contents}</a>`
renderer.link = (href, title, contents) => `<a target="_blank" rel="noreferrer" href="${href}" title="${title || ''}" onclick="event.stopPropagation(); openInNewBrowser && openInNewBrowser('${href}');">${contents}</a>`
const html = marked(text.replace(/</g, '&lt;'), {renderer, breaks: true})
return html
}