init-check-network-connection.org 1.2 KB

lexical binding

:PROPERTIES: :ID: c901c3d8-a46e-4b21-9105-482ab7b8ef16 :END:


;; -*- lexical-binding: t; -*-

check-network-connection

:PROPERTIES: :ID: 244b5234-cee7-4d5c-9e1a-47d5c2a85741 :END:

I am starting a synchronous process to determine if I have an internet connection. If I do have an internet connection, then the global variable my-onlinep will be t.


  (setq my-onlinep nil)

  (defun my/nmcli-filter-function (proc output)
    (cond
     ((string= output "full\n")
      (setq my-onlinep t))
     ((or (string= output "none\n")
          (string= output "unknown\n"))
      (setq my-onlinep nil))))

  (defun my/check-internet-connection ()
    (set-process-filter
     (start-process "nmcli" nil "nmcli" "-c" "no" "network" "connectivity"
                    "check")
     'my/nmcli-filter-function))

  (my/check-internet-connection)

provide this file

:PROPERTIES: :ID: de7b8959-ad8a-488c-9b56-356ddb8ce264 :END:


(provide 'init-check-network-connection)