Skip to content

Commit

Permalink
Merge branch 'feat-notifications' into v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
duzda committed Aug 17, 2024
2 parents 60ba6a3 + f52ba4c commit 8656d24
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/common/types/settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface Settings {
enableTray: boolean;
closeToTray: boolean;
enableNotifications: boolean;
deemixIntegration: boolean;
volumePower: number;
discordRPC: boolean;
Expand All @@ -9,6 +10,7 @@ export interface Settings {
export const DEFAULT_SETTINGS: Settings = {
enableTray: false,
closeToTray: false,
enableNotifications: false,
deemixIntegration: false,
volumePower: 4,
discordRPC: false,
Expand All @@ -17,6 +19,7 @@ export const DEFAULT_SETTINGS: Settings = {
export type SettingsProperties =
| 'enableTray'
| 'closeToTray'
| 'enableNotifications'
| 'deemixIntegration'
| 'volumePower'
| 'discordRPC';
Expand All @@ -26,6 +29,7 @@ type Setter<T> = (newValue: T) => void | undefined;
export type Setters = {
enableTray: Setter<boolean>;
closeToTray: Setter<boolean>;
enableNotifications: Setter<boolean>;
deemixIntegration: Setter<boolean>;
volumePower: Setter<number>;
discordRPC: Setter<boolean>;
Expand Down
33 changes: 32 additions & 1 deletion src/main/mpris.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-param-reassign */
import Player from 'mpris-service';
import { Episode, Song } from 'src/common/types/deezer';
import { BrowserView, ipcMain } from 'electron';
import { BrowserView, ipcMain, Notification } from 'electron';
import {
MPRIS_NEXT_SONG,
MPRIS_PAUSE,
Expand All @@ -23,9 +23,13 @@ import {
import {
DEEZER_ART_RESOLUTION,
DEEZER_EPISODE_ART_URL,
DEEZER_NOTIFICATION_RESOLUTION,
DEEZER_SONG_ART_URL,
} from './utils/urls';
import { isDiscordEnabled, setDiscordActivity } from './discord';
import { getSettings } from './settings';

let songId = '';

let songStart = 0;
let songOffset = 0;
Expand Down Expand Up @@ -122,6 +126,18 @@ const createMprisListeners = (player: Player) => {
player.getPosition() / 1_000
);
}

if (getSettings().enableNotifications && songData.SNG_ID !== songId) {
new Notification({
title: songData.SNG_TITLE,
body: songData.ART_NAME,
icon:
DEEZER_SONG_ART_URL +
songData.ALB_PICTURE +
DEEZER_NOTIFICATION_RESOLUTION,
}).show();
songId = songData.SNG_ID;
}
} else if (data.EPISODE_ID) {
const episodeData = data as Episode;
updateMetadataEpisode(player, episodeData);
Expand All @@ -138,6 +154,21 @@ const createMprisListeners = (player: Player) => {
player.getPosition() / 1_000
);
}

if (
getSettings().enableNotifications &&
episodeData.EPISODE_ID !== songId
) {
new Notification({
title: episodeData.EPISODE_TITLE,
body: episodeData.SHOW_NAME,
icon:
DEEZER_SONG_ART_URL +
episodeData.SHOW_ART_MD5 +
DEEZER_NOTIFICATION_RESOLUTION,
}).show();
songId = episodeData.EPISODE_ID;
}
}
});
ipcMain.on(MPRIS_READ_POSITION, (_, position) => {
Expand Down
2 changes: 2 additions & 0 deletions src/main/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const loadFromFile = async (file: string) => {

OnSet.enableTray(currentSettings.enableTray);
OnSet.closeToTray(currentSettings.closeToTray);
OnSet.enableNotifications(currentSettings.enableNotifications);
OnSet.deemixIntegration(currentSettings.deemixIntegration);
OnSet.volumePower(currentSettings.volumePower);
OnSet.discordRPC(currentSettings.discordRPC);
Expand Down Expand Up @@ -95,6 +96,7 @@ export const initializeSettings = async (
}
},
closeToTray: () => {},
enableNotifications: () => {},
deemixIntegration: () => {},
volumePower: () => {},
discordRPC: (enabled) => {
Expand Down
1 change: 1 addition & 0 deletions src/main/utils/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export const DEEZER_SONG_ART_URL =
export const DEEZER_EPISODE_ART_URL =
'https://e-cdns-images.dzcdn.net/images/talk/';
export const DEEZER_ART_RESOLUTION = '/512x512-000000-80-0-0.jpg';
export const DEEZER_NOTIFICATION_RESOLUTION = '/64x64-000000-80-0-0.jpg';
12 changes: 12 additions & 0 deletions src/renderer/components/Settings/SettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ function SettingsForm(): React.JSX.Element {
setCurrentSettings({ ...currentSettings, closeToTray: newValue });
}}
/>
<Switch
id="enable-notifications"
state={currentSettings.enableNotifications}
text="Enable notifications on song change"
onChange={(newValue) => {
setValue('enableNotifications', newValue);
setCurrentSettings({
...currentSettings,
enableNotifications: newValue,
});
}}
/>
<Switch
id="deemix-integration"
state={currentSettings.deemixIntegration}
Expand Down
2 changes: 2 additions & 0 deletions src/view/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { setVolumePower } from './injections/volume';
const OnSet: Setters = {
enableTray: () => {},
closeToTray: () => {},
enableNotifications: () => {},
deemixIntegration: () => {},
volumePower: (newValue: number) => setVolumePower(newValue),
discordRPC: () => {},
Expand All @@ -14,6 +15,7 @@ export const initializeSettings = async () => {

OnSet.enableTray(settings.enableTray);
OnSet.closeToTray(settings.closeToTray);
OnSet.enableNotifications(settings.enableNotifications);
OnSet.deemixIntegration(settings.deemixIntegration);
OnSet.volumePower(settings.volumePower);
OnSet.discordRPC(settings.discordRPC);
Expand Down

0 comments on commit 8656d24

Please sign in to comment.