98 lines
2.3 KiB
JavaScript
Executable File
98 lines
2.3 KiB
JavaScript
Executable File
const { Notification } = require('electron');
|
|
const { getSettings } = require('./settings.js');
|
|
|
|
function safe(str, fallback = 'Unknown') {
|
|
return (typeof str === 'string' && str.trim()) ? str.trim() : fallback;
|
|
}
|
|
|
|
function allowed(type) {
|
|
const s = getSettings();
|
|
if (!s.notificationsEnabled) return false;
|
|
return s.notificationTypes?.[type] !== false;
|
|
}
|
|
|
|
function showNowPlaying(title, artist) {
|
|
if (!allowed('nowPlaying')) return;
|
|
new Notification({
|
|
title: 'Now Playing',
|
|
body: `Song: ${safe(title)}\nArtist: ${safe(artist)}`,
|
|
silent: false
|
|
}).show();
|
|
}
|
|
|
|
function showPaused(title, artist) {
|
|
if (!allowed('paused')) return;
|
|
new Notification({
|
|
title: 'Paused',
|
|
body: `Song: ${safe(title)}\nArtist: ${safe(artist)}`,
|
|
silent: false
|
|
}).show();
|
|
}
|
|
|
|
function showLiked(title, artist) {
|
|
if (!allowed('liked')) return;
|
|
new Notification({
|
|
title: 'Liked Song',
|
|
body: `Song: ${safe(title)}\nArtist: ${safe(artist)}`,
|
|
silent: false
|
|
}).show();
|
|
}
|
|
|
|
function showUnliked(title, artist) {
|
|
if (!allowed('unliked')) return;
|
|
new Notification({
|
|
title: 'Unliked Song',
|
|
body: `Song: ${safe(title)}\nArtist: ${safe(artist)}`,
|
|
silent: false
|
|
}).show();
|
|
}
|
|
|
|
function showVerificationRequired() {
|
|
if (!allowed('verificationRequired')) return;
|
|
new Notification({
|
|
title: 'CrossSound — Verification Required',
|
|
body: 'SoundCloud is being a little fucking bitch again. Go verify so it can stop complaining...',
|
|
urgent: true,
|
|
silent: false
|
|
}).show();
|
|
}
|
|
|
|
function showTorStarted() {
|
|
if (!allowed('torStarted')) return;
|
|
new Notification({
|
|
title: 'Tor Started',
|
|
body: 'Tor is running. Traffic is now routed through the Tor network.',
|
|
silent: false
|
|
}).show();
|
|
}
|
|
|
|
function showTorStopped() {
|
|
if (!allowed('torStopped')) return;
|
|
new Notification({
|
|
title: 'Tor Stopped',
|
|
body: 'Tor has been stopped. Traffic is no longer routed through Tor.',
|
|
silent: false
|
|
}).show();
|
|
}
|
|
|
|
function showTorCrashed() {
|
|
if (!allowed('torCrashed')) return;
|
|
new Notification({
|
|
title: 'Tor Crashed',
|
|
body: 'Tor exited unexpectedly. The Tor toggle has been disabled.',
|
|
urgent: true,
|
|
silent: false
|
|
}).show();
|
|
}
|
|
|
|
module.exports = {
|
|
showNowPlaying,
|
|
showPaused,
|
|
showLiked,
|
|
showUnliked,
|
|
showVerificationRequired,
|
|
showTorStarted,
|
|
showTorStopped,
|
|
showTorCrashed,
|
|
};
|