diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-05-01 14:55:19 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-05-01 14:55:19 -0700 |
| commit | 8cb41e9fce82fc8e209348b51c2b79e6cace8e18 (patch) | |
| tree | a4ed555482280373600a503b2e17e02030d064c7 /Hotline/Models | |
| parent | 1a82975ad00bced8bba8cd6df6a9920a7ae93c61 (diff) | |
Add sound settings
Diffstat (limited to 'Hotline/Models')
| -rw-r--r-- | Hotline/Models/Hotline.swift | 21 | ||||
| -rw-r--r-- | Hotline/Models/Preferences.swift | 65 |
2 files changed, 80 insertions, 6 deletions
diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift index 6b5e3a7..1439755 100644 --- a/Hotline/Models/Hotline.swift +++ b/Hotline/Models/Hotline.swift @@ -636,7 +636,9 @@ final class Hotline: HotlineClientDelegate, HotlineFileClientDelegate { self.deleteAllTransfers() } else if status == .loggedIn { - soundEffects.playSoundEffect(.loggedIn) + if Prefs().playSounds && Prefs().playLoggedInSound { + soundEffects.playSoundEffect(.loggedIn) + } } self.status = status @@ -656,7 +658,9 @@ final class Hotline: HotlineClientDelegate, HotlineFileClientDelegate { } func hotlineReceivedChatMessage(message: String) { - soundEffects.playSoundEffect(.chatMessage) + if Prefs().playSounds && Prefs().playChatSound { + soundEffects.playSoundEffect(.chatMessage) + } self.chat.append(ChatMessage(text: message, type: .message, date: Date())) } @@ -693,7 +697,9 @@ final class Hotline: HotlineClientDelegate, HotlineFileClientDelegate { let user = self.users.remove(at: existingUserIndex) self.chat.append(ChatMessage(text: "\(user.name) left", type: .status, date: Date())) - soundEffects.playSoundEffect(.userLogout) + if Prefs().playSounds && Prefs().playLeaveSound { + soundEffects.playSoundEffect(.userLogout) + } } } @@ -776,8 +782,9 @@ final class Hotline: HotlineClientDelegate, HotlineFileClientDelegate { let transfer = self.transfers[i] transfer.fileURL = at transfer.downloadCallback?(transfer, at) - - soundEffects.playSoundEffect(.transferComplete) + if Prefs().playSounds && Prefs().playFileTransferCompleteSound { + soundEffects.playSoundEffect(.transferComplete) + } } if let i = self.downloads.firstIndex(where: { $0.referenceNumber == reference }) { @@ -798,7 +805,9 @@ final class Hotline: HotlineClientDelegate, HotlineFileClientDelegate { } else { if !self.users.isEmpty { - soundEffects.playSoundEffect(.userLogin) + if Prefs().playSounds && Prefs().playJoinSound { + soundEffects.playSoundEffect(.userLogin) + } } print("Hotline: added user: \(user.name)") diff --git a/Hotline/Models/Preferences.swift b/Hotline/Models/Preferences.swift index 350bb0c..2266f83 100644 --- a/Hotline/Models/Preferences.swift +++ b/Hotline/Models/Preferences.swift @@ -7,6 +7,15 @@ enum PrefsKeys: String { case refusePrivateChat = "refuse private chat" case enableAutomaticMessage = "enable automatic message" case automaticMessage = "automatic message" + case playSounds = "play sounds" + case playChatSound = "play chat sound" + case playFileTransferCompleteSound = "play file transfer complete sound" + case playPrivateMessageSound = "play private message sound" + case playJoinSound = "play join sound" + case playLeaveSound = "play leave sound" + case playLoggedInSound = "play logged in sound" + case playErrorSound = "play error sound" + case playChatInvitationSound = "play chat invitation sound" } @Observable @@ -19,6 +28,15 @@ class Prefs { PrefsKeys.refusePrivateChat.rawValue: false, PrefsKeys.enableAutomaticMessage.rawValue: false, PrefsKeys.automaticMessage.rawValue: "", + PrefsKeys.playSounds.rawValue: true, + PrefsKeys.playChatSound.rawValue: true, + PrefsKeys.playFileTransferCompleteSound.rawValue: true, + PrefsKeys.playPrivateMessageSound.rawValue: true, + PrefsKeys.playJoinSound.rawValue: true, + PrefsKeys.playLeaveSound.rawValue: true, + PrefsKeys.playLoggedInSound.rawValue: true, + PrefsKeys.playErrorSound.rawValue: true, + PrefsKeys.playChatInvitationSound.rawValue: true, ]) self.username = UserDefaults.standard.string(forKey: PrefsKeys.username.rawValue)! @@ -27,8 +45,19 @@ class Prefs { self.refusePrivateChat = UserDefaults.standard.bool(forKey: PrefsKeys.refusePrivateChat.rawValue) self.enableAutomaticMessage = UserDefaults.standard.bool(forKey: PrefsKeys.enableAutomaticMessage.rawValue) self.automaticMessage = UserDefaults.standard.string(forKey: PrefsKeys.automaticMessage.rawValue)! + self.playSounds = UserDefaults.standard.bool(forKey: PrefsKeys.playSounds.rawValue) + self.playChatSound = UserDefaults.standard.bool(forKey: PrefsKeys.playChatSound.rawValue) + self.playFileTransferCompleteSound = UserDefaults.standard.bool(forKey: PrefsKeys.playFileTransferCompleteSound.rawValue) + self.playPrivateMessageSound = UserDefaults.standard.bool(forKey: PrefsKeys.playPrivateMessageSound.rawValue) + self.playJoinSound = UserDefaults.standard.bool(forKey: PrefsKeys.playJoinSound.rawValue) + self.playLeaveSound = UserDefaults.standard.bool(forKey: PrefsKeys.playLeaveSound.rawValue) + self.playLoggedInSound = UserDefaults.standard.bool(forKey: PrefsKeys.playLoggedInSound.rawValue) + self.playErrorSound = UserDefaults.standard.bool(forKey: PrefsKeys.playErrorSound.rawValue) + self.playChatInvitationSound = UserDefaults.standard.bool(forKey: PrefsKeys.playChatInvitationSound.rawValue) } + public static let shared = Prefs() + var username: String { didSet { UserDefaults.standard.set(self.username, forKey: PrefsKeys.username.rawValue) } } @@ -41,6 +70,42 @@ class Prefs { didSet { UserDefaults.standard.set(self.refusePrivateMessages, forKey: PrefsKeys.refusePrivateMessages.rawValue) } } + var playSounds: Bool { + didSet { UserDefaults.standard.set(self.playSounds, forKey: PrefsKeys.playSounds.rawValue) } + } + + var playChatSound: Bool { + didSet { UserDefaults.standard.set(self.playChatSound, forKey: PrefsKeys.playChatSound.rawValue) } + } + + var playFileTransferCompleteSound: Bool { + didSet { UserDefaults.standard.set(self.playFileTransferCompleteSound, forKey: PrefsKeys.playFileTransferCompleteSound.rawValue) } + } + + var playPrivateMessageSound: Bool { + didSet { UserDefaults.standard.set(self.playPrivateMessageSound, forKey: PrefsKeys.playPrivateMessageSound.rawValue) } + } + + var playJoinSound: Bool { + didSet { UserDefaults.standard.set(self.playJoinSound, forKey: PrefsKeys.playJoinSound.rawValue) } + } + + var playLeaveSound: Bool { + didSet { UserDefaults.standard.set(self.playLeaveSound, forKey: PrefsKeys.playLeaveSound.rawValue) } + } + + var playLoggedInSound: Bool { + didSet { UserDefaults.standard.set(self.playLoggedInSound, forKey: PrefsKeys.playLoggedInSound.rawValue) } + } + + var playErrorSound: Bool { + didSet { UserDefaults.standard.set(self.playErrorSound, forKey: PrefsKeys.playErrorSound.rawValue) } + } + + var playChatInvitationSound: Bool { + didSet { UserDefaults.standard.set(self.playChatInvitationSound, forKey: PrefsKeys.playChatInvitationSound.rawValue) } + } + var refusePrivateChat: Bool { didSet { UserDefaults.standard.set(self.refusePrivateChat, forKey: PrefsKeys.refusePrivateChat.rawValue) } } |