From f02770da31a68f57cf77d607950c799304d66620 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Mon, 17 Feb 2020 16:08:12 +0100 Subject: [PATCH] Fix TeaTime not working with gnome-shell 3.35.90 and newer This commit contains the minimum amount of changes for TeaTime to mostly work with gnome-shell 3.35.90 and newer. There is one big remaining issue after this, the fullscreen notifications are not working anymore. Fixing this unfortunately is non trivial, so I plan to remove it in a separate commit. There are also some JS warnings, I will fix those in separate commits. Signed-off-by: Hans de Goede --- src/extension.js | 89 +++++++++++++++++++++++++++--------------------- src/icon.js | 38 ++++++++++++--------- src/prefs.js | 61 ++++++++++++++++++--------------- 3 files changed, 105 insertions(+), 83 deletions(-) diff --git a/src/extension.js b/src/extension.js index e27e354..5ca3e60 100644 --- a/src/extension.js +++ b/src/extension.js @@ -4,6 +4,7 @@ */ const Gio = imports.gi.Gio; +const GObject = imports.gi.GObject; const Mainloop = imports.mainloop; // timer const Shell = imports.gi.Shell; const St = imports.gi.St; @@ -130,9 +131,10 @@ class TeaTimeFullscreenNotification { }; +let PopupTeaMenuItem = GObject.registerClass( class PopupTeaMenuItem extends PopupMenu.PopupBaseMenuItem { - constructor(sTeaname, nBrewtime, params) { - super(params); + _init(sTeaname, nBrewtime, params) { + super._init(params); this.tealabel = new St.Label({ text: sTeaname @@ -162,14 +164,14 @@ class PopupTeaMenuItem extends PopupMenu.PopupBaseMenuItem { } } } -}; +}); -var TeaTime = class extends PanelMenu.Button { +let TeaTime = GObject.registerClass( +class TeaTime extends PanelMenu.Button { + _init() { + super._init(1.0, "TeaTime"); - constructor() { - super(null, "TeaTime"); - - this.myinit = function () { + this.config_keys = Utils.GetConfigKeys(); this._settings = Utils.getSettings(); @@ -190,9 +192,9 @@ var TeaTime = class extends PanelMenu.Button { this._idleTimeout = null; this._createMenu(); - }; + } - this._createMenu = function () { + _createMenu() { this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); this._settings.connect("changed::" + this.config_keys.steep_times, this._updateTeaList.bind(this)); @@ -230,8 +232,9 @@ var TeaTime = class extends PanelMenu.Button { this.menu.addMenuItem(bottom); this._updateTeaList(); - }; - this._updateTeaList = function (config, output) { + } + + _updateTeaList(config, output) { // make sure the menu is empty this.teaItemCont.removeAll(); @@ -251,8 +254,9 @@ var TeaTime = class extends PanelMenu.Button { }.bind(this)); this.teaItemCont.addMenuItem(menuItem); } - }; - this._updateCountdownType = function (config, output) { + } + + _updateCountdownType(config, output) { let bWantGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown); if (bWantGraphicalCountdown != this._bGraphicalCountdown) { @@ -267,8 +271,9 @@ var TeaTime = class extends PanelMenu.Button { this._updateTimerDisplay(this._getRemainingSec()); } // if timeout active } // value changed - }; - this._createCustomTimer = function (text, event) { + } + + _createCustomTimer(text, event) { if (event.get_key_symbol() == Clutter.KEY_Enter || event.get_key_symbol() == Clutter.KEY_Return || event.get_key_symbol() == Clutter.KEY_KP_Enter) { @@ -297,8 +302,9 @@ var TeaTime = class extends PanelMenu.Button { } this._customEntry.set_text(""); } - }; - this._showNotification = function (subject, text) { + } + + _showNotification(subject, text) { let source = (Utils.isGnome34()) ? new MessageTray.Source(_("TeaTime applet")) : new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime'); @@ -322,8 +328,9 @@ var TeaTime = class extends PanelMenu.Button { let notification = new MessageTray.Notification(source, subject, text); notification.setTransient(true); source.notify(notification); - }; - this._initCountdown = function (time) { + } + + _initCountdown(time) { this._startTime = new Date(); this._stopTime = new Date(); this._cntdownStart = time; @@ -346,26 +353,30 @@ var TeaTime = class extends PanelMenu.Button { if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout); this._idleTimeout = Mainloop.timeout_add_seconds(dt, this._doCountdown.bind(this)); - }; - this._stopCountdown = function () { + } + + _stopCountdown() { if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout); this.actor.remove_actor(this._bGraphicalCountdown ? this._graphicalTimer : this._textualTimer); this.actor.add_actor(this._logo); this._idleTimeout = null; - }; - this._getRemainingSec = function () { + } + + _getRemainingSec() { let a = new Date(); return (this._stopTime.getTime() - a.getTime()) * 1e-3; - }; - this._updateTimerDisplay = function (remainingTime) { + } + + _updateTimerDisplay(remainingTime) { if (this._bGraphicalCountdown) { this._graphicalTimer.setStatus((this._cntdownStart - remainingTime) / this._cntdownStart); } else { this._textualTimer.text = Utils.formatTime(remainingTime); } - }; - this._doCountdown = function () { + } + + _doCountdown() { let remainingTime = this._getRemainingSec(); if (remainingTime <= 0) { @@ -385,19 +396,22 @@ var TeaTime = class extends PanelMenu.Button { this._updateTimerDisplay(remainingTime); return true; // continue timer } - }; - this._playSound = function () { + } + + _playSound() { let bPlayAlarmSound = this._settings.get_boolean(this.config_keys.use_alarm_sound); if (bPlayAlarmSound) { Utils.playSound(this._settings.get_string(this.config_keys.alarm_sound)); } - }; - this._showPreferences = function () { + } + + _showPreferences() { const currExt = ExtensionUtils.getCurrentExtension(); imports.misc.util.spawn(["gnome-shell-extension-prefs", currExt.metadata['uuid']]); return 0; - }; - this._onStyleChanged = function (actor) { + } + + _onStyleChanged(actor) { let themeNode = actor.get_theme_node(); let color = themeNode.get_foreground_color() let [bHasPadding, padding] = themeNode.lookup_length("-natural-hpadding", false); @@ -421,11 +435,8 @@ var TeaTime = class extends PanelMenu.Button { let scaling = Utils.getGlobalDisplayScaleFactor(); this._logo.setScaling(scaling); this._graphicalTimer.setScaling(scaling); - }; - this.config_keys = Utils.GetConfigKeys(); - this.myinit(); } -}; +}); function init(metadata) { let theme = imports.gi.Gtk.IconTheme.get_default(); @@ -442,4 +453,4 @@ function enable() { function disable() { if (_TeaTime._idleTimeout != null) Mainloop.source_remove(_TeaTime._idleTimeout); _TeaTime.destroy(); -}; +} diff --git a/src/icon.js b/src/icon.js index eda72d8..3706ca8 100644 --- a/src/icon.js +++ b/src/icon.js @@ -10,19 +10,20 @@ * If there is a better way for that stuff, please let me know ;) ********************************************************************/ +const GObject = imports.gi.GObject; const St = imports.gi.St; const Clutter = imports.gi.Clutter; const ExUt = imports.misc.extensionUtils; const Me = ExUt.getCurrentExtension(); const Utils = Me.imports.utils; -var TwoColorIcon = class extends St.DrawingArea { - constructor(size, drawingObject) { - super({ +var TwoColorIcon = GObject.registerClass( +class TwoColorIcon extends St.DrawingArea { + _init(size, drawingObject) { + super._init({ reactive: true, style: 'padding: 0px 0px' }); - this.myinit = function () { this._base_size = size; //this.setScaling(Utils.getGlobalDisplayScaleFactor()); @@ -41,27 +42,32 @@ var TwoColorIcon = class extends St.DrawingArea { }); this._secundaryColor = this._primaryColor; this._customStatus = null; - }; - this.setPadding = function (padding) { + } + + setPadding(padding) { this.margin_left = padding; this.margin_right = padding; - }; - this.setColor = function (primary, secundary) { + } + + setColor(primary, secundary) { this._primaryColor = primary; this._secundaryColor = secundary; this.queue_repaint(); - }; - this.setScaling = function (newScale) { + } + + setScaling(newScale) { this._default_scale = newScale; this.set_width(this._base_size * this._default_scale); this.set_height(this._base_size * this._default_scale); this.queue_repaint(); - }; - this.setStatus = function (newStatus) { + } + + setStatus(newStatus) { this._customStatus = newStatus; this.queue_repaint(); - }; - this._drawIcon = function () { + } + + _drawIcon() { let cr = this.get_context(); let orWdt = this._drawingObject.width; let orHgt = this._drawingObject.height; @@ -85,10 +91,8 @@ var TwoColorIcon = class extends St.DrawingArea { } catch (e) { // ignore } - }; - this.myinit(); } -}; +}); var TeaPot = { width: 484, diff --git a/src/prefs.js b/src/prefs.js index 9916017..cccab95 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -22,9 +22,10 @@ const Columns = { ADJUSTMENT: 2 } -var TeaTimePrefsWidget = class extends Gtk.Grid { - constructor() { - super({ +var TeaTimePrefsWidget = GObject.registerClass( +class TeaTimePrefsWidget extends Gtk.Grid { + _init() { + super._init({ orientation: Gtk.Orientation.VERTICAL, column_homogeneous: false, vexpand: true, @@ -32,7 +33,8 @@ var TeaTimePrefsWidget = class extends Gtk.Grid { row_spacing: 5 }); - this.myinit = function () { + this.config_keys = Utils.GetConfigKeys(); + this._tealist = new Gtk.ListStore(); this._tealist.set_column_types([ GObject.TYPE_STRING, @@ -51,8 +53,9 @@ var TeaTimePrefsWidget = class extends Gtk.Grid { this._refresh(); this._tealist.connect("row-changed", this._save.bind(this)); this._tealist.connect("row-deleted", this._save.bind(this)); - }; - this._initWindow = function () { + } + + _initWindow() { let curRow = 0; let labelFN = new Gtk.Label({ label: _("Fullscreen Notifications"), @@ -173,8 +176,9 @@ var TeaTimePrefsWidget = class extends Gtk.Grid { }); this.removeButton.connect("clicked", this._removeSelectedTea.bind(this)); this.toolbar.insert(this.removeButton, -1); - }; - this._refresh = function () { + } + + _refresh() { // don't update the model if someone else is messing with the backend if (this._inhibitUpdate) return; @@ -205,8 +209,9 @@ var TeaTimePrefsWidget = class extends Gtk.Grid { } this._inhibitUpdate = false; - }; - this._addTea = function () { + } + + _addTea() { let adj = new Gtk.Adjustment({ lower: 1, step_increment: 1, @@ -218,8 +223,9 @@ var TeaTimePrefsWidget = class extends Gtk.Grid { this.treeview.set_cursor(this._tealist.get_path(item), this.treeview.get_column(Columns.TEA_NAME), true); - }; - this._removeSelectedTea = function () { + } + + _removeSelectedTea() { let [selection, store] = this.treeview.get_selection().get_selected_rows(); let iters = []; for (let i = 0; i < selection.length; ++i) { @@ -234,8 +240,9 @@ var TeaTimePrefsWidget = class extends Gtk.Grid { }); this.treeview.get_selection().unselect_all(); - }; - this._saveFullscreenNotifications = function (sw, data) { + } + + _saveFullscreenNotifications(sw, data) { // don't update the backend if someone else is messing with the model if (this._inhibitUpdate) return; @@ -243,8 +250,9 @@ var TeaTimePrefsWidget = class extends Gtk.Grid { this._settings.set_boolean(this.config_keys.fullscreen_notification, sw.active); this._inhibitUpdate = false; - }; - this._saveGraphicalCountdown = function (sw, data) { + } + + _saveGraphicalCountdown(sw, data) { // don't update the backend if someone else is messing with the model if (this._inhibitUpdate) return; @@ -252,8 +260,9 @@ var TeaTimePrefsWidget = class extends Gtk.Grid { this._settings.set_boolean(this.config_keys.graphical_countdown, sw.active); this._inhibitUpdate = false; - }; - this._saveUseAlarm = function (sw, data) { + } + + _saveUseAlarm(sw, data) { // don't update the backend if someone else is messing with the model if (this._inhibitUpdate) return; @@ -261,8 +270,9 @@ var TeaTimePrefsWidget = class extends Gtk.Grid { this._settings.set_boolean(this.config_keys.use_alarm_sound, sw.active); this._inhibitUpdate = false; - }; - this._saveSoundFile = function (sw, data) { + } + + _saveSoundFile(sw, data) { // don't update the backend if someone else is messing with the model if (this._inhibitUpdate) return; @@ -279,8 +289,9 @@ var TeaTimePrefsWidget = class extends Gtk.Grid { this._settings.set_string(this.config_keys.alarm_sound, alarm_sound); this._inhibitUpdate = false; } - }; - this._save = function (store, path_, iter_) { + } + + _save(store, path_, iter_) { const GLib = imports.gi.GLib; // don't update the backend if someone else is messing with the model @@ -302,12 +313,8 @@ var TeaTimePrefsWidget = class extends Gtk.Grid { this._settings.set_value(this.config_keys.steep_times, settingsValue); this._inhibitUpdate = false; - }; - this.config_keys = Utils.GetConfigKeys(); - this.myinit(); } -}; - +}); function init() {}