From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: john muhl Newsgroups: gmane.emacs.bugs Subject: bug#73538: [PATCH] Add notifications support to 'mpc' Date: Sat, 28 Sep 2024 17:48:21 -0500 Message-ID: <87frpjtmx6.fsf@pub.pink> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30473"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier To: 73538@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 29 00:48:52 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sugF8-0007ho-Ur for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 29 Sep 2024 00:48:52 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sugEt-0003xs-Ov; Sat, 28 Sep 2024 18:48:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sugEr-0003xg-Fn for bug-gnu-emacs@gnu.org; Sat, 28 Sep 2024 18:48:33 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sugEr-00011b-0D for bug-gnu-emacs@gnu.org; Sat, 28 Sep 2024 18:48:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=H1Fn39rLpZVoQC4W6mi5aMK9s8xPxyTnjEGZqRFnQ34=; b=rSaQOi7ObbBnk6zo2okdZbIcpfyCuIVhUExqiGP2Zv3D+hUihHbBvVvTXUjTJwdz+V86u/LEy6U7R1NF+GopDSNei5mvwq1T+dACuIuxx6KEfXZhmcdMY1kRytojIplAw+9/NC9785nySfihJX4IqP8dciJgfpnj6QdRPmQK/H26Y91YVDgm+10eYv3DYexG4iImBSR05wGgs1Ft6bxA01FiObR8pibI93Y2HK7nLrBPFV4wHDL8Rm/GZ8R9S20DUSQa2ibiUupBbTPsSLKSN+NYfLrUhqhTFqZEiamYhn2+Yv95DHaPbhhm2q83phzicbJxUF6C5TQ3o4c2w/wANw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sugFK-0006yO-Kw; Sat, 28 Sep 2024 18:49:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: john muhl Original-Sender: "Debbugs-submit" Resent-CC: monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org Resent-Date: Sat, 28 Sep 2024 22:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73538 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: Stefan Monnier Original-Received: via spool by submit@debbugs.gnu.org id=B.172756374126799 (code B ref -1); Sat, 28 Sep 2024 22:49:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 28 Sep 2024 22:49:01 +0000 Original-Received: from localhost ([127.0.0.1]:52473 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sugFJ-0006y5-3c for submit@debbugs.gnu.org; Sat, 28 Sep 2024 18:49:01 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:52342) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sugFH-0006xq-36 for submit@debbugs.gnu.org; Sat, 28 Sep 2024 18:49:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sugEm-0003xP-9y for bug-gnu-emacs@gnu.org; Sat, 28 Sep 2024 18:48:28 -0400 Original-Received: from fhigh-a3-smtp.messagingengine.com ([103.168.172.154]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sugEk-00011G-8q for bug-gnu-emacs@gnu.org; Sat, 28 Sep 2024 18:48:28 -0400 Original-Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 6DFF4114019F for ; Sat, 28 Sep 2024 18:48:23 -0400 (EDT) Original-Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Sat, 28 Sep 2024 18:48:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; h=cc :content-type:content-type:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:subject:subject:to:to; s=fm2; t=1727563703; x=1727650103; bh=H1Fn39rLpZVoQC4W6mi5aMK9s8xPxyTn jEGZqRFnQ34=; b=Zbj5Mvh9Yn9TidzipPv31qgHjtxJZHE0WtQcEoVs4Irm5k5C uXZqjE8DdzKrOQhyi3YciSz5yvwAb2IQryVGVZo1sYxDaKOXCdRrF6oL7WDXQFg8 e2aIe8HGLRuzH7Qgmtcyw8iTzBf+L6wHAuIRRwAJ+4aojKCS62AOHqxq1kAkjYwA 4pswj7lvt6kZFjgV5NIi4qHVDACbg2qTnm3YN0f+r3uaFrmfgYHe9/qqxD4sMYRh DcodIPnpRQE/KjpdHqimMtOO/cANpvQvaXv0+XdsxrQnyZd5t2riJmW0VLtf3FSF 87ZASj3Cbbol1mb44uHaUqMyv4KwainVEGP2cw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1727563703; x=1727650103; bh=H1Fn39rLpZVoQC4W6mi5aMK9s8xPxyTnjEG ZqRFnQ34=; b=VTa4bsX6zlRPVsOl0wdZpMLx6hsIvZNfdguVFnYZe7nqHj85+Kq +U0mxvuAqfz8Qi/ukt1ygspMPl6f8JTMZpRf1er8v7rz1gPwwdCbMNhO+Z1zxhdM 4YAlTE6kqVEJXslYbfzHjlq/DheDHd6xDMif7768FSPkvN9gMNgJkQZSqldwsADK g9QdKJVohlittW1xLyoC5oOqtXmXCWRBvIFYdh7gDw0GVybAaFsh7QVU6s3Inx+o oDf/vTuvqbA8RWjMsZfTXKcWAgWUuyjUDHMknPqC/S3e4ecUanjAp7N+2DLavs7R QWh9DP+6pFjb95zDcYMq/Q/hqAPcFnrWIGg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduvddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvffuff fkgggtsehmtderredttddtnecuhfhrohhmpehjohhhnhcumhhuhhhluceojhhmsehpuhgs rdhpihhnkheqnecuggftrfgrthhtvghrnhepfefhvdefuddtledvvddvjefhfedvfeelge fgieeuieeitddvvdfgieeuudegleejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepjhhmsehpuhgsrdhpihhnkhdpnhgspghrtghpthhtohepud dpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepsghughdqghhnuhdqvghmrggtshes ghhnuhdrohhrgh X-ME-Proxy: Feedback-ID: i74194916:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sat, 28 Sep 2024 18:48:22 -0400 (EDT) Received-SPF: pass client-ip=103.168.172.154; envelope-from=jm@pub.pink; helo=fhigh-a3-smtp.messagingengine.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:292607 Archived-At: --=-=-= Content-Type: text/plain Tags: patch This adds support for displaying a notification when the song changes. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-notifications-support-to-mpc.patch >From eb495c851dafcf883b0c1cbcd22b2dedc074f226 Mon Sep 17 00:00:00 2001 From: john muhl Date: Sun, 15 Sep 2024 19:52:25 -0500 Subject: [PATCH] Add notifications support to 'mpc' * lisp/mpc.el (mpc-notifications): (mpc-notifications-function): New option. (mpc-notifications-id): New variable. (mpc-notifications-notify): (mpc-cover-image-find): (mpc-cover-image-p): New function. --- lisp/mpc.el | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/lisp/mpc.el b/lisp/mpc.el index 768c70c2e3a..30e295d4810 100644 --- a/lisp/mpc.el +++ b/lisp/mpc.el @@ -95,6 +95,8 @@ (require 'cl-lib) (require 'subr-x)) +(require 'notifications) + (defgroup mpc () "Client for the Music Player Daemon (mpd)." :prefix "mpc-" @@ -2766,6 +2768,83 @@ mpc-drag-n-drop (t (error "Unsupported drag'n'drop gesture")))))) +;;; Notifications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(declare-function notifications-notify "notifications") +(declare-function w32-notification-notify "notifications") +(declare-function haiku-notifications-notify "notifications") +(declare-function android-notifications-notify "notifications") + +(defcustom mpc-notifications-function 'mpc-notifications-notify + "Function called to display notification." + :version "31.1" + :type 'function) + +(defcustom mpc-notifications nil + "Non-nil means to display notifications when the song changes." + :version "31.1" + :type 'boolean + :set (lambda (symbol value) + (if-let ((cb (cons 'file mpc-notifications-function)) + value) + (add-to-list 'mpc-status-callbacks cb) + (setq mpc-status-callbacks (delete cb mpc-status-callbacks))) + (set-default-toplevel-value symbol value))) + +(defvar mpc-notifications-id nil) + +(defun mpc-notifications-notify () + "Display a notification with information about the current song." + (interactive) + (mpc-status-refresh) + (when-let (((string= "play" (alist-get 'state mpc-status))) + (title (or (alist-get 'Title mpc-status) "Unknown Title")) + (body (or (alist-get 'Artist mpc-status) + (alist-get 'AlbumArtist mpc-status) + "Unknown Artist")) + (icon (or (mpc-cover-image-find (alist-get 'file mpc-status)) + notifications-application-icon))) + (pcase system-type + ("windows-nt" + (w32-notification-notify :title title :body body :icon icon)) + ("haiku" + (setq mpc-notifications-id + (haiku-notifications-notify :title title + :body body + :app-icon icon + :replaces-id mpc-notifications-id))) + ("android" + (setq mpc-notifications-id + (android-notifications-notify :title title + :body body + :icon icon + :replaces-id mpc-notifications-id)) + (android-notifications-notify :title title :body body :icon icon)) + (_ (when (notifications-get-server-information) + (setq mpc-notifications-id + (notifications-notify :title title + :body body + :app-icon icon + :replaces-id mpc-notifications-id))))))) + +(defun mpc-cover-image-find (file) + "Find cover image for FILE." + (and-let* ((default-directory mpc-mpd-music-directory) + (dir (file-name-directory file)) + (files (directory-files (mpc-file-local-copy dir))) + (cover (seq-find #'mpc-cover-image-p files)) + ((expand-file-name cover dir))))) + +(defun mpc-cover-image-p (file) + "Check if FILE is a cover image." + (let ((covers '(".folder.png" "folder.png" "cover.jpg" "folder.jpg"))) + (or (seq-find (lambda (cover) (string= file cover)) covers) + (and mpc-cover-image-re (string-match-p mpc-cover-image-re file))))) + +(when mpc-notifications + (add-to-list 'mpc-status-callbacks + (cons 'file mpc-notifications-function))) + ;;; Toplevel ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defcustom mpc-frame-alist '((name . "MPC") (tool-bar-lines . 1) -- 2.46.2 --=-=-=--