refactor: move browser open into shared modules

This commit is contained in:
2025-11-04 17:21:23 +01:00
parent fa3d5198d2
commit 4ebac7d7fc
7 changed files with 91 additions and 56 deletions
+37
View File
@@ -0,0 +1,37 @@
package shared
import (
"errors"
"fmt"
"os"
"os/exec"
)
func OpenBrowserWindow(url string, fullscreen bool, temp bool) error {
bins := []string{"chromium", "chromium-browser"}
args := []string{fmt.Sprintf("--app=%s", url), "--autoplay-policy=no-user-gesture-required"}
if fullscreen {
args = append(args, "--start-fullscreen")
}
if temp {
tempDirPath, err := os.MkdirTemp("", "plg-mudics-browser-")
if err != nil {
return err
}
arg := fmt.Sprintf("--user-data-dir=%s", tempDirPath)
args = append(args, arg)
}
for _, bin := range bins {
cmd := exec.Command(bin, args...)
fmt.Println(cmd)
commandOutput := RunShellCommand(cmd)
if commandOutput.ExitCode == 0 {
return nil
}
}
return errors.New("chromium not found in PATH")
}