mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-06 00:47:09 +00:00
refactor(display): use chrome devtools protocol (#38)
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"plg-mudics/shared"
|
||||
)
|
||||
|
||||
func openBrowserWindow(url string) error {
|
||||
bins := []string{"chromium", "chromium-browser"}
|
||||
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to determine user home directory: %w", err)
|
||||
}
|
||||
browserProfileDirPath := filepath.Join(home, ".local", "share", "plg-mudics", "browser-control")
|
||||
if err := os.MkdirAll(browserProfileDirPath, os.ModePerm); err != nil {
|
||||
return fmt.Errorf("failed to create local config directory: %w", err)
|
||||
}
|
||||
|
||||
args := []string{
|
||||
fmt.Sprintf("--app=%s", url),
|
||||
fmt.Sprintf("--user-data-dir=%s", browserProfileDirPath),
|
||||
}
|
||||
|
||||
errs := []string{}
|
||||
for _, bin := range bins {
|
||||
cmd := exec.Command(bin, args...)
|
||||
commandOutput := shared.RunShellCommand(cmd)
|
||||
if commandOutput.ExitCode == 0 {
|
||||
return nil
|
||||
}
|
||||
errs = append(errs, commandOutput.Stderr)
|
||||
}
|
||||
|
||||
return errors.New("failed to open browser window: " + fmt.Sprint(errs))
|
||||
}
|
||||
Reference in New Issue
Block a user