refactor(display): use chrome devtools protocol (#38)

This commit is contained in:
2026-01-30 15:26:57 +01:00
committed by GitHub
parent cbbf50e5a4
commit 71f152ef2a
24 changed files with 570 additions and 504 deletions
@@ -51,6 +51,17 @@ export async function show_html(ip: string, html: string): Promise<void> {
await request_display(ip, '/showHTML', options);
}
export async function open_website(ip: string, url: string): Promise<void> {
const options = {
method: 'PATCH',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
url: url
})
};
await request_display(ip, '/openWebsite', options);
}
export async function get_file_data(
ip: string,
path: string
@@ -21,7 +21,8 @@
show_blackscreen,
shutdown,
startup,
show_html
show_html,
open_website
} from '$lib/ts/api_handler';
import {
get_display_by_id,
@@ -144,7 +145,7 @@
async function send_website() {
popup_content.open = false;
await run_on_all_selected_displays((d) =>
show_html(d.ip, `<iframe src="${website_url}"></iframe>`)
open_website(d.ip, website_url)
);
}
</script>
+1 -1
View File
@@ -64,7 +64,7 @@ func main() {
os.Exit(1)
}
}()
err = shared.OpenBrowserWindow("http://localhost:"+port, false, "control")
err = openBrowserWindow("http://localhost:" + port)
if err != nil {
slog.Error("Failed to open browser window", "error", err)
os.Exit(1)
+40
View File
@@ -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))
}