diff --git a/Sources/CyanUI/PopupButton/PopupButton.swift b/Sources/CyanUI/PopupButton/PopupButton.swift index d001947..9ab61f2 100644 --- a/Sources/CyanUI/PopupButton/PopupButton.swift +++ b/Sources/CyanUI/PopupButton/PopupButton.swift @@ -159,8 +159,10 @@ class _PopupButtonTriggerView: NSView where S: StringProtocol { } deinit { - if let localMonitor = localMonitor, let globalMonitor = globalMonitor { + if let localMonitor = localMonitor { NSEvent.removeMonitor(localMonitor) + } + if let globalMonitor = globalMonitor { NSEvent.removeMonitor(globalMonitor) } } diff --git a/Sources/CyanUI/PopupButton/PopupList.swift b/Sources/CyanUI/PopupButton/PopupList.swift index bf3b7fd..eee7951 100644 --- a/Sources/CyanUI/PopupButton/PopupList.swift +++ b/Sources/CyanUI/PopupButton/PopupList.swift @@ -21,6 +21,8 @@ struct _PopupList: View where Content: StringProtocol { init(contents: [Content], selection: Binding, mouseUpEventPublisher: AnyPublisher) { _selection = selection self.mouseUpEventPublisher = mouseUpEventPublisher + + // TODO: Optimize the handling of duplicated items. self.contents = contents.enumerated().filter { index, element in contents.firstIndex(of: element) == index }.map { $0.element } diff --git a/Sources/CyanUI/VisualEffectView.swift b/Sources/CyanUI/VisualEffectView.swift index ce3adc6..b8aba2b 100644 --- a/Sources/CyanUI/VisualEffectView.swift +++ b/Sources/CyanUI/VisualEffectView.swift @@ -22,14 +22,12 @@ public struct VisualEffectView: NSViewRepresentable { self.blendingMode = blendingMode } - public func makeNSView(context: Context) -> NSVisualEffectView { - let effectView = NSVisualEffectView() - effectView.state = state - effectView.blendingMode = blendingMode - effectView.material = material - return effectView - } + public func makeNSView(context: Context) -> NSVisualEffectView { .init() } - public func updateNSView(_ nsView: NSVisualEffectView, context: Context) { } + public func updateNSView(_ nsView: NSVisualEffectView, context: Context) { + nsView.state = state + nsView.blendingMode = blendingMode + nsView.material = material + } } diff --git a/Sources/CyanUtils/WeakWrapper.swift b/Sources/CyanUtils/WeakPropertyWrapper.swift similarity index 54% rename from Sources/CyanUtils/WeakWrapper.swift rename to Sources/CyanUtils/WeakPropertyWrapper.swift index 8d72899..bee9f32 100644 --- a/Sources/CyanUtils/WeakWrapper.swift +++ b/Sources/CyanUtils/WeakPropertyWrapper.swift @@ -7,15 +7,10 @@ import Foundation @propertyWrapper public class Weak where T: AnyObject { - private weak var _wrappedValue: T? - - public var wrappedValue: T? { - get { _wrappedValue } - set { _wrappedValue = newValue } - } + public weak var wrappedValue: T? public init(wrappedValue: T?) { - _wrappedValue = wrappedValue + self.wrappedValue = wrappedValue } }