Skip to content

fix: replace imports.byteArray with TextDecoder (broken on GNOME 48+)#525

Open
mayconrcmello wants to merge 1 commit intoforge-ext:mainfrom
mayconrcmello:fix/replace-imports-bytearray
Open

fix: replace imports.byteArray with TextDecoder (broken on GNOME 48+)#525
mayconrcmello wants to merge 1 commit intoforge-ext:mainfrom
mayconrcmello:fix/replace-imports-bytearray

Conversation

@mayconrcmello
Copy link
Copy Markdown

Summary

lib/shared/settings.js reads window-floating config via:

const stringContents = imports.byteArray.toString(contents);

GJS removed imports.byteArray in 1.86 (shipped with GNOME 48). Forge has been ESM since the GNOME 45 port, where the legacy imports global is gone — calling imports.byteArray.toString(...) throws ReferenceError: imports is not defined.

When it bites users

The default config/windows.json ships inside the extension dir, so the read path is rarely hit on a clean install. But every Super+Shift+C ("Toggle always float for this class") goes through windowProps getter / setter, which reads + writes that JSON. On GNOME 48+, the first toggle throws and the always-float entry never persists.

Fix

Both call sites switch to new TextDecoder().decode(contents):

- const stringContents = imports.byteArray.toString(contents);
+ return new TextDecoder().decode(contents);

Gio.File.load_contents() returns a Uint8Array on GJS 1.74+, which TextDecoder accepts directly.

Test plan

  • node --check lib/shared/settings.js
  • Super+Shift+C on a window persists the class to ~/.config/forge/config/windows.json; subsequent windows of that class open floating.
  • No JS ERROR: ReferenceError: imports is not defined in the journal under the patched extension.

GJS removed `imports.byteArray` in 1.86 (GNOME 48). Calling
`imports.byteArray.toString(...)` from an ESM extension throws
`ReferenceError: imports is not defined` — `imports` only exists in
the legacy non-ESM module system, and Forge has been ESM since the
GNOME 45 port.

This had no immediate impact for users without a custom window
floating list (the default `config/windows.json` is shipped inside
the extension and the read path was apparently never hit during
testing), but it breaks `addFloatOverride` / `removeFloatOverride`
the moment the user toggles `Super+Shift+C` ("toggle always float")
on any window — `windowProps` reads the JSON config and then writes
it back with the new entry.

Replace both call sites with `new TextDecoder().decode(contents)`,
which is the modern equivalent. `Gio.File.load_contents()` returns a
Uint8Array on GNOME 45+, so TextDecoder accepts it directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant