File 0111-Port-GObject-classes-to-JS6-classes.patch of Package hamster-time-tracker
From 86b61b5d552754b58960fcea1afd886112337e18 Mon Sep 17 00:00:00 2001
From: Martin Wilck <mwilck@suse.com>
Date: Thu, 9 May 2019 16:10:40 +0200
Subject: [PATCH 111/130] Port GObject classes to JS6 classes
This patch is heavily based on original work by
Ernestas Kulik <ekulik@redhat.com>.
This patch is required to make hamster-shell-extension work on
GNOME 3.32. At the same time, it breaks compatibility with older
gnome-shell versions that don't support ES6 class syntax.
See https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/361
Fixes https://github.com/projecthamster/hamster-shell-extension/issues/307
---
extension/prefs.js | 24 +++++------
extension/widgets/categoryTotalsWidget.js | 18 ++++-----
extension/widgets/factsBox.js | 26 ++++++------
extension/widgets/ongoingFactEntry.js | 21 +++++-----
extension/widgets/panelWidget.js | 49 +++++++++++------------
extension/widgets/todaysFactsWidget.js | 21 +++++-----
6 files changed, 77 insertions(+), 82 deletions(-)
diff --git a/extension/prefs.js b/extension/prefs.js
index 93ab15e..608034a 100644
--- a/extension/prefs.js
+++ b/extension/prefs.js
@@ -31,13 +31,13 @@ const Lang = imports.lang;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
-const HamsterSettingsWidget = new GObject.Class({
- Name: 'ProjectHamster.Prefs.HamsterSettingsWidget',
- GTypeName: 'HamsterSettingsWidget',
- Extends: Gtk.VBox,
+const HamsterSettingsWidget = GObject.registerClass(
+class HamsterSettingsWidget extends Gtk.VBox {
+ _init(params) {
+ super._init(params);
+
+ this.name = 'ProjectHamster.Prefs.HamsterSettingsWidget';
- _init : function(params) {
- this.parent(params);
this.margin = 10;
this._settings = ExtensionUtils.getSettings();
@@ -114,9 +114,9 @@ const HamsterSettingsWidget = new GObject.Class({
let version_text = ExtensionUtils.getCurrentExtension().metadata.version;
let version_label_text = "You are running hamster-shell-extension version " + version_text;
vbox.add(new Gtk.Label({label: version_label_text, margin_top: 10}));
- },
+ }
- _onPlacementChange: function(widget) {
+ _onPlacementChange(widget) {
let [success, iter] = widget.get_active_iter();
if (!success)
return;
@@ -127,9 +127,9 @@ const HamsterSettingsWidget = new GObject.Class({
return;
this._settings.set_int("panel-placement", newPlacement);
- },
+ }
- _onAppearanceChange: function(widget) {
+ _onAppearanceChange(widget) {
let [success, iter] = widget.get_active_iter();
if (!success)
return;
@@ -140,9 +140,9 @@ const HamsterSettingsWidget = new GObject.Class({
return;
this._settings.set_int("panel-appearance", newAppearance);
- },
+ }
- _onHotkeyChange: function(widget, bananas) {
+ _onHotkeyChange(widget, bananas) {
//global.log(widget, bananas);
let hotkey = widget.get_text();
let [key, mods] = Gtk.accelerator_parse(hotkey);
diff --git a/extension/widgets/categoryTotalsWidget.js b/extension/widgets/categoryTotalsWidget.js
index 683fe92..17af747 100644
--- a/extension/widgets/categoryTotalsWidget.js
+++ b/extension/widgets/categoryTotalsWidget.js
@@ -25,6 +25,7 @@ const Lang = imports.lang;
const St = imports.gi.St;
const Clutter = imports.gi.Clutter;
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Stuff = Me.imports.stuff;
@@ -33,19 +34,16 @@ const Stuff = Me.imports.stuff;
/**
* Custom Label widget that displays category totals.
*/
-var CategoryTotalsWidget = new Lang.Class({
- Name: 'CategoryTotals',
- Extends: St.Label,
-
- _init: function() {
- this.parent({style_class: 'summary-label'});
-
- },
+var CategoryTotalsWidget = GObject.registerClass(
+class CategoryTotals extends St.Label {
+ _init() {
+ super._init({style_class: 'summary-label'});
+ }
/**
* Recompute values and replace old string with new one based on passed facts.
*/
- refresh: function(facts) {
+ refresh(facts) {
/**
* Construct a string representing category totals.
*/
@@ -67,5 +65,5 @@ var CategoryTotalsWidget = new Lang.Class({
}
this.set_text(getString(facts));
- },
+ }
});
diff --git a/extension/widgets/factsBox.js b/extension/widgets/factsBox.js
index 42857f5..aa5a336 100644
--- a/extension/widgets/factsBox.js
+++ b/extension/widgets/factsBox.js
@@ -27,6 +27,7 @@ const PopupMenu = imports.ui.popupMenu;
const Clutter = imports.gi.Clutter;
const Mainloop = imports.mainloop;
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Gettext = imports.gettext.domain('hamster-shell-extension');
const _ = Gettext.gettext;
@@ -43,11 +44,10 @@ const TodaysFactsWidget = Me.imports.widgets.todaysFactsWidget.TodaysFactsWidget
* well as todays facts.
* @class
*/
-var FactsBox = new Lang.Class({
- Name: 'FactsBox',
- Extends: PopupMenu.PopupBaseMenuItem,
- _init: function(controller, panelWidget) {
- this.parent({reactive: false});
+var FactsBox =
+class FactsBox extends PopupMenu.PopupBaseMenuItem {
+ constructor(controller, panelWidget) {
+ super({reactive: false});
this._controller = controller;
@@ -79,32 +79,32 @@ var FactsBox = new Lang.Class({
// Setup category summery
this.summaryLabel = new CategoryTotalsWidget();
main_box.add(this.summaryLabel);
- },
+ }
// [FIXME]
// The best solution would be to listen for a 'FactsChanged' Signal that carries the new
// facts as payload and just refresh with this. But for now we stick with this
// simpler version.
- refresh: function(facts, ongoingFact) {
+ refresh(facts, ongoingFact) {
this.todaysFactsWidget.refresh(facts, ongoingFact);
this.summaryLabel.refresh(facts);
- },
+ }
/**
* Focus the fact entry and make sure todaysFactsWidget are scrolled to the bottom.
*/
- focus: function() {
+ focus() {
Mainloop.timeout_add(20, Lang.bind(this, function() {
this._scrollAdjustment.value = this._scrollAdjustment.upper;
global.stage.set_key_focus(this.ongoingFactEntry);
}));
- },
+ }
/**
* Remove any existing focus.
*/
- unfocus: function() {
+ unfocus() {
global.stage.set_key_focus(null);
- },
-});
+ }
+};
diff --git a/extension/widgets/ongoingFactEntry.js b/extension/widgets/ongoingFactEntry.js
index a46948d..b90238e 100644
--- a/extension/widgets/ongoingFactEntry.js
+++ b/extension/widgets/ongoingFactEntry.js
@@ -22,6 +22,7 @@ Copyright (c) 2016 - 2018 Eric Goller / projecthamster <elbenfreund@projecthamst
const Lang = imports.lang;
+const GObject = imports.gi.GObject;
const St = imports.gi.St;
const Clutter = imports.gi.Clutter;
@@ -39,12 +40,10 @@ const Me = imports.misc.extensionUtils.getCurrentExtension();
*
*
*/
-var OngoingFactEntry = new Lang.Class({
- Name: 'OngoingFactEntry',
- Extends: St.Entry,
-
- _init: function(controller) {
- this.parent({
+var OngoingFactEntry = GObject.registerClass(
+class OngoingFactEntry extends St.Entry {
+ _init(controller) {
+ super._init({
name: 'searchEntry',
can_focus: true,
track_hover: true,
@@ -59,7 +58,7 @@ var OngoingFactEntry = new Lang.Class({
this._runningActivitiesQuery = null;
this.clutter_text.connect('activate', Lang.bind(this, this._onEntryActivated));
this.clutter_text.connect('key-release-event', Lang.bind(this, this._onKeyReleaseEvent));
- },
+ }
/**
* Callback for when ``ongoingFactEntry`` gets activated.
@@ -70,13 +69,13 @@ var OngoingFactEntry = new Lang.Class({
*
* @callback FactsBox~_onEntryActivated
*/
- _onEntryActivated: function() {
+ _onEntryActivated() {
let text = this.get_text();
this._controller.apiProxy.AddFactRemote(text, 0, 0, false, Lang.bind(this, function(response, error) {
// not interested in the new id - this shuts up the warning
}));
this.set_text('');
- },
+ }
/**
* Callback triggered after key release.
@@ -85,7 +84,7 @@ var OngoingFactEntry = new Lang.Class({
*
* @callback FactsBox~_onKeyReleaseEvent
*/
- _onKeyReleaseEvent: function(textItem, evt) {
+ _onKeyReleaseEvent(textItem, evt) {
/**
* Check if the passed key is on our list of keys to be ignored.
*/
@@ -185,5 +184,5 @@ var OngoingFactEntry = new Lang.Class({
this._prevText = completion.toLowerCase();
}
}
- },
+ }
});
diff --git a/extension/widgets/panelWidget.js b/extension/widgets/panelWidget.js
index d43833d..7328ba0 100644
--- a/extension/widgets/panelWidget.js
+++ b/extension/widgets/panelWidget.js
@@ -23,6 +23,7 @@ Copyright (c) 2016 - 2018 Eric Goller / projecthamster <elbenfreund@projecthamst
const Lang = imports.lang;
const Gio = imports.gi.Gio;
+const GObject = imports.gi.GObject;
const Clutter = imports.gi.Clutter;
const PanelMenu = imports.ui.panelMenu;
const St = imports.gi.St;
@@ -55,14 +56,12 @@ const Stuff = Me.imports.stuff;
*
* @class
*/
-var PanelWidget = new Lang.Class({
- Name: 'PanelWidget',
- Extends: PanelMenu.Button,
-
- _init: function(controller) {
+var PanelWidget = GObject.registerClass(
+class PanelWidget extends PanelMenu.Button {
+ _init(controller) {
// [FIXME]
// What is the parameter?
- this.parent(0.0);
+ super._init(0.0);
this._controller = controller;
// [FIXME]
@@ -140,7 +139,7 @@ var PanelWidget = new Lang.Class({
this.timeout = GLib.timeout_add_seconds(0, 60, Lang.bind(this, this.refresh));
this.connect('destroy', Lang.bind(this, this._disableRefreshTimer));
this.refresh();
- },
+ }
/**
* This is our main 'update/refresh' method.
@@ -152,7 +151,7 @@ var PanelWidget = new Lang.Class({
* required facts etc and pass them to the relevant sub-widget's
* refresh methods.
*/
- refresh: function() {
+ refresh() {
/**
* We need to wrap our actual refresh code in this callback for now as
* I am having major difficulties using a syncronous dbus method call to
@@ -197,21 +196,21 @@ var PanelWidget = new Lang.Class({
// here.
this._controller.apiProxy.GetTodaysFactsRemote(Lang.bind(this, _refresh));
return GLib.SOURCE_CONTINUE;
- },
+ }
/**
* Open 'popup menu' containing the bulk of the extension widgets.
*/
- show: function() {
+ show() {
this.menu.open();
- },
+ }
/**
* Close/Open the 'popup menu' depending on previous state.
*/
- toggle: function() {
+ toggle() {
this.menu.toggle();
- },
+ }
/**
@@ -220,7 +219,7 @@ var PanelWidget = new Lang.Class({
* Depending on the 'display mode' set in the extensions settings this has
* slightly different consequences.
*/
- updatePanelDisplay: function(fact) {
+ updatePanelDisplay(fact) {
/**
* Return a text string representing the passed fact suitable for the panelLabel.
*
@@ -262,7 +261,7 @@ var PanelWidget = new Lang.Class({
this.panelLabel.show();
break;
}
- },
+ }
/**
* Disable the refresh timer.
@@ -272,9 +271,9 @@ var PanelWidget = new Lang.Class({
* This method is actually a callback triggered on the destroy
* signal.
*/
- _disableRefreshTimer: function() {
+ _disableRefreshTimer() {
GLib.source_remove(this.timeout);
- },
+ }
/**
* Callback to be triggered when an *ongoing fact* is stopped.
@@ -283,7 +282,7 @@ var PanelWidget = new Lang.Class({
* This will get the current time and issue the ``StopTracking``
* method call to the dbus interface.
*/
- _onStopTracking: function() {
+ _onStopTracking() {
let now = new Date();
let epochSeconds = Date.UTC(now.getFullYear(),
now.getMonth(),
@@ -293,25 +292,25 @@ var PanelWidget = new Lang.Class({
now.getSeconds());
epochSeconds = Math.floor(epochSeconds / 1000);
this._controller.apiProxy.StopTrackingRemote(GLib.Variant.new('i', [epochSeconds]));
- },
+ }
/**
* Callback that triggers opening of the *Overview*-Window.
*
* @callback panelWidget~_onOpenOverview
*/
- _onOpenOverview: function() {
+ _onOpenOverview() {
this._controller.windowsProxy.overviewSync();
- },
+ }
/**
* Callback that triggers opening of the *Add Fact*-Window.
*
* @callback panelWidget~_onOpenAddFact
*/
- _onOpenAddFact: function() {
+ _onOpenAddFact() {
this._controller.windowsProxy.editSync(GLib.Variant.new('i', [0]));
- },
+ }
/**
* Callback that triggers opening of the *Add Fact*-Window.
@@ -320,7 +319,7 @@ var PanelWidget = new Lang.Class({
*
* Note: This will open the GUI settings, not the extension settings!
*/
- _onOpenSettings: function() {
+ _onOpenSettings() {
this._controller.windowsProxy.preferencesSync();
- },
+ }
});
diff --git a/extension/widgets/todaysFactsWidget.js b/extension/widgets/todaysFactsWidget.js
index 1ec2de3..1b7f84a 100644
--- a/extension/widgets/todaysFactsWidget.js
+++ b/extension/widgets/todaysFactsWidget.js
@@ -25,6 +25,7 @@ const Lang = imports.lang;
const St = imports.gi.St;
const Clutter = imports.gi.Clutter;
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Stuff = Me.imports.stuff;
@@ -33,12 +34,10 @@ const Stuff = Me.imports.stuff;
/**
* A widget that lists all facts for *today*.
*/
-var TodaysFactsWidget = new Lang.Class({
- Name: 'TodaysFactsWidget',
- Extends: St.ScrollView,
-
- _init: function(controller, panelWidget) {
- this.parent({style_class: 'hamster-scrollbox'});
+var TodaysFactsWidget = GObject.registerClass(
+class TodaysFactsWidget extends St.ScrollView {
+ _init(controller, panelWidget) {
+ super._init({style_class: 'hamster-scrollbox'});
this._controller = controller;
this._panelWidget = panelWidget;
@@ -53,12 +52,12 @@ var TodaysFactsWidget = new Lang.Class({
this.factsBox.add(this.facts_widget);
this.add_actor(this.factsBox);
- },
+ }
/**
* Populate the widget with rows representing the passed facts.
*/
- populateFactsWidget: function(facts, ongoingFact) {
+ populateFactsWidget(facts, ongoingFact) {
/**
* Construct an individual row within the widget - representing a single fact.
@@ -181,13 +180,13 @@ var TodaysFactsWidget = new Lang.Class({
}
rowCount += 1;
}
- },
+ }
/**
* Clear the widget and populate it anew.
*/
- refresh: function(facts, ongoingFact) {
+ refresh(facts, ongoingFact) {
this.facts_widget.remove_all_children();
this.populateFactsWidget(facts, ongoingFact);
- },
+ }
});
--
2.26.1