diff options
| author | Dustin Mierau <dustin@mierau.me> | 2024-05-01 21:22:18 -0700 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2024-05-01 21:32:15 -0700 |
| commit | 60a3f2d29dfff945f59787f5a7786c6e78ba7bb9 (patch) | |
| tree | e3d0aa6ae541790ea700353b0ac01fe8b4950f9f /Hotline/Utility | |
| parent | b9529a0d255ad41c62a4e3b93a47ebb5bb82a565 (diff) | |
New Hotline toolbar window for banner.
Diffstat (limited to 'Hotline/Utility')
| -rw-r--r-- | Hotline/Utility/SoundEffects.swift | 25 | ||||
| -rw-r--r-- | Hotline/Utility/VisualEffectView.swift | 27 |
2 files changed, 15 insertions, 37 deletions
diff --git a/Hotline/Utility/SoundEffects.swift b/Hotline/Utility/SoundEffects.swift index 175fa5b..931e27f 100644 --- a/Hotline/Utility/SoundEffects.swift +++ b/Hotline/Utility/SoundEffects.swift @@ -12,7 +12,9 @@ enum SoundEffects: String { @Observable class SoundEffectPlayer: NSObject, AVAudioPlayerDelegate { - var activeSounds: [AVAudioPlayer] = [] + static let shared = SoundEffectPlayer() + + private var activeSounds: [AVAudioPlayer] = [] func playSoundEffect(_ name: SoundEffects) { // Load a local sound file @@ -23,18 +25,21 @@ class SoundEffectPlayer: NSObject, AVAudioPlayerDelegate { return } - do { - let soundEffect = try AVAudioPlayer(contentsOf: soundFileURL) - soundEffect.delegate = self - - self.activeSounds.append(soundEffect) + DispatchQueue.main.async { [weak self] in + guard let self = self else { + return + } - soundEffect.volume = 0.75 - soundEffect.play() + if let soundEffect = try? AVAudioPlayer(contentsOf: soundFileURL) { + soundEffect.delegate = self + soundEffect.volume = 0.75 + soundEffect.play() + + self.activeSounds.append(soundEffect) + } } - catch {} } - + func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) { if let i = self.activeSounds.firstIndex(of: player) { self.activeSounds.remove(at: i) diff --git a/Hotline/Utility/VisualEffectView.swift b/Hotline/Utility/VisualEffectView.swift deleted file mode 100644 index 4f72a6e..0000000 --- a/Hotline/Utility/VisualEffectView.swift +++ /dev/null @@ -1,27 +0,0 @@ -import SwiftUI - -public struct VisualEffectView: NSViewRepresentable { - let material: NSVisualEffectView.Material - let blendingMode: NSVisualEffectView.BlendingMode - - public init( - material: NSVisualEffectView.Material = .contentBackground, - blendingMode: NSVisualEffectView.BlendingMode = .withinWindow - ) { - self.material = material - self.blendingMode = blendingMode - } - - public func makeNSView(context: Context) -> NSVisualEffectView { - let visualEffectView = NSVisualEffectView() - visualEffectView.material = material - visualEffectView.blendingMode = blendingMode - visualEffectView.state = NSVisualEffectView.State.active - return visualEffectView - } - - public func updateNSView(_ visualEffectView: NSVisualEffectView, context: Context) { - visualEffectView.material = material - visualEffectView.blendingMode = blendingMode - } -} |