From e9a220de2d5814c746c84f8c7cbbc00992d871c6 Mon Sep 17 00:00:00 2001 From: mrbobbytables Date: Wed, 16 Sep 2026 13:10:49 +0000 Subject: [PATCH] fix: keep GSConnect loading on GNOME 51 (clipboard final-type) On GNOME 48+ / GNOME 51, GjsPrivate.DBusImplementation became a final GType. GSConnect's shell/clipboard.js registers GSConnectShellClipboard as a subclass of GjsPrivate.DBusImplementation, throwing "Cannot inherit from a final type" during module load. This causes the entire extension to fail initialization and enter ERROR state instead of ACTIVE. Wrap GSConnectShellClipboard class registration in try/catch in scripts/build-gnome-extensions.sh, falling back to an inert portal stub. Verify after meson install that the installed clipboard.js carries the guard. Update desktop-contract skill documentation and skill catalog, and add unit tests in tests/test_gnome_extensions.py. Fixes projectbluefin/utah#88 Assisted-by: Gemini 3.8 Flash via GitHub Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: mrbobbytables --- docs/skills/desktop-contract.md | 7 +++- docs/skills/index.json | 4 +- docs/skills/index.md | 2 +- scripts/build-gnome-extensions.sh | 62 +++++++++++++++++++++++++++++++ tests/test_gnome_extensions.py | 59 +++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 tests/test_gnome_extensions.py diff --git a/docs/skills/desktop-contract.md b/docs/skills/desktop-contract.md index 5e6c1e4f..2ccadd89 100644 --- a/docs/skills/desktop-contract.md +++ b/docs/skills/desktop-contract.md @@ -1,7 +1,7 @@ --- name: desktop-contract version: "1.0" -last_updated: "2026-09-05" +last_updated: "2026-09-16" id: desktop-contract one_line_purpose: Maintain Utah identity, Bluefin desktop defaults, and first-boot Flatpak policy. entry_point: docs/skills/desktop-contract.md @@ -81,7 +81,10 @@ Building GSConnect runs meson install. Because `desktop-file-utils` is not published by Hummingbird or Utah's repository, `scripts/build-gnome-extensions.sh` disables GSConnect's `update_desktop_database` meson post-install hook to avoid failing on the missing utility. MIME and schema databases are handled by the -system and glib-compile-schemas. +system and glib-compile-schemas. Additionally, `scripts/build-gnome-extensions.sh` +guards `src/shell/clipboard.js` against GNOME 48+ final GTypes: wrapping +`GSConnectShellClipboard` registration in a try/catch prevents module load failures +on `GjsPrivate.DBusImplementation`, gracefully degrading to an inert portal on GNOME 51. ## Services and login defaults diff --git a/docs/skills/index.json b/docs/skills/index.json index 9a380aa0..02838e2d 100644 --- a/docs/skills/index.json +++ b/docs/skills/index.json @@ -1,5 +1,5 @@ { - "generated_at": "2026-09-05", + "generated_at": "2026-09-16", "schema_version": "1.0", "skills": [ { @@ -53,7 +53,7 @@ ], "description": "The runtime desktop contract in contracts/bluefin-desktop.toml and its in-image verifiers. Use when changing branding, os-release, service presets, GNOME extensions, or first-boot Flatpak behavior.", "version": "1.0", - "last_updated": "2026-09-05", + "last_updated": "2026-09-16", "doc_type": "policy" }, { diff --git a/docs/skills/index.md b/docs/skills/index.md index 2864a0b1..688ac521 100644 --- a/docs/skills/index.md +++ b/docs/skills/index.md @@ -3,7 +3,7 @@ This file is a human-readable mirror of `index.json`. Both are generated by `scripts/generate_skill_index.py` — do not hand-edit either file. -Generated: 2026-09-05 · schema 1.0 · 8 skills +Generated: 2026-09-16 · schema 1.0 · 8 skills | id | category | status | one-line purpose | |---|---|---|---| diff --git a/scripts/build-gnome-extensions.sh b/scripts/build-gnome-extensions.sh index 9dba777a..05660495 100755 --- a/scripts/build-gnome-extensions.sh +++ b/scripts/build-gnome-extensions.sh @@ -40,10 +40,72 @@ glib-compile-schemas --strict /usr/share/gnome-shell/extensions/gradia-integrati # Disable update-desktop-database hook since desktop-file-utils is unavailable in Hummingbird/Utah repositories. gsconnect_dir="/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io" sed -i 's/update_desktop_database: true/update_desktop_database: false/' "${gsconnect_dir}/meson.build" + +# GNOME 48+ makes GjsPrivate.DBusImplementation a final GType, so +# GObject.registerClass(... extends GjsPrivate.DBusImplementation) throws +# "Cannot inherit from a final type" at module load, which takes the whole +# GSConnect extension down. Wrap the registration in try/catch so a final base +# type degrades to an inert portal instead of a hard load failure. Fail loudly +# if the upstream lines move so a submodule bump cannot silently drop the fix. +gs_clipboard="${gsconnect_dir}/src/shell/clipboard.js" +python3 - "${gs_clipboard}" <<'PY' +import sys +from pathlib import Path + +path = Path(sys.argv[1]) +content = path.read_text(encoding="utf-8") + +old_start = "export const Clipboard = GObject.registerClass({" +new_start = """let Clipboard; +try { +Clipboard = GObject.registerClass({""" + +old_end = """ if (this._handleMethodCallId > 0) { + this.disconnect(this._handleMethodCallId); + this._handleMethodCallId = 0; + this.unexport(); + } + } +});""" + +new_end = """ if (this._handleMethodCallId > 0) { + this.disconnect(this._handleMethodCallId); + this._handleMethodCallId = 0; + this.unexport(); + } + } +}); +} catch (_e) { + // GNOME 48+ makes GjsPrivate.DBusImplementation a final GType, so the + // Wayland background clipboard portal cannot be registered as a + // subclass of it: registerClass throws "Cannot inherit from a final + // type" at module load, which otherwise takes the whole extension down. + // Fall back to an inert portal so the rest of GSConnect still loads; + // clipboard sync through this portal is disabled on such shells. + console.warn(`GSConnect: clipboard portal disabled on this GNOME version: ${_e}`); + Clipboard = class { destroy() {} }; +} +export { Clipboard };""" + +if old_start not in content or old_end not in content: + sys.exit("gsconnect clipboard.js no longer matches expected DBusImplementation class structure; re-check the GNOME 51 guard") + +content = content.replace(old_start, new_start, 1) +content = content.replace(old_end, new_end, 1) +path.write_text(content, encoding="utf-8") +PY + meson setup --prefix=/usr "${gsconnect_dir}" "${gsconnect_dir}/_build" meson install -C "${gsconnect_dir}/_build" --skip-subprojects # GSConnect installs schemas to /usr/share/glib-2.0/schemas and meson compiles them automatically +# Assert the installed extension carries the guard +test -f "${gsconnect_dir}/shell/clipboard.js" +if ! grep -q "clipboard portal disabled on this GNOME version" "${gsconnect_dir}/shell/clipboard.js"; then + echo "gsconnect shell/clipboard.js was not installed with the GNOME 51 final-type guard" >&2 + exit 1 +fi + # Custom Command Menu glib-compile-schemas --strict /usr/share/gnome-shell/extensions/custom-command-list@storageb.github.com/schemas diff --git a/tests/test_gnome_extensions.py b/tests/test_gnome_extensions.py new file mode 100644 index 00000000..7070c6c5 --- /dev/null +++ b/tests/test_gnome_extensions.py @@ -0,0 +1,59 @@ +"""Test GNOME extension maintenance guards and patches.""" + +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[1] + + +class GnomeExtensionPatchTests(unittest.TestCase): + def test_build_script_contains_gsconnect_final_type_guard(self): + script = (ROOT / "scripts/build-gnome-extensions.sh").read_text() + self.assertIn("GjsPrivate.DBusImplementation a final GType", script) + self.assertIn("clipboard portal disabled on this GNOME version", script) + self.assertIn("Clipboard = class { destroy() {} };", script) + + def test_gsconnect_clipboard_patch_applies_and_validates(self): + src_clipboard = ( + ROOT + / "system_files/shared/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/src/shell/clipboard.js" + ) + if not src_clipboard.is_file(): + self.skipTest("gsconnect submodule not initialized") + + with tempfile.TemporaryDirectory() as tmp: + tmp_clipboard = Path(tmp) / "clipboard.js" + shutil.copyfile(src_clipboard, tmp_clipboard) + + # Extract python patch snippet from build-gnome-extensions.sh + script = (ROOT / "scripts/build-gnome-extensions.sh").read_text() + self.assertIn("python3 - \"${gs_clipboard}\" <<'PY'", script) + py_code = script.split("python3 - \"${gs_clipboard}\" <<'PY'\n", 1)[1].split("\nPY\n", 1)[0] + + proc = subprocess.run( + ["python3", "-c", py_code, str(tmp_clipboard)], + capture_output=True, + text=True, + ) + self.assertEqual(proc.returncode, 0, f"patch script failed: {proc.stderr}") + + patched_text = tmp_clipboard.read_text(encoding="utf-8") + self.assertIn("clipboard portal disabled on this GNOME version", patched_text) + self.assertIn("Clipboard = class { destroy() {} };", patched_text) + self.assertIn("export { Clipboard };", patched_text) + + # If node is present, check syntax + if shutil.which("node"): + res = subprocess.run( + ["node", "--check", str(tmp_clipboard)], + capture_output=True, + text=True, + ) + self.assertEqual(res.returncode, 0, f"syntax error in patched clipboard.js: {res.stderr}") + + +if __name__ == "__main__": + unittest.main()