Skip to content

Commit b8618c8

Browse files
authored
Merge pull request #48 from nlpsuge/fix-47-gnome-freezing
Create EndSessionDialog dbus proxy and connect dbus signals asynchronously, otherwise gnome freezes for some time (about 25 seconds in my machine, maybe it is timeout of connecting dbus signals) when logging in, unlocking the screen or disable/enable it. Fixes #47.
2 parents 9057018 + 4ce0f10 commit b8618c8

4 files changed

Lines changed: 74 additions & 12 deletions

File tree

extension.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ const Autostart = Me.imports.ui.autostart;
1313

1414
let _indicator;
1515
let _autostartServiceProvider;
16+
let _openWindowsInfoTracker;
1617

1718
function enable() {
1819
_indicator = new Indicator.AwsIndicator();
1920
Main.panel.addToStatusArea('Another Window Session Manager', _indicator);
2021

2122
_autostartServiceProvider = new Autostart.AutostartServiceProvider();
2223

23-
new OpenWindowsInfoTracker.OpenWindowsInfoTracker();
24+
_openWindowsInfoTracker = new OpenWindowsInfoTracker.OpenWindowsInfoTracker();
2425

2526
}
2627

@@ -34,6 +35,11 @@ function disable() {
3435
_autostartServiceProvider.disable();
3536
_autostartServiceProvider = null;
3637
}
38+
39+
if (_openWindowsInfoTracker) {
40+
_openWindowsInfoTracker.destroy();
41+
_openWindowsInfoTracker = null;
42+
}
3743

3844
}
3945

metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
],
1010
"url": "https://github.com/nlpsuge/gnome-shell-extension-another-window-session-manager",
1111
"uuid": "another-window-session-manager@gmail.com",
12-
"version": 19
12+
"version": 20
1313
}

openWindowsInfoTracker.js

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,51 @@ var OpenWindowsInfoTracker = class {
2929
this._prefsUtils = new PrefsUtils.PrefsUtils();
3030
this._settings = this._prefsUtils.getSettings();
3131

32-
this._endSessionProxy = new EndSessionDialogProxy(Gio.DBus.session,
33-
'org.gnome.Shell',
34-
'/org/gnome/SessionManager/EndSessionDialog');
35-
36-
this._endSessionProxy.connectSignal('ConfirmedLogout', this._onConfirmedLogout.bind(this));
37-
this._endSessionProxy.connectSignal('ConfirmedReboot', this._onConfirmedReboot.bind(this));
38-
this._endSessionProxy.connectSignal('ConfirmedShutdown', this._onConfirmedShutdown.bind(this));
39-
this._endSessionProxy.connectSignal('Closed', this._onClose.bind(this));
40-
this._endSessionProxy.connectSignal('Canceled', this._onCancel.bind(this));
32+
this._confirmedLogoutId = 0;
33+
this._confirmedRebootId = 0;
34+
this._confirmedShutdownId = 0;
35+
this._closedId = 0;
36+
this._canceledId = 0;
37+
38+
this._busWatchId = Gio.bus_watch_name(
39+
Gio.BusType.SESSION,
40+
'org.gnome.Shell',
41+
Gio.BusNameWatcherFlags.NONE,
42+
this._onNameAppeared.bind(this),
43+
this._onNameVanished.bind(this)
44+
);
4145

4246
this._display = global.display;
4347
this._displayId = this._display.connect('window-created', this._windowCreated.bind(this));
4448
}
4549

50+
_onNameAppeared() {
51+
this._endSessionProxy = new EndSessionDialogProxy(Gio.DBus.session,
52+
'org.gnome.Shell',
53+
'/org/gnome/SessionManager/EndSessionDialog',
54+
(proxy, error) => {
55+
// If `error` is not `null` it will be an Error object indicating the
56+
// failure, and `proxy` will be `null` in this case.
57+
if (error !== null) {
58+
this._log.error(error);
59+
return;
60+
}
61+
62+
this._confirmedLogoutId = this._endSessionProxy.connectSignal('ConfirmedLogout', this._onConfirmedLogout.bind(this));
63+
this._confirmedRebootId = this._endSessionProxy.connectSignal('ConfirmedReboot', this._onConfirmedReboot.bind(this));
64+
this._confirmedShutdownId = this._endSessionProxy.connectSignal('ConfirmedShutdown', this._onConfirmedShutdown.bind(this));
65+
this._closedId = this._endSessionProxy.connectSignal('Closed', this._onClose.bind(this));
66+
this._canceledId = this._endSessionProxy.connectSignal('Canceled', this._onCancel.bind(this));
67+
},
68+
null,
69+
Gio.DBusProxyFlags.NONE
70+
);
71+
}
72+
73+
_onNameVanished(connection, name) {
74+
this._log.debug(`Dbus name ${name} vanished`);
75+
}
76+
4677
_onClose() {
4778
this._log.debug(`User closed endSessionDialog`);
4879
}
@@ -127,6 +158,31 @@ var OpenWindowsInfoTracker = class {
127158
this._displayId = 0;
128159
}
129160

161+
if (this._busWatchId) {
162+
Gio.bus_unwatch_name(this._busWatchId);
163+
this._busWatchId = 0;
164+
}
165+
166+
if (this._confirmedLogoutId) {
167+
this._endSessionProxy?.disconnectSignal(this._confirmedLogoutId);
168+
this._confirmedLogoutId = 0;
169+
}
170+
if (this._confirmedRebootId) {
171+
this._endSessionProxy?.disconnectSignal(this._confirmedRebootId);
172+
this._confirmedRebootId = 0;
173+
}
174+
if (this._confirmedShutdownId) {
175+
this._endSessionProxy?.disconnectSignal(this._confirmedShutdownId);
176+
this._confirmedShutdownId = 0;
177+
}
178+
if (this._closedId) {
179+
this._endSessionProxy?.disconnectSignal(this._closedId);
180+
this._closedId = 0;
181+
}
182+
if (this._canceledId) {
183+
this._endSessionProxy?.disconnectSignal(this._canceledId);
184+
this._canceledId = 0;
185+
}
130186
}
131187

132188
}

ui/autostart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var AutostartServiceProvider = GObject.registerClass(
6969
this._log.debug(`DBus name ${name} acquired!`);
7070
}
7171

72-
onNameLost(_connection, name) {
72+
onNameLost(connection, name) {
7373
this._log.debug(`Dbus name ${name} lost`);
7474
}
7575

0 commit comments

Comments
 (0)