mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-12-14 22:35:35 +01:00
Refactor preload script
This commit is contained in:
23
src/preload/integrations/notifications.ts
Normal file
23
src/preload/integrations/notifications.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { settingsStore } from "../../scripts/settings";
|
||||
import { $tidalState, coverArtPaths } from "../state";
|
||||
import { settings } from "../../constants/settings";
|
||||
import { Notification } from "@electron/remote";
|
||||
|
||||
let currentNotification: Electron.Notification | undefined;
|
||||
|
||||
$tidalState.subscribe(async (state, prevState) => {
|
||||
if (!settingsStore.get(settings.notifications)) return;
|
||||
if (!state.currentTrack) return;
|
||||
|
||||
if (state.currentTrack.id === prevState.currentTrack?.id) return;
|
||||
|
||||
currentNotification?.close();
|
||||
if (state.status !== "Playing") return;
|
||||
const icon = await coverArtPaths.get(state.currentTrack.image);
|
||||
currentNotification = new Notification({
|
||||
title: state.currentTrack.title,
|
||||
body: state.currentTrack.artists.join(", "),
|
||||
icon,
|
||||
});
|
||||
currentNotification.show();
|
||||
});
|
||||
Reference in New Issue
Block a user