diff options
| author | Dustin Mierau <dustin@mierau.me> | 2024-05-03 13:04:56 -0700 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2024-05-03 13:04:56 -0700 |
| commit | 5d61fbfd67c3f59bcffa997590d1bc7d41e61528 (patch) | |
| tree | 799877739a5b5c80d8381352897ce3510f71d8d3 /Hotline/Models | |
| parent | 02b452ccaf54cb24eb38fcb752126888994c0a1b (diff) | |
Remember banner toolbar displayed state. Clean up use of preferences throughout project.
Diffstat (limited to 'Hotline/Models')
| -rw-r--r-- | Hotline/Models/Hotline.swift | 8 | ||||
| -rw-r--r-- | Hotline/Models/Preferences.swift | 59 |
2 files changed, 11 insertions, 56 deletions
diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift index beed6a3..564845a 100644 --- a/Hotline/Models/Hotline.swift +++ b/Hotline/Models/Hotline.swift @@ -673,7 +673,7 @@ class Hotline: Equatable, HotlineClientDelegate, HotlineFileClientDelegate { self.deleteAllTransfers() } else if status == .loggedIn { - if Prefs().playSounds && Prefs().playLoggedInSound { + if Prefs.shared.playSounds && Prefs.shared.playLoggedInSound { SoundEffectPlayer.shared.playSoundEffect(.loggedIn) } } @@ -772,7 +772,7 @@ class Hotline: Equatable, HotlineClientDelegate, HotlineFileClientDelegate { let user = self.users.remove(at: existingUserIndex) self.chat.append(ChatMessage(text: "\(user.name) left", type: .status, date: Date())) - if Prefs().playSounds && Prefs().playLeaveSound { + if Prefs.shared.playSounds && Prefs.shared.playLeaveSound { SoundEffectPlayer.shared.playSoundEffect(.userLogout) } } @@ -857,7 +857,7 @@ class Hotline: Equatable, HotlineClientDelegate, HotlineFileClientDelegate { let transfer = self.transfers[i] transfer.fileURL = at transfer.downloadCallback?(transfer, at) - if Prefs().playSounds && Prefs().playFileTransferCompleteSound { + if Prefs.shared.playSounds && Prefs.shared.playFileTransferCompleteSound { SoundEffectPlayer.shared.playSoundEffect(.transferComplete) } } @@ -881,7 +881,7 @@ class Hotline: Equatable, HotlineClientDelegate, HotlineFileClientDelegate { } else { if !self.users.isEmpty { - if Prefs().playSounds && Prefs().playJoinSound { + if Prefs.shared.playSounds && Prefs.shared.playJoinSound { SoundEffectPlayer.shared.playSoundEffect(.userLogin) } } diff --git a/Hotline/Models/Preferences.swift b/Hotline/Models/Preferences.swift index 2266f83..3925bc7 100644 --- a/Hotline/Models/Preferences.swift +++ b/Hotline/Models/Preferences.swift @@ -16,6 +16,7 @@ enum PrefsKeys: String { case playLoggedInSound = "play logged in sound" case playErrorSound = "play error sound" case playChatInvitationSound = "play chat invitation sound" + case showBannerToolbar = "show banner toolbar" } @Observable @@ -37,6 +38,7 @@ class Prefs { PrefsKeys.playLoggedInSound.rawValue: true, PrefsKeys.playErrorSound.rawValue: true, PrefsKeys.playChatInvitationSound.rawValue: true, + PrefsKeys.showBannerToolbar.rawValue: true, ]) self.username = UserDefaults.standard.string(forKey: PrefsKeys.username.rawValue)! @@ -54,6 +56,7 @@ class Prefs { 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) + self.showBannerToolbar = UserDefaults.standard.bool(forKey: PrefsKeys.showBannerToolbar.rawValue) } public static let shared = Prefs() @@ -117,56 +120,8 @@ class Prefs { var automaticMessage: String { didSet { UserDefaults.standard.set(self.automaticMessage, forKey: PrefsKeys.automaticMessage.rawValue) } } + + var showBannerToolbar: Bool { + didSet { UserDefaults.standard.set(self.showBannerToolbar, forKey: PrefsKeys.showBannerToolbar.rawValue) } + } } - -//@Observable -//final class Preferences { -// -// var username: String { -// get { -// access(keyPath: \.username) -// return UserDefaults.standard.object(forKey: "username") as? String ?? "guest" -// } -// set { -// withMutation(keyPath: \.username) { -// UserDefaults.standard.set(newValue, forKey: "username") -// } -// } -// } -// -// var refusePrivateMessages: Bool { -// get { return UserDefaults.standard.object(forKey: "refuse private messages") as? Bool ?? false } -// set { UserDefaults.standard.set(newValue, forKey: "refuse private messages") } -// } -// -// var refusePrivateChat: Bool { -// get { return UserDefaults.standard.object(forKey: "refuse private chat") as? Bool ?? false } -// set { UserDefaults.standard.set(newValue, forKey: "refuse private chat") } -// } -// -// var automaticResponseEnabled: Bool { -// get { return UserDefaults.standard.object(forKey: "enable automatic response") as? Bool ?? false } -// set { UserDefaults.standard.set(newValue, forKey: "enable automatic response") } -// } -// -// var automaticResponse: String { -// get { return UserDefaults.standard.object(forKey: "automatic response") as? String ?? "" } -// set { UserDefaults.standard.set(newValue, forKey: "automatic response") } -// } -// -// var userIconID: Int { -// get { return UserDefaults.standard.object(forKey: "user icon") as? Int ?? 404 } -// set { UserDefaults.standard.set(newValue, forKey: "user icon") } -// } -// -//// @AppStorage("username") public var username: String = "guest" -//// @AppStorage("refuse private messages") public var refusePrivateMessages: Bool = false -//// @AppStorage("refuse private chat") public var refusePrivateChat: Bool = false -//// @AppStorage("enable automatic response") public var enableAutomaticResponse: Bool = false -//// @AppStorage("automatic response") public var automaticResponse: String = "" -//// -//// // Icon -//// @AppStorage("user icon id") public var iconID: Int = 404 -// -// public static let shared = Preferences() -//} |