[gnome-shell/eos3.8: 176/255] status/payg: add menu action to apply a code before PayGo time is expired



commit b5aee404f02ccaaf7686bd225349b3d9690a22be
Author: Travis Reitter <travis reitter endlessm com>
Date:   Mon Dec 3 14:51:32 2018 -0800

    status/payg: add menu action to apply a code before PayGo time is expired
    
    With this change, the PAYG status applet supports entering a credit
    code before credit has expired. Without this last feature, users are
    forced to deal with the "credit expired" screen on its timeline rather
    than theirs (and without the implication that they're falling behind on
    payments).
    
     * 2020-04-01: Squash with 1684d3d6e
    
    https://phabricator.endlessm.com/T24125

 js/misc/paygManager.js |  1 +
 js/ui/payg.js          | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++
 js/ui/status/payg.js   |  4 ++++
 3 files changed, 69 insertions(+)
---
diff --git a/js/misc/paygManager.js b/js/misc/paygManager.js
index d252bf0e5a..b30521f27e 100644
--- a/js/misc/paygManager.js
+++ b/js/misc/paygManager.js
@@ -174,6 +174,7 @@ var PaygManager = GObject.registerClass({
         this._expiryTime = value;
         this._updateExpirationReminders();
 
+        this._paygNotifier.clearNotification();
         this.emit('expiry-time-changed', this._expiryTime);
     }
 
diff --git a/js/ui/payg.js b/js/ui/payg.js
index 725910883c..d2a2c42159 100644
--- a/js/ui/payg.js
+++ b/js/ui/payg.js
@@ -465,3 +465,67 @@ function timeToString(seconds) {
     let hoursStr = Gettext.ngettext('%s hour', '%s hours', hoursPast).format(hoursPast);
     return '%s %s'.format(daysStr, hoursStr);
 }
+
+var PaygNotifier = GObject.registerClass(
+class PaygNotifier extends GObject.Object {
+    _init() {
+        super._init();
+
+        this._notification = null;
+    }
+
+    notify(secondsLeft) {
+        // Only notify when in an regular session, not in GDM or initial-setup.
+        if (Main.sessionMode.currentMode !== 'user' &&
+            Main.sessionMode.currentMode !== 'endless')
+            return;
+
+        // Clear previous notification
+        this.clearNotification();
+
+        let source = new MessageTray.SystemNotificationSource();
+        Main.messageTray.add(source);
+
+        // by default, this notification is for early entry of an unlock code
+        let messageText = NOTIFICATION_EARLY_CODE_ENTRY_TEXT;
+        let urgency = MessageTray.Urgency.NORMAL;
+        let userInitiated = false;
+
+        // in case this is a "only X time left" warning notification
+        if (secondsLeft >= 0) {
+            let timeLeft = timeToString(secondsLeft);
+            messageText = NOTIFICATION_DETAILED_FORMAT_STRING.format(timeLeft);
+            urgency = MessageTray.Urgency.HIGH;
+        } else {
+            userInitiated = true;
+        }
+
+        this._notification = new ApplyCodeNotification(
+            source,
+            NOTIFICATION_TITLE_TEXT,
+            messageText);
+
+        if (userInitiated)
+            this._notification.setResident(true);
+
+        this._notification.setTransient(false);
+        this._notification.setUrgency(urgency);
+        source.notify(this._notification);
+
+        // if the user triggered this notification, immediately expand so the
+        // user sees the input field
+        if (userInitiated)
+            Main.messageTray._expandActiveNotification();
+
+        this._notification.connect('destroy', () => {
+            this._notification = null;
+        });
+    }
+
+    clearNotification() {
+        if (this._notification) {
+            this._notification.destroy();
+            this._notification = null;
+        }
+    }
+});
diff --git a/js/ui/status/payg.js b/js/ui/status/payg.js
index c6f9159ad7..26d66b8ff4 100644
--- a/js/ui/status/payg.js
+++ b/js/ui/status/payg.js
@@ -23,6 +23,10 @@ class PaygIndicator extends PanelMenu.SystemIndicator {
         this._paygManager = new PaygManager.PaygManager();
         this._indicator = this._addIndicator();
         this._item = new PopupMenu.PopupSubMenuMenuItem('', true);
+        this._paygNotifier = new Payg.PaygNotifier();
+        this._item.menu.addAction(_('Enter unlock codeā€¦'), () => {
+            this._paygNotifier.notify(-1);
+        });
         this.menu.addMenuItem(this._item);
 
         // show this status applet if PAYG is enabled and fill in


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]