aboutsummaryrefslogtreecommitdiff
path: root/Hotline
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2024-05-01 14:55:19 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2024-05-01 14:55:19 -0700
commit8cb41e9fce82fc8e209348b51c2b79e6cace8e18 (patch)
treea4ed555482280373600a503b2e17e02030d064c7 /Hotline
parent1a82975ad00bced8bba8cd6df6a9920a7ae93c61 (diff)
Add sound settings
Diffstat (limited to 'Hotline')
-rw-r--r--Hotline/Models/Hotline.swift21
-rw-r--r--Hotline/Models/Preferences.swift65
-rw-r--r--Hotline/macOS/SettingsView.swift50
3 files changed, 130 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) }
}
diff --git a/Hotline/macOS/SettingsView.swift b/Hotline/macOS/SettingsView.swift
index 350c70f..e2fc8db 100644
--- a/Hotline/macOS/SettingsView.swift
+++ b/Hotline/macOS/SettingsView.swift
@@ -106,6 +106,51 @@ struct IconSettingsView: View {
}
}
+struct SoundSettingsView: View {
+ @Environment(Prefs.self) private var preferences: Prefs
+
+ var body: some View {
+ @Bindable var preferences = preferences
+ Form {
+ Toggle("Play Sounds for:", isOn: $preferences.playSounds)
+
+ Toggle("Chat", isOn: $preferences.playChatSound)
+ .disabled(!preferences.playSounds)
+ .padding([.leading], 20)
+
+ Toggle("File transfer complete", isOn: $preferences.playFileTransferCompleteSound)
+ .disabled(!preferences.playSounds)
+ .padding([.leading], 20)
+ Toggle("Private Message", isOn: $preferences.playPrivateMessageSound)
+ .disabled(!preferences.playSounds)
+ .padding([.leading], 20)
+
+ Toggle("Join", isOn: $preferences.playJoinSound)
+ .disabled(!preferences.playSounds)
+ .padding([.leading], 20)
+
+ Toggle("Leave", isOn: $preferences.playLeaveSound)
+ .disabled(!preferences.playSounds)
+ .padding([.leading], 20)
+
+ Toggle("Logged in", isOn: $preferences.playLoggedInSound)
+ .disabled(!preferences.playSounds)
+ .padding([.leading], 20)
+
+ Toggle("Error", isOn: $preferences.playErrorSound)
+ .disabled(!preferences.playSounds)
+ .padding([.leading], 20)
+
+ Toggle("Chat Invitation", isOn: $preferences.playChatInvitationSound)
+ .disabled(!preferences.playSounds)
+ .padding([.leading], 20)
+
+ }
+ .padding(20)
+ .frame(width: 350)
+ }
+}
+
struct SettingsView: View {
private enum Tabs: Hashable {
case general, icon
@@ -123,6 +168,11 @@ struct SettingsView: View {
Label("Icon", systemImage: "person")
}
.tag(Tabs.icon)
+ SoundSettingsView()
+ .tabItem {
+ Label("Sound", systemImage: "speaker.wave.3")
+ }
+ .tag(Tabs.icon)
}
}
}