Fix device not appearing in share extension

This commit is contained in:
Leon Böttger committed 2025-03-12 07:37:29 +01:00
1 parent d399f5f99a
commit 8d8d4036dd
1 file changed
+32 -1
+32 -1
View File
@@ -18,7 +18,10 @@ class ShareViewController: NSViewController, ShareExtensionDelegate{
private var foundDevices:[RemoteDeviceInfo]=[] private var foundDevices:[RemoteDeviceInfo]=[]
private var chosenDevice:RemoteDeviceInfo? private var chosenDevice:RemoteDeviceInfo?
private var lastError:Error? private var lastError:Error?
private var refreshTimer: Timer? = nil
private var isDiscovering=false
@IBOutlet var filesIcon:NSImageView? @IBOutlet var filesIcon:NSImageView?
@IBOutlet var filesLabel:NSTextField? @IBOutlet var filesLabel:NSTextField?
@IBOutlet var loadingOverlay:NSStackView? @IBOutlet var loadingOverlay:NSStackView?
@@ -107,7 +110,30 @@ class ShareViewController: NSViewController, ShareExtensionDelegate{
override func viewDidLoad(){ override func viewDidLoad(){
super.viewDidLoad() super.viewDidLoad()
NearbyConnectionManager.shared.startDeviceDiscovery() NearbyConnectionManager.shared.startDeviceDiscovery()
isDiscovering = true
NearbyConnectionManager.shared.addShareExtensionDelegate(self) NearbyConnectionManager.shared.addShareExtensionDelegate(self)
let refreshInterval = 7.0
refreshTimer = Timer.scheduledTimer(withTimeInterval: refreshInterval, repeats: true, block: { _ in
log("Refreshing device list")
if self.isDiscovering {
NearbyConnectionManager.shared.stopDeviceDiscovery()
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
if self.isDiscovering {
NearbyConnectionManager.shared.startDeviceDiscovery()
}
}
}
})
DispatchQueue.main.asyncAfter(deadline: .now() + refreshInterval) {
self.refreshTimer?.fire()
}
} }
override func viewWillDisappear() { override func viewWillDisappear() {
@@ -116,6 +142,8 @@ class ShareViewController: NSViewController, ShareExtensionDelegate{
if chosenDevice==nil{ if chosenDevice==nil{
NearbyConnectionManager.shared.stopDeviceDiscovery() NearbyConnectionManager.shared.stopDeviceDiscovery()
isDiscovering = false
refreshTimer?.invalidate()
} }
NearbyConnectionManager.shared.removeShareExtensionDelegate(self) NearbyConnectionManager.shared.removeShareExtensionDelegate(self)
} }
@@ -285,6 +313,9 @@ class ShareViewController: NSViewController, ShareExtensionDelegate{
self.qrWindow?.close() self.qrWindow?.close()
NearbyConnectionManager.shared.stopDeviceDiscovery() NearbyConnectionManager.shared.stopDeviceDiscovery()
isDiscovering = false
refreshTimer?.invalidate()
listViewWrapper?.animator().isHidden=true listViewWrapper?.animator().isHidden=true
progressView?.animator().isHidden=false progressView?.animator().isHidden=false
progressDeviceName?.stringValue=getDeviceName(device: device) progressDeviceName?.stringValue=getDeviceName(device: device)