gui: on Linux without gst-plugins-good the masking demo shows her poster

On stock Omarchy (Arch + Hyprland, WebKitGTK 2.52.6, GStreamer 1.28.6
with gst-plugins-base and -bad only), opening the masking demo aborted
WebKitWebProcess about three seconds in, so the app's window went blank.
WebKitGTK gives every video, a muted one too, an audio sink it makes with
autoaudiosink ("GStreamer element autoaudiosink not found", then a NULL
g_signal_connect, then SIGABRT); that element is in gst-plugins-good.
canPlayType can't tell: an Ogg Theora copy, "probably" playable there,
crashed the same way, so no other format would do.

The Linux app now looks for libgstautodetect.so in GStreamer's plugin
folders (its variables' and the system's): GStreamer's core there and
autodetect in none of them means no video (webkitPlaysVideo). Settings
state says noVideo then, in the app only (magpie web plays in the user's
own browser), and the demo sets no src: she is her poster and the sheets
move on the frame clock, as when the video can't load. No GStreamer folder
found says nothing, and video stays on.

Run at this head (origin/main 0f053024f + this change; the runs were at
ec6c2de52 + this change, and 0f053024f changes only README and site/):
- mote: node --test masking-demo, masking-records: 110 pass, 0 fail
  (Chromium and WebKit; the new poster test in both).
- magpie-desktop (WSL, Ubuntu 24.04): go test -tags gtk3 -run
  'TestGstAutodetect|TestWebkitDefaults|TestRenderNodeOpens|TestSettings'
  ./internal/gui: ok.
- mote: GOOS=linux CGO_ENABLED=0 go vet -tags gtk3, GOOS=windows go vet
  and go vet of ./internal/gui: ok. gofmt -l: none.
- omarchy, the real check on the real system, from a test binary built
  at this head: webkitPlaysVideo() is false
  ([/usr/lib/gstreamer-1.0 /usr/lib64/gstreamer-1.0]); on magpie-desktop,
  which has gst-plugins-good, true.
- omarchy, WebKitGTK driven from Python on `magpie web`'s page: with the
  demo's webm src set, the web process aborts every time (core dumps
  23:07:33, 23:10:17, 23:12:59, and 23:18:30 with an .ogv); with no src,
  as this change does, it stays up and T runs (2.99 -> 4.39 s).
- Broken by hand: gstAutodetect returning true makes TestGstAutodetect
  red ("stock omarchy: gstAutodetect = true, want false"); demo.js setting
  src regardless makes the poster test red in both engines.

