mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-08 23:02:05 -04:00
feature: add login sound functionality and settings entry (#2155)
* added login sound functionality and settings entry * Removed debug warning that was accidentally left in * loginSound is off by default, and fixed toggle not working * Prevent login sound from playing in the same session --------- Co-authored-by: Iris <iris@raidev.eu>
This commit is contained in:
@@ -26,6 +26,7 @@ Singleton {
|
||||
property var powerUnplugSound: null
|
||||
property var normalNotificationSound: null
|
||||
property var criticalNotificationSound: null
|
||||
property var loginSound: null
|
||||
property real notificationsVolume: 1.0
|
||||
property bool notificationsAudioMuted: false
|
||||
|
||||
@@ -67,6 +68,16 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
// Used in playLoginSoundIfApplicable()
|
||||
Process {
|
||||
id: loginSoundChecker
|
||||
onExited: (exitCode) => {
|
||||
if (exitCode === 0) {
|
||||
playLoginSound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getAvailableSinks() {
|
||||
const hidden = SessionData.hiddenOutputDeviceNames ?? [];
|
||||
return Pipewire.nodes.values.filter(node => node.audio && node.isSink && !node.isStream && !hidden.includes(node.name));
|
||||
@@ -395,7 +406,7 @@ EOFCONFIG
|
||||
const themesToSearch = themeName !== "freedesktop" ? `${themeName} freedesktop` : themeName;
|
||||
|
||||
const script = `
|
||||
for event_key in audio-volume-change power-plug power-unplug message message-new-instant; do
|
||||
for event_key in audio-volume-change power-plug power-unplug message message-new-instant desktop-login; do
|
||||
found=0
|
||||
|
||||
case "$event_key" in
|
||||
@@ -457,7 +468,8 @@ EOFCONFIG
|
||||
"power-plug": "../assets/sounds/plasma/power-plug.wav",
|
||||
"power-unplug": "../assets/sounds/plasma/power-unplug.wav",
|
||||
"message": "../assets/sounds/freedesktop/message.wav",
|
||||
"message-new-instant": "../assets/sounds/freedesktop/message-new-instant.wav"
|
||||
"message-new-instant": "../assets/sounds/freedesktop/message-new-instant.wav",
|
||||
"desktop-login": "../assets/sounds/freedesktop/desktop-login.wav"
|
||||
};
|
||||
|
||||
const specialConditions = {
|
||||
@@ -551,6 +563,10 @@ EOFCONFIG
|
||||
criticalNotificationSound.destroy();
|
||||
criticalNotificationSound = null;
|
||||
}
|
||||
if (loginSound) {
|
||||
loginSound.destroy();
|
||||
loginSound = null;
|
||||
}
|
||||
}
|
||||
|
||||
function createSoundPlayers() {
|
||||
@@ -622,6 +638,19 @@ EOFCONFIG
|
||||
}
|
||||
}
|
||||
`, root, "AudioService.CriticalNotificationSound");
|
||||
|
||||
const loginPath = getSoundPath("desktop-login");
|
||||
loginSound = Qt.createQmlObject(`
|
||||
import QtQuick
|
||||
import QtMultimedia
|
||||
MediaPlayer {
|
||||
source: "${loginPath}"
|
||||
audioOutput: AudioOutput {
|
||||
${deviceProperty}volume: notificationsVolume
|
||||
}
|
||||
}
|
||||
`, root, "AudioService.LoginSound");
|
||||
|
||||
} catch (e) {
|
||||
console.warn("AudioService: Error creating sound players:", e);
|
||||
}
|
||||
@@ -661,6 +690,31 @@ EOFCONFIG
|
||||
criticalNotificationSound.play();
|
||||
}
|
||||
|
||||
function playLoginSound() {
|
||||
if (!soundsAvailable || !loginSound || notificationsAudioMuted || isMediaPlaying()) {
|
||||
return;
|
||||
}
|
||||
loginSound.play();
|
||||
}
|
||||
|
||||
function playLoginSoundIfApplicable() {
|
||||
if (SettingsData.soundsEnabled && SettingsData.soundLogin && !notificationsAudioMuted) {
|
||||
// plays login sound on session start, but only if a specific file doesn't exist,
|
||||
// to prevent it from playing on every DMS restart during the session
|
||||
const runtimeDir = Quickshell.env("XDG_RUNTIME_DIR");
|
||||
const sessionId = Quickshell.env("XDG_SESSION_ID") || "0";
|
||||
|
||||
if (!runtimeDir) return;
|
||||
|
||||
const loginFile = `${runtimeDir}/danklinux.login-${sessionId}`;
|
||||
|
||||
// if file doesn't exist, touch it (0)
|
||||
// If it exists, do nothing (1)
|
||||
loginSoundChecker.command = ["sh", "-c", `[ ! -f ${loginFile} ] && touch ${loginFile}`];
|
||||
loginSoundChecker.running = true;
|
||||
}
|
||||
}
|
||||
|
||||
function playVolumeChangeSoundIfEnabled() {
|
||||
if (SettingsData.soundsEnabled && SettingsData.soundVolumeChanged && !notificationsAudioMuted) {
|
||||
playVolumeChangeSound();
|
||||
|
||||
Reference in New Issue
Block a user