[polari/wip/fmuellner/nm-portal-fixes: 9/9] app: Handle initially incorrect NetworkMonitor state
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/fmuellner/nm-portal-fixes: 9/9] app: Handle initially incorrect NetworkMonitor state
- Date: Tue, 4 Sep 2018 00:07:37 +0000 (UTC)
commit f7583cba468b14c94d0dc85a7fc1aa82f7f4cde6
Author: Florian Müllner <fmuellner gnome org>
Date: Fri Aug 31 17:30:36 2018 +0200
app: Handle initially incorrect NetworkMonitor state
The portal implementation now fetches the initial state asynchronously,
which means that "offline" can now either mean "offline" or a newly
initialized singleton that hasn't fetched its state yet.
Address this by tracking whether the state is valid, and wait for a
::network-changed signal otherwise. In particular this fixes cutting
off existing connections on startup due to an incorrect offline state.
https://gitlab.gnome.org/GNOME/polari/merge_requests/68
src/application.js | 22 ++++++++++++++++++++--
src/initialSetup.js | 3 ++-
src/telepathyClient.js | 5 +++--
3 files changed, 25 insertions(+), 5 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 4b259e6..ae371ba 100644
--- a/src/application.js
+++ b/src/application.js
@@ -285,8 +285,26 @@ var Application = GObject.registerClass({
this._userStatusMonitor = UserStatusMonitor.getDefault();
this._networksManager = NetworksManager.getDefault();
- if (!Gio.NetworkMonitor.get_default().get_network_metered())
- this._serverRoomManager = ServerRoomManager.getDefault();
+ // The portal implementation fetches the initial state asynchronously,
+ // so track when the it becomes valid to not base decisions on an
+ // incorrect offline state
+ let networkMonitor = Gio.NetworkMonitor.get_default();
+ networkMonitor.state_valid =
+ !Utils.isFlatpakSandbox() &&
+ GLib.getenv('GTK_USE_PORTAL') != '1';
+
+ if (!networkMonitor.state_valid) {
+ let id = networkMonitor.connect('network-changed', () => {
+ networkMonitor.disconnect(id);
+ networkMonitor.state_valid = true;
+
+ if (!networkMonitor.network_metered)
+ this._serverRoomManager = ServerRoomManager.getDefault();
+ });
+ } else {
+ if (!networkMonitor.network_metered)
+ this._serverRoomManager = ServerRoomManager.getDefault();
+ }
this._accountsMonitor.connect('account-status-changed',
this._onAccountStatusChanged.bind(this));
diff --git a/src/initialSetup.js b/src/initialSetup.js
index b9b55b8..2e1911f 100644
--- a/src/initialSetup.js
+++ b/src/initialSetup.js
@@ -57,7 +57,8 @@ var InitialSetupWindow = GObject.registerClass({
this._networkMonitor = Gio.NetworkMonitor.get_default();
this._networkMonitor.connect('notify::network-available',
this._onNetworkAvailableChanged.bind(this));
- this._onNetworkAvailableChanged();
+ if (this._networkMonitor.state_valid)
+ this._onNetworkAvailableChanged();
}
_onNetworkAvailableChanged() {
diff --git a/src/telepathyClient.js b/src/telepathyClient.js
index 39b81a4..71b6bc8 100644
--- a/src/telepathyClient.js
+++ b/src/telepathyClient.js
@@ -193,8 +193,9 @@ class TelepathyClient extends Tp.BaseClient {
this._networkMonitor.connect('network-changed',
this._onNetworkChanged.bind(this));
- this._onNetworkChanged(this._networkMonitor,
- this._networkMonitor.network_available);
+ if (this._networkMonitor.state_valid)
+ this._onNetworkChanged(this._networkMonitor,
+ this._networkMonitor.network_available);
}
_onNetworkChanged(mon, connected) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]