How can app know gjs runtime version?

Following advice to use TextDecoder for gjs since 1.70, using TextDecode/TextEncoder works fine on my development machine. However when I try running the app on a Raspberry Pi 4, it throws ReferenceError: TextEncoder not defined, after which I find the gjs version is 1.66.2-1.

I can go back to using byteArray as an alternative if gjs version is too low but how can I know which version is being used?

Nodejs has process.version - is there something like that for gjs?

Thanks,
chris

I don’t know if there’s a way to get GJS version, but you can use feature detection to run different code paths:

if ('TextEncoder' in globalThis) {
    doSomethingWithTextEncoder();
} else {
    doSomethingWithByteArray();
}

globalThis has been introduced in GJS 1.63.90, if you target older versions you can use window instead.

Thanks Romain,

That will solve the immediate problem.

It’s still interesting that there’s no obvious way to obtain the GJS version.

chris

https://gitlab.gnome.org/GNOME/gjs/-/blob/master/doc/Modules.md#System

import system from 'system';
log(system.version);

or

log(imports.system.version);

Feature detection is in my opinion preferable, as it’s immediately clear in code which feature you need, and you don’t have to mess with versions. And that’s historically what’s been done in JavaScript, after we deciding that browser sniffing was a bad idea :slight_smile:

I agree that feature detection is a nicer way to go.

Even though it meant that I no longer needed a version number, it was still a bit irritating not to know how, so thanks Sonny.

chris

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.