fluttercommunity / plus_plugins

Flutter Community Plus Plugins
BSD 3-Clause "New" or "Revised" License
1.55k stars 927 forks source link

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

Open emersion opened 1 year ago

emersion commented 1 year ago

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.

jpnurmi commented 1 year ago
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;
sgehrman commented 1 year ago

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

jpnurmi commented 1 year ago

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

sgehrman commented 1 year ago

Thanks!! I didn't know this existed.

sgehrman commented 1 year ago

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;
    });