From 3e8accaadec5c856ff0488246581ff2bb88e9ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6ttger?= Date: Tue, 11 Mar 2025 07:30:03 +0100 Subject: [PATCH] Fix empty device name --- .../Base.lproj/ShareViewController.xib | 21 ++++++------------- ShareExtension/ShareViewController.swift | 11 ++++++++-- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/ShareExtension/Base.lproj/ShareViewController.xib b/ShareExtension/Base.lproj/ShareViewController.xib index 6856a98..3193b8e 100644 --- a/ShareExtension/Base.lproj/ShareViewController.xib +++ b/ShareExtension/Base.lproj/ShareViewController.xib @@ -109,7 +109,7 @@ Gw - + @@ -130,42 +130,33 @@ Gw - + - + - + - - - - - - - - - + + - - diff --git a/ShareExtension/ShareViewController.swift b/ShareExtension/ShareViewController.swift index b3286e3..2766466 100644 --- a/ShareExtension/ShareViewController.swift +++ b/ShareExtension/ShareViewController.swift @@ -263,7 +263,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate{ NearbyConnectionManager.shared.stopDeviceDiscovery() listViewWrapper?.animator().isHidden=true progressView?.animator().isHidden=false - progressDeviceName?.stringValue=device.name + progressDeviceName?.stringValue=getDeviceName(device: device) progressDeviceIcon?.image=imageForDeviceType(type: device.type) progressProgressBar?.startAnimation(nil) progressState?.stringValue=NSLocalizedString("Connecting", value: "Connecting...", comment: "") @@ -308,7 +308,7 @@ extension ShareViewController:NSCollectionViewDataSource{ let item=collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "DeviceListCell"), for: indexPath) guard let collectionViewItem = item as? DeviceListCell else {return item} let device=foundDevices[indexPath[1]] - collectionViewItem.textField?.stringValue=device.name + collectionViewItem.textField?.stringValue=getDeviceName(device: device) collectionViewItem.imageView?.image=imageForDeviceType(type: device.type) // TODO maybe there's a better way to handle clicks on collection view items? I'm still new to Apple's way of doing UIs so I may do dumb shit occasionally collectionViewItem.clickHandler={ @@ -316,4 +316,11 @@ extension ShareViewController:NSCollectionViewDataSource{ } return collectionViewItem } + + func getDeviceName(device: RemoteDeviceInfo) -> String { + if device.name.count <= 1 { + return "Android" + } + return device.name + } }