Skip to content

Commit debf9ae

Browse files
committed
Fix review comments from v37
1 parent dfd1a22 commit debf9ae

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

extension.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import GLib from 'gi://GLib';
33
import GObject from 'gi://GObject';
44
import St from 'gi://St';
55
import Clutter from 'gi://Clutter';
6-
const Mainloop = imports.mainloop;
76

87
import * as LoginManager from 'resource:///org/gnome/shell/misc/loginManager.js';
98
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
@@ -26,7 +25,7 @@ const N__ = function (e) {
2625

2726
const HIBERNATE_CHECK_TIMEOUT = 20000;
2827

29-
export default class MyExtension extends Extension {
28+
export default class HibernateButtonExtension extends Extension {
3029
_loginManagerCanHibernate(asyncCallback) {
3130
if (this._loginManager._proxy) {
3231
// systemd path
@@ -50,7 +49,7 @@ export default class MyExtension extends Extension {
5049
}
5150
);
5251
} else {
53-
Mainloop.idle_add(() => {
52+
this.can_hibernate_sourceID = GLib.idle_add(() => {
5453
asyncCallback(false);
5554
return false;
5655
});
@@ -60,7 +59,7 @@ export default class MyExtension extends Extension {
6059
_loginManagerHibernate() {
6160
if (this._setting.get_boolean('hibernate-works-check')) {
6261
this._hibernateStarted = new Date();
63-
GLib.timeout_add(
62+
this.hibernate_sourceID = GLib.timeout_add(
6463
GLib.PRIORITY_DEFAULT,
6564
HIBERNATE_CHECK_TIMEOUT,
6665
() => this._checkDidHibernate()
@@ -106,7 +105,7 @@ export default class MyExtension extends Extension {
106105
}
107106
);
108107
} else {
109-
Mainloop.idle_add(() => {
108+
this.can_hybrid_sleep_sourceID = GLib.idle_add(() => {
110109
asyncCallback(false);
111110
return false;
112111
});
@@ -154,7 +153,7 @@ export default class MyExtension extends Extension {
154153
}
155154
);
156155
} else {
157-
Mainloop.idle_add(() => {
156+
this.can_suspend_then_hibernate_sourceID = GLib.idle_add(() => {
158157
asyncCallback(false);
159158
return false;
160159
});
@@ -478,6 +477,26 @@ export default class MyExtension extends Extension {
478477
GLib.Source.remove(this.sourceId);
479478
this.sourceId = null;
480479
}
480+
481+
if (this.can_suspend_then_hibernate_sourceID) {
482+
GLib.Source.remove(this.can_suspend_then_hibernate_sourceID);
483+
this.can_suspend_then_hibernate_sourceID = null;
484+
}
485+
486+
if (this.can_hybrid_sleep_sourceID) {
487+
GLib.Source.remove(this.can_hybrid_sleep_sourceID);
488+
this.can_hybrid_sleep_sourceID = null;
489+
}
490+
491+
if (this.can_hibernate_sourceID) {
492+
GLib.Source.remove(this.can_hibernate_sourceID);
493+
this.can_hibernate_sourceID = null;
494+
}
495+
496+
if (this.hibernate_sourceID) {
497+
GLib.Source.remove(this.hibernate_sourceID);
498+
this.hibernate_sourceID = null;
499+
}
481500
};
482501
}
483502

0 commit comments

Comments
 (0)