From 4ad81530200d2a82f29ca265c0cccb45b769a498 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Thu, 20 May 2021 11:41:32 +0800 Subject: Refactor wifi and bluetooth settings to a separate file * view-conf.el (durand-wifi-on-p): (durand-bluetooth-on-p): (durand-wifi-filter): (durand-bluetooth-filter): (durand-wifi-or-bluetooth): (global-map): These are moved to wifi-bluetooth-conf.el now. * wifi-bluetooth-conf.el (durand-wifi-on-p): (durand-bluetooth-on-p): (durand-wifi-filter): (durand-bluetooth-filter): (durand-wifi-toggle): (durand-bluetooth-toggle): These are old functions. (durand-wifi-executable): The name of an executable to manage wifis. (durand-wifi-bluetooth-buffer): A shared buffer for wifi-related commands. (durand-wifi-list-ports): List all available WIFI ports or the currently connected one, if the optional argument is non-nil. (durand-wifi-join-port): Join a port. This is still buggy. (durand-wifi-list-sentinel): The sentinel for the list-port function. (durand-wifi-join-filter): The filter to inform the user of the output of the command. This is important since currently the command will only error out for some reason. (global-map): Bind the functions to appropriate key sequences. --- view-conf.el | 96 ------------------------------------------------------------ 1 file changed, 96 deletions(-) (limited to 'view-conf.el') diff --git a/view-conf.el b/view-conf.el index 65f5d9f..f1f015f 100644 --- a/view-conf.el +++ b/view-conf.el @@ -241,101 +241,6 @@ options to choose from." (concat "https://www.youtube.com/watch?v=" (substring-no-properties video-name -11)))))) -;;; Wifi and Bluetooth handling - -;;;###autoload -(defvar durand-wifi-on-p nil - "If WIFI is on or not. -This is defined in \"/Users/durand/.emacs.d/view-conf.el\"") - -;;;###autoload -(defvar durand-bluetooth-on-p nil - "If BLUETOOTH is on or not. -This is defined in \"/Users/durand/.emacs.d/view-conf.el\"") - -;;;###autoload -(defun durand-wifi-filter (proc output) - "Filter function to set the wifi variable. -This should only be used for the process \"durand-wifi\". -This is defined in \"/Users/durand/.emacs.d/view-conf.el\"" - (cond - ((string= (process-name proc) "durand-wifi")) - ((user-error "Filter function associated with a wrong process."))) - (setq durand-wifi-on-p (string-match "On$" output))) - -;;;###autoload -(defun durand-bluetooth-filter (proc output) - "Filter function to set the bluetooth variable. -This should only be used for the process \"durand-bluetooth\". -This is defined in \"/Users/durand/.emacs.d/view-conf.el\"" - (cond - ((string= (process-name proc) "durand-bluetooth")) - ((user-error "Filter function associated with a wrong process."))) - (setq durand-bluetooth-on-p (string-match "1" output))) - -;;;###autoload -(defun durand-wifi-or-bluetooth (&optional arg) - "Check if WIFI is enabled, then ask for confirmation to toggle WIFI. -If ARG is non-nil, do the same for Bluetooth." - (interactive "P") - (cond - ((null arg) - (make-process - :name "durand-wifi" - :buffer nil - :command '("networksetup" "-getairportpower" "en0") - :filter #'durand-wifi-filter - :sentinel #'ignore) - (accept-process-output (get-process "durand-wifi")) - (let* ((prompt (format "WIFI is %s. Do you want to turn WIFI %s" - (cond (durand-wifi-on-p "on") - ("off")) - (cond (durand-wifi-on-p "off?") - ("on?")))) - (decision (y-or-n-p prompt))) - (cond - (decision - (let ((new-state (cond (durand-wifi-on-p "off") - ("on")))) - (make-process - :name "durand-toggle-wifi" - :buffer nil - :command (list - "networksetup" "-setairportpower" - "en0" new-state) - :sentinel #'ignore - :filter #'ignore) - (message "WIFI turned %s" new-state)))))) - (t - (make-process - :name "durand-bluetooth" - :buffer nil - :command '("blueutil" "-p") - :filter #'durand-bluetooth-filter - :sentinel 'ignore) - (accept-process-output (get-process "durand-bluetooth")) - (let* ((prompt (format "BLUETOOTH is %s. Do you want to turn BLUETOOTH %s" - (cond (durand-bluetooth-on-p "on") - ("off")) - (cond (durand-bluetooth-on-p "off?") - ("on?")))) - (decision (y-or-n-p prompt))) - (cond - (decision - (let ((new-state (cond (durand-bluetooth-on-p "0") - ("1")))) - (make-process - :name "durand-toggle-bluetooth" - :buffer nil - :command (list "blueutil" "-p" new-state) - :sentinel 'ignore - :filter 'ignore) - (message "BLUETOOTH turned %s" - (cond (durand-bluetooth-on-p "off") - ("on")))))))))) - -(define-key global-map (vector 3 ?w) #'durand-wifi-or-bluetooth) - ;;; moving by paragraphs ;;;###autoload @@ -399,4 +304,3 @@ If ARG is non-nil, do the same for Bluetooth." (view-mode -1) (olivetti-mode -1) (text-scale-increase 0)))) - -- cgit v1.2.3-18-g5258