plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[Request]: Use org.freedesktop.portal.NetworkMonitor on Linux

Open emersion opened this issue 2 years ago • 5 comments

Plugin

connectivity_plus

Use case

I want to distribute my app in a Flatpak sandbox.

The plugin is not allowed to connect to the D-Bus system bus:

flutter: SocketException: Connection failed (OS Error: No such file or directory, errno = 2), address = /var/run/dbus/system_bus_socket, port = 0

Proposal

Flatpak portals are a network daemon agnostic way to fetch network information. It works both inside and outside sandboxes.

https://docs.flatpak.org/en/latest/portal-api-reference.html#gdbus-org.freedesktop.portal.NetworkMonitor

It shjould be used instead of trying to talk directly to NetworkManager.

emersion avatar Oct 14 '22 12:10 emersion

enum ConnectivityResult { bluetooth, wifi, ethernet, mobile, none, vpn }

vs.

typedef enum {
  G_NETWORK_CONNECTIVITY_LOCAL       = 1,
  G_NETWORK_CONNECTIVITY_LIMITED     = 2,
  G_NETWORK_CONNECTIVITY_PORTAL      = 3,
  G_NETWORK_CONNECTIVITY_FULL        = 4
} GNetworkConnectivity;

jpnurmi avatar Dec 12 '22 10:12 jpnurmi

I'm on flatpak too. connectivity_plus doesn't work. What is the work around?

sgehrman avatar Mar 25 '23 08:03 sgehrman

https://pub.dev/documentation/xdg_desktop_portal/latest/xdg_desktop_portal/XdgNetworkMonitorPortal-class.html

jpnurmi avatar Mar 25 '23 08:03 jpnurmi

Thanks!! I didn't know this existed.

sgehrman avatar Mar 25 '23 08:03 sgehrman

For anyone else that needs this:

   import 'package:xdg_desktop_portal/xdg_desktop_portal.dart';

   final XdgDesktopPortalClient portal = XdgDesktopPortalClient();
    portal.networkMonitor.status.listen((event) {
      _hasNetwork = event.available;
    });

sgehrman avatar Mar 25 '23 09:03 sgehrman