Fix errors in ‘oni-termux’
For some reason it appears that ‘alert-termux’ is added to the ‘load-path’ after ‘oni-termux’, so that when ‘oni-termux’ calls ‘require’ for ‘alert-termux’ it hasn’t been added to the ‘load-path’ yet and fails. When requiring the ‘battery’ library it seems to immediately try to read some information. Since Termux isn’t actually a linux distribution if fails with a "Permission Denied" error when trying to read ‘/sys/class/power_supply’. To prevent this from happening the ‘battery-status-function’ needs to be set before loading ‘battery’.
This commit is contained in:
parent
b9d40baf5e
commit
298885434b
1 changed files with 18 additions and 4 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
;; Author: Tom Willemse <tom@ryuslash.org>
|
;; Author: Tom Willemse <tom@ryuslash.org>
|
||||||
;; Keywords: local
|
;; Keywords: local
|
||||||
;; Version: 2019.0920.193557
|
;; Version: 2019.1006.113112
|
||||||
;; Package-Requires: (oni-alert alert-termux)
|
;; Package-Requires: (oni-alert alert-termux)
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
;; This program is free software; you can redistribute it and/or modify
|
||||||
|
@ -31,8 +31,7 @@
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(require 'alert)
|
(require 'alert)
|
||||||
(require 'alert-termux)
|
;;(require 'alert-termux)
|
||||||
(require 'battery)
|
|
||||||
(require 'json)
|
(require 'json)
|
||||||
|
|
||||||
(defun oni-termux--battery-status ()
|
(defun oni-termux--battery-status ()
|
||||||
|
@ -55,12 +54,27 @@ The following %-sequences are provided:
|
||||||
(cons ?B (alist-get 'status info "N/A"))
|
(cons ?B (alist-get 'status info "N/A"))
|
||||||
(cons ?t (number-to-string (alist-get 'temperature info -1))))))
|
(cons ?t (number-to-string (alist-get 'temperature info -1))))))
|
||||||
|
|
||||||
(setq battery-status-function #'oni-termux--battery-status)
|
(defun oni-termux--load-alert-termux ()
|
||||||
|
"Load ‘alert-termux’.
|
||||||
|
This can’t be done by a require because it appears that
|
||||||
|
‘alert-termux’ gets added to the load path and loaded after this
|
||||||
|
library, so use this function in ‘after-init-hook’ instead."
|
||||||
|
(load-library "alert-termux"))
|
||||||
|
|
||||||
|
;; To keep the byte-compiler happy I use a `defvar' here.
|
||||||
|
(defvar battery-status-function #'oni-termux--battery-status)
|
||||||
|
|
||||||
|
;; The battery library needs to be loaded after the battery variables
|
||||||
|
;; have been set, otherwise loading it will produce the error that
|
||||||
|
;; access is denied to /sys/class/power_supply.
|
||||||
|
(require 'battery)
|
||||||
|
|
||||||
(setq battery-mode-line-format "%p%%")
|
(setq battery-mode-line-format "%p%%")
|
||||||
|
|
||||||
(setq alert-default-style 'termux)
|
(setq alert-default-style 'termux)
|
||||||
|
|
||||||
|
(add-hook 'after-init-hook #'oni-termux--load-alert-termux)
|
||||||
|
|
||||||
(display-battery-mode)
|
(display-battery-mode)
|
||||||
|
|
||||||
;;;###autoload(require 'oni-termux)
|
;;;###autoload(require 'oni-termux)
|
||||||
|
|
Loading…
Reference in a new issue