@@ -25,6 +25,50 @@ import PangoCairo from 'gi://PangoCairo';
2525const St = await importInShellOnly ( 'gi://St' ) ;
2626const Gtk = await importInPrefsOnly ( 'gi://Gtk' ) ;
2727
28+ // We import the Config module. This is done differently in the GNOME Shell process and in
29+ // the preferences process.
30+ const Config = await importConfig ( ) ;
31+
32+ //////////////////////////////////////////////////////////////////////////////////////////
33+ // Two methods for checking the current version of GNOME Shell. //
34+ //////////////////////////////////////////////////////////////////////////////////////////
35+
36+ // Returns the given argument, except for "alpha", "beta", and "rc". In these cases -3,
37+ // -2, and -1 are returned respectively.
38+ function toNumericVersion ( x ) {
39+ switch ( x ) {
40+ case 'alpha' :
41+ return - 3 ;
42+ case 'beta' :
43+ return - 2 ;
44+ case 'rc' :
45+ return - 1 ;
46+ }
47+ return x ;
48+ }
49+
50+ const [ GS_MAJOR , GS_MINOR ] = Config . PACKAGE_VERSION . split ( '.' ) . map ( toNumericVersion ) ;
51+
52+ // This method returns true if the current GNOME Shell version matches the given
53+ // arguments.
54+ export function shellVersionIs ( major , minor ) {
55+ return GS_MAJOR == major && GS_MINOR == toNumericVersion ( minor ) ;
56+ }
57+
58+ // This method returns true if the current GNOME Shell version is at least as high as the
59+ // given arguments. Supports "alpha" and "beta" for the minor version number.
60+ export function shellVersionIsAtLeast ( major , minor = 0 ) {
61+ if ( GS_MAJOR > major ) {
62+ return true ;
63+ }
64+
65+ if ( GS_MAJOR == major ) {
66+ return GS_MINOR >= toNumericVersion ( minor ) ;
67+ }
68+
69+ return false ;
70+ }
71+
2872//////////////////////////////////////////////////////////////////////////////////////////
2973// This method can be used to write a message to GNOME Shell's log. This is enhances //
3074// the standard log() functionality by prepending the extension's name and the location //
@@ -85,6 +129,17 @@ export async function importGettext() {
85129 return ( await import ( 'resource:///org/gnome/shell/extensions/extension.js' ) ) . gettext ;
86130}
87131
132+ //////////////////////////////////////////////////////////////////////////////////////////
133+ // This method can be used to import the Config module. //
134+ //////////////////////////////////////////////////////////////////////////////////////////
135+
136+ export async function importConfig ( ) {
137+ if ( typeof global === 'undefined' ) {
138+ return ( await import ( 'resource:///org/gnome/Shell/Extensions/js/misc/config.js' ) ) ;
139+ }
140+ return ( await import ( 'resource:///org/gnome/shell/misc/config.js' ) ) ;
141+ }
142+
88143//////////////////////////////////////////////////////////////////////////////////////////
89144// Returns the path to the extension's directory. This is useful to load resources from //
90145// the extension's directory. //
0 commit comments