Not tried: clicking the demo row in the real desktop app on omarchy (no
pointer tool there); the app's half was checked through the same
WebKitGTK and the detection through the real folders, separately.
This commit is contained in:
yetone
2026-10-28 07:31:02 +08:00
parent 0f053024f5
commit b90e81da14
6 changed files with 105 additions and 5 deletions
+4
View File
@@ -403,6 +403,9 @@ type settingsJSON struct {
GatewayOn bool `json:"gatewayOn,omitempty"`
GatewayWhy string `json:"gatewayWhy,omitempty"`
Web bool `json:"web,omitempty"`
// NoVideo: this app's webview would crash on a <video> (Linux without
// gst-plugins-good, webkitPlaysVideo), so the pages show no video
NoVideo bool `json:"noVideo,omitempty"`
// the proxy vendor requests go through now, and where it came from:
// settings, environment, system, off or none
ProxyNow string `json:"proxyNow"`
@@ -627,6 +630,7 @@ func settingsState() settingsJSON {
}
s.WSL = runtime.GOOS == "windows"
s.Web = webPage.Load()
s.NoVideo = !s.Web && !webkitPlaysVideo()
s.GatewayOn, s.GatewayWhy = gatewayMode(s.Web)
s.LANKey = "" // the retained credential belongs on disk, not in UI state
// the GitHub token, masked, and where the library's requests take one
+3 -2
View File
@@ -8,7 +8,8 @@
// sheets, the notebook and the boxes are the page's, moved over her. The
// video is fetched when the row is first opened, never before. It plays
// while the row is open and on screen, once through, and rests on its last
// step; with reduced motion it starts there.
// step; with reduced motion it starts there. Where the app's webview would
// crash on a video (state.settings.noVideo), she is her poster.
const XQD_END = 27.5;
const XQD_STEPS = [
@@ -368,7 +369,7 @@ function maskDemoBuild(body) {
if (th === theme) return;
theme = th;
vid.poster = `plugins/redact/xq_${th}.jpg`;
vid.src = `plugins/redact/xq_${th}.webm`;
if (!state.settings?.noVideo) vid.src = `plugins/redact/xq_${th}.webm`;
// a new source starts paused: it goes on where the old one was
seek(T);
wake();
+18 -3
View File
@@ -18,8 +18,8 @@ const K = "1792987654321000001";
const record = { key: K, t: new Date(Date.now() - 60e3).toISOString(), route: "messages", what: "chat", agent: "claude", provider: "anthropic", model: "claude-opus-4-1", n: 1,
values: [{ p: "{{PERSON_bbbb2222}}", k: "PERSON", b: "model", h: "", l: 3, n: 1 }], snips: { "{{PERSON_bbbb2222}}": "ask {{PERSON_bbbb2222}} about it" } };
function serve(lang, theme, fetched) {
const settings = { theme, lang, tray: "panel", currency: "usd", redact: true, redactPersonal: true };
function serve(lang, theme, fetched, more) {
const settings = { theme, lang, tray: "panel", currency: "usd", redact: true, redactPersonal: true, ...more };
return async (route) => {
const req = route.request(), url = new URL(req.url());
const json = (data) => route.fulfill({ json: data });
@@ -56,7 +56,7 @@ async function open(engine, lang, width, opts = {}) {
page.setDefaultTimeout(8000);
const errors = [], fetched = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, opts.theme || "light", fetched));
await page.route("**/*", serve(lang, opts.theme || "light", fetched, opts.settings));
await page.goto("http://magpie.test/?view=masking");
await page.locator("#mdRow").waitFor();
return { browser, page, errors, fetched };
@@ -217,6 +217,21 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await until(async () => { const s = await state(page); return !s.paused && s.ct > a.T + .5 && Math.abs(s.ct - s.T) < .3; }, 8000, page);
assert.deepEqual(errors, []);
});
// on Linux without gst-plugins-good WebKitGTK's web process aborts on any
// video (stock Omarchy), so there she is her poster and the sheets still move
test(`${engine}: where the app can't play video she is her poster, and the demo still plays`, async (t) => {
const { browser, page, errors, fetched } = await open(engine, "en", 1100, { motion: true, settings: { noVideo: true } });
t.after(() => browser.close());
await page.locator("#mdRow").click();
await until(async () => (await state(page)).T > 1, 8000, page);
await page.evaluate(() => { document.documentElement.dataset.theme = "dark"; });
await until(() => fetched.includes("xq_dark.jpg"));
assert.deepEqual(await page.evaluate(() => { const v = document.querySelector(".xqd video"); return [v.getAttribute("src"), v.poster.split("/").pop()]; }), [null, "xq_dark.jpg"]);
assert.deepEqual(fetched.filter((f) => f.endsWith(".webm")), []);
const a = await state(page);
await until(async () => (await state(page)).T > a.T + .5, 8000, page);
assert.deepEqual(errors, []);
});
}
// her background is the card's: the video's own corners, against the card
+44
View File
@@ -3,6 +3,8 @@ package gui
import (
"os"
"path/filepath"
"strings"
"sync"
)
// webkitDefaults sets how WebKitGTK draws the pages before the app makes
@@ -57,3 +59,45 @@ func renderNodeOpens(nodes []string, open func(string) error) bool {
}
return false
}
// webkitPlaysVideo is whether WebKitGTK can play a <video> here. It gives
// every video, a muted one too, an audio sink it makes with autoaudiosink,
// from gst-plugins-good; where that isn't installed (stock Omarchy has only
// -base and -bad) it gets none, and its web process aborts a moment after
// the video starts loading, which leaves the window blank. GStreamer keeps
// the element in libgstautodetect.so. A system with no plugin folder magpie
// knows of says nothing either way, and plays.
var webkitPlaysVideo = sync.OnceValue(func() bool {
return gstAutodetect(gstPluginDirs(os.Getenv), func(p string) bool { _, err := os.Stat(p); return err == nil })
})
// gstPluginDirs is where GStreamer looks for plugins: the folders its
// variables name, and the system's own.
func gstPluginDirs(getenv func(string) string) []string {
var dirs []string
for _, k := range []string{"GST_PLUGIN_SYSTEM_PATH_1_0", "GST_PLUGIN_SYSTEM_PATH", "GST_PLUGIN_PATH_1_0", "GST_PLUGIN_PATH"} {
for _, d := range strings.Split(getenv(k), ":") {
if d != "" {
dirs = append(dirs, d)
}
}
}
for _, g := range []string{"/usr/lib*/gstreamer-1.0", "/usr/lib*/*/gstreamer-1.0", "/usr/local/lib*/gstreamer-1.0", "/usr/local/lib*/*/gstreamer-1.0"} {
m, _ := filepath.Glob(g)
dirs = append(dirs, m...)
}
return dirs
}
// gstAutodetect is false only when GStreamer's core plugins are there and
// autoaudiosink is in none of the folders.
func gstAutodetect(dirs []string, exists func(string) bool) bool {
found := false
for _, d := range dirs {
if exists(filepath.Join(d, "libgstautodetect.so")) {
return true
}
found = found || exists(filepath.Join(d, "libgstcoreelements.so"))
}
return !found
}
+33
View File
@@ -2,6 +2,7 @@ package gui
import (
"errors"
"slices"
"testing"
)
@@ -61,3 +62,35 @@ func TestRenderNodeOpens(t *testing.T) {
}
}
}
// WebKitGTK's web process aborts on any video where autoaudiosink is
// missing (stock Omarchy: gst-plugins-base and -bad, no -good), so video is
// off only there; with GStreamer's folder not found, nothing is known and
// video stays on.
func TestGstAutodetect(t *testing.T) {
for _, c := range []struct {
name string
files []string
want bool
}{
{"plugins-good installed", []string{"/usr/lib/gstreamer-1.0/libgstcoreelements.so", "/usr/lib/gstreamer-1.0/libgstautodetect.so"}, true},
{"stock omarchy", []string{"/usr/lib/gstreamer-1.0/libgstcoreelements.so", "/usr/lib/gstreamer-1.0/libgsttheora.so"}, false},
{"good in a folder the variable names", []string{"/usr/lib/gstreamer-1.0/libgstcoreelements.so", "/opt/gst/libgstautodetect.so"}, true},
{"no gstreamer folder found", nil, true},
} {
have := map[string]bool{}
for _, f := range c.files {
have[f] = true
}
if got := gstAutodetect([]string{"/opt/gst", "/usr/lib/gstreamer-1.0"}, func(p string) bool { return have[p] }); got != c.want {
t.Errorf("%s: gstAutodetect = %v, want %v", c.name, got, c.want)
}
}
env := map[string]string{"GST_PLUGIN_PATH_1_0": "/opt/gst:/opt/more", "GST_PLUGIN_SYSTEM_PATH": "/sys/gst"}
dirs := gstPluginDirs(func(k string) string { return env[k] })
for _, d := range []string{"/opt/gst", "/opt/more", "/sys/gst"} {
if !slices.Contains(dirs, d) {
t.Errorf("gstPluginDirs = %v, missing %s", dirs, d)
}
}
}
+3
View File
@@ -4,3 +4,6 @@ package gui
// webkitDefaults: only Linux's webview is WebKitGTK.
func webkitDefaults() {}
// webkitPlaysVideo: the other systems' webviews play video.
func webkitPlaysVideo() bool { return true }