diff --git a/WhatCopiedMac/Sources/PasteObserver.swift b/WhatCopiedMac/Sources/PasteObserver.swift index 755360e..b8120aa 100644 --- a/WhatCopiedMac/Sources/PasteObserver.swift +++ b/WhatCopiedMac/Sources/PasteObserver.swift @@ -24,20 +24,12 @@ final class PasteObserver { return } - DispatchQueue.main.async { - let newToken = NSPasteboard.changeToken - guard self.changeToken != newToken else { - return - } - - self.changeToken = newToken - NotificationCenter.default.post(name: .pasteboardChanged, object: nil) - } + DispatchQueue.main.async(execute: checkChangeToken) } self.timer = timer + self.checkChangeToken() RunLoop.current.add(timer, forMode: .common) - NotificationCenter.default.post(name: .pasteboardChanged, object: nil) } func stopObserving() { @@ -53,4 +45,14 @@ final class PasteObserver { private init() { // no-op } + + private func checkChangeToken() { + let newToken = NSPasteboard.changeToken + guard changeToken != newToken else { + return + } + + changeToken = newToken + NotificationCenter.default.post(name: .pasteboardChanged, object: nil) + } }