This commit is contained in:
Trevor Slocum 2024-11-21 10:05:45 -08:00
parent e4e37cf67e
commit 9c0270611b
5 changed files with 45 additions and 3 deletions

2
go.mod
View file

@ -6,7 +6,7 @@ toolchain go1.23.0
require (
code.rocket9labs.com/tslocum/clipboard v0.0.0-20241012025701-2c0fb515daab
github.com/hajimehoshi/ebiten/v2 v2.8.4
github.com/hajimehoshi/ebiten/v2 v2.8.5
github.com/llgcode/draw2d v0.0.0-20240627062922-0ed1ff131195
golang.org/x/image v0.22.0
)

4
go.sum
View file

@ -14,8 +14,8 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/hajimehoshi/bitmapfont/v3 v3.2.0 h1:0DISQM/rseKIJhdF29AkhvdzIULqNIIlXAGWit4ez1Q=
github.com/hajimehoshi/bitmapfont/v3 v3.2.0/go.mod h1:8gLqGatKVu0pwcNCJguW3Igg9WQqVXF0zg/RvrGQWyg=
github.com/hajimehoshi/ebiten/v2 v2.8.4 h1:BzXkcyYX046SRZFkzF2KaCaHiBjwCaufUPCAOK59JSw=
github.com/hajimehoshi/ebiten/v2 v2.8.4/go.mod h1:SXx/whkvpfsavGo6lvZykprerakl+8Uo1X8d2U5aAnA=
github.com/hajimehoshi/ebiten/v2 v2.8.5 h1:w1/3XxjEwIo+amtQCOnCrwGzu4e6dr0ewu83JUKoxrM=
github.com/hajimehoshi/ebiten/v2 v2.8.5/go.mod h1:SXx/whkvpfsavGo6lvZykprerakl+8Uo1X8d2U5aAnA=
github.com/jezek/xgb v1.1.1 h1:bE/r8ZZtSv7l9gk6nU0mYx51aXrvnyb44892TwSaqS4=
github.com/jezek/xgb v1.1.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/llgcode/draw2d v0.0.0-20240627062922-0ed1ff131195 h1:Vdz2cBh5Fw2MYHWi3ED2PraDQaWEUhNCr1XFHrP4N5A=

12
platform_linux.go Normal file
View file

@ -0,0 +1,12 @@
//go:build linux
package etk
import "os/exec"
// Open opens a file, directory or URI using the default application registered
// in the OS to handle it. Only URIs are supported on WebAssembly.
func Open(target string) error {
cmd := exec.Command("xdg-open", target)
return cmd.Start()
}

View file

@ -3,6 +3,7 @@
package etk
import (
"fmt"
"syscall/js"
)
@ -26,3 +27,20 @@ func clipboardBuffer() []byte {
}))
return <-result
}
// Open opens a file, directory or URI using the default application registered
// in the OS to handle it. Only URIs are supported on WebAssembly.
func Open(target string) error {
window := js.Global().Get("window")
if !window.Truthy() {
return fmt.Errorf("failed to get window object")
} else if !window.Get("open").Truthy() {
return fmt.Errorf("failed to get window.open")
}
windowProxy := window.Call("open", target)
if !windowProxy.Truthy() || !windowProxy.Get("focus").Truthy() {
return nil
}
windowProxy.Call("focus", nil)
return nil
}

12
platform_windows.go Normal file
View file

@ -0,0 +1,12 @@
//go:build windows
package etk
import "os/exec"
// Open opens a file, directory or URI using the default application registered
// in the OS to handle it. Only URIs are supported on WebAssembly.
func Open(target string) error {
cmd := exec.Command("cmd", "/C", "start", target)
return cmd.Start()
}