chore(emacs): Orgnaise emacs modules in packages

This commit is contained in:
js0ny 2025-03-05 13:42:07 +00:00
parent 869e6ed042
commit 8f452172a5
5 changed files with 104 additions and 9 deletions

View file

@ -0,0 +1,77 @@
;;; org-pomodoro-music-controller.el --- Play music during org-pomodoro breaks -*- lexical-binding: t; -*-
;;; Commentary:
;;; Add music control to org-pomodoro breaks.
;;; Code:
(require 'org-pomodoro)
;; Variables
(defcustom org-pomodoro-music-player-command "playerctl"
"Command to control the music player."
:type 'string
:group 'org-pomodoro)
(defcustom org-pomodoro-music-player-args nil
"Arguments to pass to the music player command."
:type '(repeat string)
:group 'org-pomodoro)
(defun org-pomodoro-music-get-status ()
"Get thestatus of the music player."
(with-temp-buffer
(let ((args (append org-pomodoro-music-player-args '("status"))))
(apply #'call-process org-pomodoro-music-player-command nil t nil args)
(string-trim (buffer-string)))))
(defun org-pomodoro-music-is-playing-p ()
"Check if the music player is playing."
(let ((status (org-pomodoro-music-get-status)))
(string= status "Playing")))
(defun org-pomodoro-music-pause ()
"Stop the music player."
(let ((args (append org-pomodoro-music-player-args '("pause"))))
(apply #'call-process org-pomodoro-music-player-command nil nil nil args)))
(defun org-pomodoro-music-play ()
"Start the music player."
(let ((args (append org-pomodoro-music-player-args '("play"))))
(apply #'call-process org-pomodoro-music-player-command nil nil nil args)))
;; Defining Hooks
(defun org-pomodoro-music-break-started-hook ()
"When a break start, pause the music player."
(setq org-pomodoro-music-was-playing (org-pomodoro-music-is-playing-p))
(when org-pomodoro-music-was-playing
(org-pomodoro-music-pause)
(message "休息开始,音乐已暂停")))
;; (defun org-pomodoro-music-break-finished-hook ()
;; "When a break finishes, resume the music player."
;; (when (and org-pomodoro-music-was-playing
;; (not (org-pomodoro-music-is-playing-p)))
;; (org-pomodoro-music-play)
;; (message "休息结束,音乐已恢复播放"))
;; (setq org-pomodoro-music-was-playing nil))
(defun org-pomodoro-music-started-hook ()
"When a pomodoro start, play the music player."
(unless (org-pomodoro-music-is-playing-p)
(org-pomodoro-music-play)
(message "番茄开始,音乐已开始播放"))
)
;; Adding hooks
;; (add-hook 'org-pomodoro-break-started-hook #'org-pomodoro-music-break-started-hook)
;; (add-hook 'org-pomodoro-break-finished-hook #'org-pomodoro-music-break-finished-hook)
;; (add-hook 'org-pomodoro-long-break-started-hook #'org-pomodoro-music-break-started-hook)
;; (add-hook 'org-pomodoro-long-break-finished-hook #'org-pomodoro-music-break-finished-hook)
(add-hook 'org-pomodoro-started-hook #'org-pomodoro-music-started-hook)
(provide 'org-pomodoro-music-controller)
;;; org-pomodoro-music-controller.el ends here

View file

@ -0,0 +1,57 @@
;;; org-pomodoro-telegram-notifier.el --- 为 org-pomodoro 添加发送 Telegram 通知的功能。 -*- lexical-binding: t; -*-
;;; Commentary:
;;; Provide a way to send Telegram notifications when org-pomodoro breaks end.
;;; Code:
(require 'org-pomodoro)
(require 'request)
(defcustom org-pomodoro-telegram-bot-token ""
"Your Telegram bot token."
:type 'string
:group 'org-pomodoro)
(defcustom org-pomodoro-telegram-chat-id ""
"Your Telegram chat ID."
:type 'string
:group 'org-pomodoro)
(defcustom org-pomodoro-telegram-break-end-message "休息时间结束"
"The message to send when a break ends."
:type 'string
:group 'org-pomodoro)
(defun org-pomodoro-send-telegram-message (message)
"Send a message to the Telegram chat.
MESSAGE is the message to send."
(interactive)
(when (and (not (string-empty-p org-pomodoro-telegram-bot-token))
(not (string-empty-p org-pomodoro-telegram-chat-id)))
(request
(format "https://api.telegram.org/bot%s/sendMessage" org-pomodoro-telegram-bot-token)
:type "POST"
:data `(("chat_id" . ,org-pomodoro-telegram-chat-id)
("text" . ,"⏳<b>[Emacs]</b> <code>org-pomodoro</code>: 休息时间结束")
("parse_mode" . "HTML"))
:parser 'json-read
:success (cl-function
(lambda (&key data &allow-other-keys)
(message "成功发送 Telegram 通知")))
:error (cl-function
(lambda (&key error-thrown &allow-other-keys)
(message "发送 Telegram 通知失败: %S" error-thrown))))
)
)
(defun org-pomodoro-telegram-break-finished-hook ()
"Send a Telegram message when a break ends."
(org-pomodoro-send-telegram-message org-pomodoro-telegram-break-end-message))
(add-hook 'org-pomodoro-break-finished-hook #'org-pomodoro-telegram-break-finished-hook)
(add-hook 'org-pomodoro-long-break-finished-hook #'org-pomodoro-telegram-break-finished-hook)
(provide 'org-pomodoro-telegram-notifier)
;;; org-pomodoro-telegram-notifier.el ends here