aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Models
diff options
context:
space:
mode:
Diffstat (limited to 'Hotline/Models')
-rw-r--r--Hotline/Models/Hotline.swift21
-rw-r--r--Hotline/Models/Preferences.swift65
2 files changed, 80 insertions, 6 deletions
diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift
index cccb4d4..f1c745f 100644
--- a/Hotline/Models/Hotline.swift
+++ b/Hotline/Models/Hotline.swift
@@ -647,7 +647,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
@@ -680,7 +682,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()))
}
@@ -717,7 +721,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)
+ }
}
}
@@ -800,8 +806,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 }) {
@@ -822,7 +829,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) }
}