This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository enlightenment.

View the commit online.

commit d96d53a69263da7b60daadc7cbf540b0d7315f43
Author: Carsten Haitzler <[email protected]>
AuthorDate: Fri Sep 11 17:48:01 2026 +0100

    nm: call functions when connected or disconnected and if online or not
---
 src/modules/networkmanager/e_mod_main.c | 62 ++++++++++++++++++++++++++++++++-
 src/modules/networkmanager/e_mod_main.h |  5 +++
 2 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/src/modules/networkmanager/e_mod_main.c b/src/modules/networkmanager/e_mod_main.c
index 1381a7cde..cef0091ef 100644
--- a/src/modules/networkmanager/e_mod_main.c
+++ b/src/modules/networkmanager/e_mod_main.c
@@ -2415,6 +2415,60 @@ _enm_mod_manager_update_inst(E_NM_Module_Context *ctxt EINA_UNUSED,
  */
 }
 
+/* Connection hooks.  Called after overall connectivity has settled,
+ * including changes in Internet access while a network remains connected. */
+static void
+_enm_connected(Eina_Bool online)
+{
+   INF("Network connected (_online_=%d)", online);
+}
+
+static void
+_enm_disconnected(void)
+{
+   INF("Network disconnected");
+}
+
+static Eina_Bool
+_enm_connection_timer_cb(void *data)
+{
+   E_NM_Module_Context *ctxt = data;
+
+   ctxt->connection_timer = NULL;
+   ctxt->connected = ctxt->pending_connected;
+   ctxt->_online_ = ctxt->pending_online;
+   if (ctxt->connected) _enm_connected(ctxt->online);
+   else _enm_disconnected();
+
+   return ECORE_CALLBACK_CANCEL;
+}
+
+static void
+_enm_connection_state_update(E_NM_Module_Context *ctxt, enum NM_State state)
+{
+   Eina_Bool connected, online;
+
+   connected = (state == NM_STATE_CONNECTED_LOCAL) ||
+               (state == NM_STATE_CONNECTED_SITE) ||
+               (state == NM_STATE_CONNECTED_GLOBAL);
+   /* NM's global state reports Internet access; local/site are connected
+    * networks without global connectivity. */
+   _online_ = (state == NM_STATE_CONNECTED_GLOBAL);
+   /* Routine manager updates must not postpone a pending notification. */
+   if ((ctxt->pending_connected == connected) &&
+       (ctxt->pending_online == online)) return;
+
+   ctxt->pending_connected = connected;
+   ctxt->pending_online = online;
+   E_FREE_FUNC(ctxt->connection_timer, ecore_timer_del);
+
+   /* A brief excursion back to the last reported state needs no callback. */
+   if ((ctxt->connected == connected) && (ctxt->_online_ == online)) return;
+
+   /* Wait for two seconds without a connectivity change before reporting. */
+   ctxt->connection_timer = ecore_timer_add(2.0, _enm_connection_timer_cb, ctxt);
+}
+
 static void
 _enm_mod_manager_update(struct NM_Manager *nm)
 {
@@ -2424,6 +2478,8 @@ _enm_mod_manager_update(struct NM_Manager *nm)
 
    EINA_SAFETY_ON_NULL_RETURN(nm);
 
+   _enm_connection_state_update(ctxt, nm->state);
+
    EINA_LIST_FOREACH(ctxt->instances, l, inst)
      _enm_mod_manager_update_inst(ctxt, inst, nm, nm->state);
 
@@ -2456,7 +2512,10 @@ _enm_mod_manager_inout(struct NM_Manager *nm)
         enm_saved_connections_get(nm);
      }
    else
-     _enm_traffic_timer_stop(ctxt);
+     {
+        _enm_connection_state_update(ctxt, NM_STATE_UNKNOWN);
+        _enm_traffic_timer_stop(ctxt);
+     }
 }
 
 static void
@@ -3263,6 +3322,7 @@ e_modapi_shutdown(E_Module *m)
    e_gadcon_provider_unregister(&_gc_class);
 
    E_FREE_FUNC(ctxt->popup_update_timer, ecore_timer_del);
+   E_FREE_FUNC(ctxt->connection_timer, ecore_timer_del);
    E_FREE_FUNC(ctxt->vpn_update_job, ecore_job_del);
    _enm_traffic_timer_stop(ctxt);
    E_FREE_FUNC(ctxt->powersave_handler, ecore_event_handler_del);
diff --git a/src/modules/networkmanager/e_mod_main.h b/src/modules/networkmanager/e_mod_main.h
index 71e622447..9eb2384e7 100644
--- a/src/modules/networkmanager/e_mod_main.h
+++ b/src/modules/networkmanager/e_mod_main.h
@@ -72,6 +72,7 @@ struct E_NM_Module_Context
    Eina_List          *instances;
    E_Config_Dialog    *conf_dialog;
    Ecore_Timer        *popup_update_timer;
+   Ecore_Timer        *connection_timer;
    Ecore_Job          *vpn_update_job;   /* deferred VPN-active-changed notify */
 
    struct NM_Manager  *nm;
@@ -91,6 +92,10 @@ struct E_NM_Module_Context
    int                  rx_level;        /* 0=idle, 1=low, 2=medium, 3=high */
    int                  tx_level;
    Eina_Bool            powersave_high : 1;
+   Eina_Bool            connected : 1;
+   Eina_Bool            online : 1;
+   Eina_Bool            pending_connected : 1;
+   Eina_Bool            pending_online : 1;
 };
 
 E_API extern E_Module_Api e_modapi;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to