Skip to content

Commit 75c54b9

Browse files
committed
add OpenBrowser method
1 parent f4a8663 commit 75c54b9

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

app.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"io"
1515
"log"
1616
"os"
17+
"os/exec"
18+
"runtime"
1719
"strings"
1820

1921
"github.com/disintegration/imaging"
@@ -61,6 +63,24 @@ type Placeholder struct {
6163
Transform string `json:"transform"`
6264
}
6365

66+
func (a *App) OpenBrowser(url string) {
67+
var err error
68+
69+
switch runtime.GOOS {
70+
case "linux":
71+
err = exec.Command("xdg-open", url).Start()
72+
case "windows":
73+
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
74+
case "darwin":
75+
err = exec.Command("open", url).Start()
76+
default:
77+
err = fmt.Errorf("unsupported platform")
78+
}
79+
if err != nil {
80+
log.Fatal(err)
81+
}
82+
}
83+
6484
func (a *App) Proceed(b64image string, placehldr string, csvData string) string {
6585
reader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(b64image))
6686
m, _, err := image.Decode(reader)

frontend/wailsjs/go/main/App.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33

44
export function Greet(arg1:string):Promise<string>;
55

6+
export function OpenBrowser(arg1:string):Promise<void>;
7+
68
export function Proceed(arg1:string,arg2:string,arg3:string):Promise<string>;

frontend/wailsjs/go/main/App.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export function Greet(arg1) {
66
return window['go']['main']['App']['Greet'](arg1);
77
}
88

9+
export function OpenBrowser(arg1) {
10+
return window['go']['main']['App']['OpenBrowser'](arg1);
11+
}
12+
913
export function Proceed(arg1, arg2, arg3) {
1014
return window['go']['main']['App']['Proceed'](arg1, arg2, arg3);
1115
}

0 commit comments

Comments
 (0)