prefs: Add ability to run it as standalone app with both Gtk 3 and 4
Marco Trevisan (TreviƱo)
2 years ago
1 | 1 | |
2 | 2 | /* exported init, buildPrefsWidget */ |
3 | 3 | |
4 | const Gio = imports.gi.Gio; | |
5 | ||
6 | try { | |
7 | // eslint-disable-next-line no-unused-expressions | |
8 | imports.misc.extensionUtils; | |
9 | } catch (e) { | |
10 | const resource = Gio.Resource.load( | |
11 | '/usr/share/gnome-shell/org.gnome.Extensions.src.gresource'); | |
12 | resource._register(); | |
13 | imports.searchPath.push('resource:///org/gnome/Extensions/js'); | |
14 | ||
15 | const { GLib } = imports.gi; | |
16 | const gtkVersion = GLib.getenv('FORCE_GTK_VERSION') || '4.0'; | |
17 | imports.gi.versions.Gtk = gtkVersion; | |
18 | imports.gi.versions.Gdk = gtkVersion; | |
19 | } | |
20 | ||
4 | 21 | const GObject = imports.gi.GObject; |
5 | 22 | const Gtk = imports.gi.Gtk; |
6 | const Gio = imports.gi.Gio; | |
7 | 23 | |
8 | 24 | const ExtensionUtils = imports.misc.extensionUtils; |
9 | 25 | const Me = ExtensionUtils.getCurrentExtension(); |
10 | const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']); | |
26 | const Gettext = imports.gettext.domain( | |
27 | Me ? Me.metadata['gettext-domain'] : 'AppIndicatorExtension'); | |
11 | 28 | const _ = Gettext.gettext; |
12 | 29 | |
13 | 30 | function init() { |
19 | 36 | _init() { |
20 | 37 | super._init({ row_spacing: 10 }); |
21 | 38 | this.margin = 24; |
22 | this._settings = ExtensionUtils.getSettings(); | |
39 | this._settings = Me ? ExtensionUtils.getSettings() | |
40 | : new Gio.Settings({ schema_id: 'org.gnome.shell.extensions.appindicator' }); | |
23 | 41 | |
24 | 42 | let label = null; |
25 | 43 | let widget = null; |
142 | 160 | |
143 | 161 | return widget; |
144 | 162 | } |
163 | ||
164 | if (!Me) { | |
165 | const { GLib } = imports.gi; | |
166 | GLib.setenv('GSETTINGS_SCHEMA_DIR', './schemas', true); | |
167 | Gtk.init(null); | |
168 | ||
169 | const loop = GLib.MainLoop.new(null, false); | |
170 | const win = new Gtk.Window(); | |
171 | if (win.set_child) { | |
172 | win.set_child(buildPrefsWidget()); | |
173 | win.connect('close-request', () => loop.quit()); | |
174 | } else { | |
175 | win.add(buildPrefsWidget()); | |
176 | win.connect('delete-event', () => loop.quit()); | |
177 | } | |
178 | win.present(); | |
179 | ||
180 | loop.run(); | |
181 | } |