mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Untested Fix: Memory Leak in Music Player
This commit is contained in:
parent
369e4fc6a2
commit
efb2eaad6a
1 changed files with 17 additions and 0 deletions
|
|
@ -18,6 +18,10 @@ class AudioSpectrum: NSView {
|
||||||
wantsLayer = true
|
wantsLayer = true
|
||||||
setupBars()
|
setupBars()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
animationTimer?.invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
super.init(coder: coder)
|
super.init(coder: coder)
|
||||||
|
|
@ -50,6 +54,15 @@ class AudioSpectrum: NSView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func viewDidMoveToWindow() {
|
||||||
|
super.viewDidMoveToWindow()
|
||||||
|
if window == nil {
|
||||||
|
stopAnimating()
|
||||||
|
} else if isPlaying {
|
||||||
|
startAnimating()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func startAnimating() {
|
private func startAnimating() {
|
||||||
guard animationTimer == nil else { return }
|
guard animationTimer == nil else { return }
|
||||||
animationTimer = Timer.scheduledTimer(withTimeInterval: 0.3, repeats: true) { [weak self] _ in
|
animationTimer = Timer.scheduledTimer(withTimeInterval: 0.3, repeats: true) { [weak self] _ in
|
||||||
|
|
@ -108,6 +121,10 @@ struct AudioSpectrumView: NSViewRepresentable {
|
||||||
func updateNSView(_ nsView: AudioSpectrum, context: Context) {
|
func updateNSView(_ nsView: AudioSpectrum, context: Context) {
|
||||||
nsView.setPlaying(isPlaying)
|
nsView.setPlaying(isPlaying)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static func dismantleNSView(_ nsView: AudioSpectrum, coordinator: ()) {
|
||||||
|
nsView.setPlaying(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue