From e814b13b228d277254c887fd7381e97726936554 Mon Sep 17 00:00:00 2001 From: Shawn <45184146+shawnc722@users.noreply.github.com> Date: Sat, 18 May 2024 18:07:49 +0000 Subject: [PATCH] Implement MPRIS Raise method to allow showing the window (#1845) * add functionality to raise window on mpris method call * since electron tray doesn't support double click on linux, open on single click there --- src/main/base/app.ts | 12 +++++++++++- src/main/plugins/mpris.ts | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/base/app.ts b/src/main/base/app.ts index 27be6fec5..27b5c9034 100644 --- a/src/main/base/app.ts +++ b/src/main/base/app.ts @@ -281,7 +281,7 @@ export class AppEvents { this.tray.setToolTip(app.getName()); this.setTray(false); - this.tray.on("double-click", () => { + this.tray.on("double-click", () => { // supports windows and mac only if (utils.getWindow()) { if (utils.getWindow().isVisible()) { utils.getWindow().focus(); @@ -291,6 +291,16 @@ export class AppEvents { } }); + this.tray.on("click", () => { + if (utils.getWindow() && process.platform === "linux") { // use single click to open when double doesn't work + if (utils.getWindow().isVisible()) { + utils.getWindow().focus(); + } else { + utils.getWindow().show(); + } + } + }); + utils.getWindow().on("show", () => { this.setTray(true); }); diff --git a/src/main/plugins/mpris.ts b/src/main/plugins/mpris.ts index 480dfad14..f8b8f67fd 100644 --- a/src/main/plugins/mpris.ts +++ b/src/main/plugins/mpris.ts @@ -73,6 +73,10 @@ export default class mpris { player.on("volume", (volume: string) => { renderer.executeJavaScript(`app.mk.volume = ${parseFloat(volume)}`); }); + player.on("raise", () => { + mpris.utils.getWindow().show(); + mpris.utils.getWindow().focus(); + }); mpris.utils.getIPCMain().on("mpris:playbackTimeDidChange", (event: any, time: number) => { player.getPosition = () => time;