Move all old shell versions compatibility code to a single file

This commit is contained in:
Romain Vigier
2020-07-28 12:10:53 +02:00
parent 4e70a11624
commit c6f35255b2
12 changed files with 72 additions and 118 deletions
+30 -13
View File
@@ -16,27 +16,44 @@ You should have received a copy of the GNU General Public License along with
this program. If not, see <http s ://www.gnu.org/licenses/>.
*/
const Meta = imports.gi.Meta;
const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const shell_minor_version = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[1]);
function init_translations(domain) {
if ( shell_minor_version <= 30 ) return Me.imports.convenience.initTranslations(domain);
else return extensionUtils.initTranslations(domain);
}
function extension_manager_initialized() {
if ( shell_minor_version > 32 ) return imports.ui.main.extensionManager._initialized;
else return imports.ui.extensionSystem.initted;
}
function extension_manager_lookup(uuid) {
if ( shell_minor_version > 32 ) return imports.ui.main.extensionManager.lookup(uuid);
else return extensionUtils.extensions[uuid] || null;
}
function get_extension_settings() {
if ( shell_minor_version <= 30 ) return Me.imports.convenience.getSettings();
else return extensionUtils.getSettings();
}
function key_binding_auto_repeat() {
// if version is less then 3.30 the keybinding flags are NONE
if (shell_minor_version < 30) {
return Meta.KeyBindingFlags.NONE;
}
else {
return Meta.KeyBindingFlags.IGNORE_AUTOREPEAT;
}
if (shell_minor_version < 30) return imports.gi.Meta.KeyBindingFlags.NONE;
else return imports.gi.Meta.KeyBindingFlags.IGNORE_AUTOREPEAT;
};
function get_actor(subject) {
if (shell_minor_version > 34) {
return subject;
}
else {
return subject.actor;
}
if (shell_minor_version > 34) return subject;
else return subject.actor;
};
+5 -18
View File
@@ -23,6 +23,7 @@ const { main } = imports.ui;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { log_debug } = Me.imports.utils;
const { SettingsManager } = Me.imports.modules.SettingsManager;
const { Timer } = Me.imports.modules.Timer;
@@ -34,12 +35,6 @@ const { Backgrounder } = Me.imports.modules.Backgrounder;
const { Commander } = Me.imports.modules.Commander;
const shell_minor_version = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[1]);
if ( shell_minor_version <= 30 ) {
extensionUtils.initTranslations = Me.imports.convenience.initTranslations;
}
var enabled = false;
var settingsManager = null;
var timer = null;
@@ -53,7 +48,7 @@ var commander = null;
function init() {
log_debug('Initializing extension...');
extensionUtils.initTranslations(Me.metadata.uuid);
compat.init_translations(Me.metadata.uuid);
log_debug('Extension initialized.');
}
@@ -109,16 +104,8 @@ function disable() {
async function _await_extensionManager_init() {
log_debug('Waiting for the Extension Manager to be initialized...');
if ( shell_minor_version > 32 ) {
while ( true ) {
if ( main.extensionManager._initialized ) return;
await null;
}
}
else {
while ( true ) {
if ( imports.ui.extensionSystem.initted ) return;
await null;
}
while ( true ) {
if ( compat.extension_manager_initialized() ) return;
await null;
}
}
+1 -7
View File
@@ -17,7 +17,7 @@ this program. If not, see <http s ://www.gnu.org/licenses/>.
*/
const { Gio, GLib } = imports.gi;
const { extensionUtils, fileUtils } = imports.misc;
const { extensionUtils } = imports.misc;
const Signals = imports.signals;
const Me = extensionUtils.getCurrentExtension();
@@ -25,12 +25,6 @@ const Me = extensionUtils.getCurrentExtension();
const { log_debug } = Me.imports.utils;
const shell_minor_version = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[1]);
if ( shell_minor_version <= 30 ) {
fileUtils.loadInterfaceXML = Me.imports.convenience.loadInterfaceXML;
}
const COLOR_INTERFACE = `
<node>
<interface name="org.gnome.SettingsDaemon.Color">
+4 -9
View File
@@ -21,22 +21,17 @@ const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
const shell_minor_version = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[1]);
if ( shell_minor_version <= 30 ) {
extensionUtils.getSettings = Me.imports.convenience.getSettings;
}
var BackgroundsPreferences = class {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const label = _('Backgrounds');
const description = _('You can set different backgrounds for day and night.');
@@ -71,7 +66,7 @@ var BackgroundsPreferences = class {
class BackgroundsEnabledControl {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('backgrounds-enabled')
});
@@ -90,7 +85,7 @@ class BackgroundsEnabledControl {
class TimeBackgroundControl {
constructor(time) {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const filter = new Gtk.FileFilter();
filter.add_mime_type('image/jpeg');
+4 -9
View File
@@ -21,22 +21,17 @@ const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
const shell_minor_version = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[1]);
if ( shell_minor_version <= 30 ) {
extensionUtils.getSettings = Me.imports.convenience.getSettings;
}
var CommandsPreferences = class {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const label = _('Commands');
const description = _('You can set custom commands that will be run when the time of the day changes.');
@@ -71,7 +66,7 @@ var CommandsPreferences = class {
class CommandsEnabledControl {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('commands-enabled')
});
@@ -94,7 +89,7 @@ class SuntimeCommandControl {
['sunrise', _('Hello sunshine!')],
['sunset', _('Hello moonshine!')]
]);
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const entry = new Gtk.Entry({
width_request: 300,
placeholder_text: _(`notify-send "${message.get(suntime)}"`)
+4 -9
View File
@@ -21,6 +21,7 @@ const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const { get_installed_cursor_themes } = Me.imports.utils;
@@ -28,16 +29,10 @@ const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
const shell_minor_version = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[1]);
if ( shell_minor_version <= 30 ) {
extensionUtils.getSettings = Me.imports.convenience.getSettings;
}
var CursorThemePreferences = class {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const label = _('Cursor theme');
const description = _('You can set different cursor themes for day and night.');
@@ -72,7 +67,7 @@ var CursorThemePreferences = class {
class CursorVariantsEnabledControl {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('cursor-variants-enabled')
});
@@ -91,7 +86,7 @@ class CursorVariantsEnabledControl {
class TimeCursorVariantControl {
constructor(time) {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const combo = new Gtk.ComboBoxText();
const themes = Array.from(get_installed_cursor_themes()).sort();
themes.forEach(theme => combo.append(theme, theme));
+5 -10
View File
@@ -21,6 +21,7 @@ const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const { get_installed_gtk_themes } = Me.imports.utils;
@@ -28,16 +29,10 @@ const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
const shell_minor_version = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[1]);
if ( shell_minor_version <= 30 ) {
extensionUtils.getSettings = Me.imports.convenience.getSettings;
}
var GtkThemePreferences = class {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const label = _('GTK theme');
const description = _('The extension will try to automatically detect the day and night variants of your GTK theme.\n\nIf the theme you use isn\'t supported, please <a href="https://gitlab.com/rmnvgr/nightthemeswitcher-gnome-shell-extension/-/issues">submit a request</a>. You can also manually set variants.');
@@ -77,7 +72,7 @@ var GtkThemePreferences = class {
class GtkVariantsEnabledControl {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('gtk-variants-enabled')
});
@@ -96,7 +91,7 @@ class GtkVariantsEnabledControl {
class ManualGtkVariantsControl {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: false
});
@@ -115,7 +110,7 @@ class ManualGtkVariantsControl {
class TimeGtkVariantControl {
constructor(time) {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const combo = new Gtk.ComboBoxText();
const themes = Array.from(get_installed_gtk_themes()).sort();
themes.forEach(theme => combo.append(theme, theme));
+4 -9
View File
@@ -21,6 +21,7 @@ const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const { get_installed_icon_themes } = Me.imports.utils;
@@ -28,16 +29,10 @@ const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
const shell_minor_version = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[1]);
if ( shell_minor_version <= 30 ) {
extensionUtils.getSettings = Me.imports.convenience.getSettings;
}
var IconThemePreferences = class {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const label = _('Icon theme');
const description = _('You can set different icon themes for day and night.');
@@ -72,7 +67,7 @@ var IconThemePreferences = class {
class IconVariantsEnabledControl {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('icon-variants-enabled')
});
@@ -91,7 +86,7 @@ class IconVariantsEnabledControl {
class TimeIconVariantControl {
constructor(time) {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const combo = new Gtk.ComboBoxText();
const themes = Array.from(get_installed_icon_themes()).sort();
themes.forEach(theme => combo.append(theme, theme));
+6 -11
View File
@@ -21,22 +21,17 @@ const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
const shell_minor_version = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[1]);
if ( shell_minor_version <= 30 ) {
extensionUtils.getSettings = Me.imports.convenience.getSettings;
}
var SchedulePreferences = class {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const label = _('Schedule');
const description = _('The extension will try to use Night Light or Location Services to automatically set your current sunrise and sunset times if they are enabled.\n\nIf you prefer, you can manually choose a time source.');
@@ -82,7 +77,7 @@ var SchedulePreferences = class {
class ManualTimeSourceControl {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: false
});
@@ -101,7 +96,7 @@ class ManualTimeSourceControl {
class TimeSourceControl {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const colorSettings = new Gio.Settings({ schema: 'org.gnome.settings-daemon.plugins.color' });
const locationSettings = new Gio.Settings({ schema: 'org.gnome.system.location' });
@@ -189,7 +184,7 @@ class TimeSourceControl {
class KeyBindingControl {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const KEYBINDING_KEY = 'nightthemeswitcher-ondemand-keybinding';
const COLUMN_KEY = 0;
const COLUMN_MODS = 1;
@@ -239,7 +234,7 @@ class KeyBindingControl {
class SuntimeControl {
constructor(suntime) {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const box = new Gtk.Box({
spacing: 8,
orientation: Gtk.Orientation.HORIZONTAL,
+5 -10
View File
@@ -21,6 +21,7 @@ const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const { get_installed_shell_themes } = Me.imports.utils;
@@ -28,16 +29,10 @@ const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
const shell_minor_version = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[1]);
if ( shell_minor_version <= 30 ) {
extensionUtils.getSettings = Me.imports.convenience.getSettings;
}
var ShellThemePreferences = class {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const label = _('Shell theme');
const description = _('The extension will try to automatically detect the day and night variants of your GNOME Shell theme.\n\nIf the theme you use isn\'t supported, please <a href="https://gitlab.com/rmnvgr/nightthemeswitcher-gnome-shell-extension/-/issues">submit a request</a>. You can also manually set variants.');
@@ -77,7 +72,7 @@ var ShellThemePreferences = class {
class ShellVariantsEnabledControl {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('shell-variants-enabled')
});
@@ -96,7 +91,7 @@ class ShellVariantsEnabledControl {
class ManualShellVariantsControl {
constructor() {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: false
});
@@ -115,7 +110,7 @@ class ManualShellVariantsControl {
class TimeShellVariantControl {
constructor(time) {
const settings = extensionUtils.getSettings();
const settings = compat.get_extension_settings();
const combo = new Gtk.ComboBoxText();
const themes = Array.from(get_installed_shell_themes()).sort();
themes.forEach(theme => combo.append(theme, (theme === '' ? _('Default') : theme)));
+2 -7
View File
@@ -23,6 +23,7 @@ const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { BackgroundsPreferences } = Me.imports.preferences.Backgrounds;
const { CommandsPreferences } = Me.imports.preferences.Commands;
const { CursorThemePreferences } = Me.imports.preferences.CursorTheme;
@@ -32,14 +33,8 @@ const { SchedulePreferences } = Me.imports.preferences.Schedule;
const { ShellThemePreferences } = Me.imports.preferences.ShellTheme;
const shell_minor_version = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[1]);
if ( shell_minor_version <= 30 ) {
extensionUtils.initTranslations = Me.imports.convenience.initTranslations;
}
function init() {
extensionUtils.initTranslations(Me.metadata.uuid);
compat.init_translations(Me.metadata.uuid);
}
function buildPrefsWidget() {
+2 -6
View File
@@ -20,6 +20,7 @@ const { Gio, GLib, Gtk } = imports.gi;
const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const config = Me.imports.config;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
@@ -178,12 +179,7 @@ function get_installed_cursor_themes() {
* it isn't installed.
*/
function get_userthemes_extension() {
if ( shell_minor_version > 32 ) {
return imports.ui.main.extensionManager.lookup('user-theme@gnome-shell-extensions.gcampax.github.com');
}
else {
return extensionUtils.extensions['user-theme@gnome-shell-extensions.gcampax.github.com'] || null;
}
return compat.extension_manager_lookup('user-theme@gnome-shell-extensions.gcampax.github.com');
}
/**