diff --git a/NearbyShare/Logger.swift b/NearbyShare/Logger.swift index d197e37..6d35119 100644 --- a/NearbyShare/Logger.swift +++ b/NearbyShare/Logger.swift @@ -21,6 +21,7 @@ final class LogManager { @Published var loggingEnabled = true + /// Private initializer private init() { // Use the App Group container @@ -36,6 +37,7 @@ final class LogManager { self.logFileURL = directory?.appendingPathComponent(fileName) } + /// Writes a specified string to the log file. func writeToFile(string: String) { guard let logFileURL = logFileURL else { return } @@ -70,6 +72,7 @@ final class LogManager { } } + /// Gets the contents of the log file. func getLogString() -> String { guard let logFileURL = logFileURL else { return "" } @@ -80,7 +83,8 @@ final class LogManager { return "" } } - + + /// Deletes all log files in the shared container. func deleteLogs() { log("[LUI] Deleting all logs...") @@ -104,6 +108,7 @@ final class LogManager { } } + /// Logs a specified string public func log(_ text: String) { let logger = LogManager.sharedInstance @@ -120,6 +125,7 @@ public func log(_ text: String) { } } + /// Returns the shared App Group directory fileprivate func getAppGroupDirectory() -> URL? { let groupIdentifier = "group.com.leonboettger.neardrop" diff --git a/NearbyShare/NearbyConnectionManager.swift b/NearbyShare/NearbyConnectionManager.swift index 7ad08fc..258a0d7 100644 --- a/NearbyShare/NearbyConnectionManager.swift +++ b/NearbyShare/NearbyConnectionManager.swift @@ -25,6 +25,7 @@ public struct RemoteDeviceInfo { type = info.deviceType } + public enum DeviceType: Int32 { case unknown = 0 case phone @@ -48,6 +49,7 @@ public struct RemoteDeviceInfo { } } + public enum NearbyError: Error { case protocolError(_ message: String) case requiredFieldMissing(_ message: String) @@ -76,6 +78,7 @@ public enum NearbyError: Error { } } + public struct TransferMetadata { public let files: [FileMetadata] public let id: String @@ -98,17 +101,20 @@ public struct TransferMetadata { } } + public struct FileMetadata { public let name: String public let size: Int64 public let mimeType: String } + struct FoundServiceInfo { let service: NWBrowser.Result var device: RemoteDeviceInfo? } + struct OutgoingTransferInfo { let service: NWBrowser.Result let device: RemoteDeviceInfo @@ -116,15 +122,18 @@ struct OutgoingTransferInfo { let delegate: ShareExtensionDelegate } + struct EndpointInfo { let name: String let deviceType: RemoteDeviceInfo.DeviceType + init(name: String, deviceType: RemoteDeviceInfo.DeviceType) { self.name = name self.deviceType = deviceType } + init?(data: Data) { guard data.count > 17 else { return nil } let deviceNameLength = Int(data[17]) @@ -135,6 +144,7 @@ struct EndpointInfo { deviceType = RemoteDeviceInfo.DeviceType.fromRawValue(value: rawDeviceType) } + func serialize() -> Data { // 1 byte: Version(3 bits)|Visibility(1 bit)|Device Type(3 bits)|Reserved(1 bits) // Device types: unknown=0, phone=1, tablet=2, laptop=3 @@ -156,6 +166,7 @@ struct EndpointInfo { } } + public protocol MainAppDelegate { func obtainUserConsent(for transfer: TransferMetadata, from device: RemoteDeviceInfo) func incomingTransfer(id: String, didFinishWith error: Error?) @@ -174,6 +185,7 @@ public protocol ShareExtensionDelegate: AnyObject { func transferFinished() } + public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearbyConnectionDelegate, OutboundNearbyConnectionDelegate { public var checkSignature = true { didSet { @@ -199,14 +211,17 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb public static let shared = NearbyConnectionManager() + override init() { tcpListener = try! NWListener(using: NWParameters(tls: .none)) super.init() } - + + public func becomeVisible() { startTCPListener() } + private func startTCPListener() { tcpListener.stateUpdateHandler = { (state: NWListener.State) in @@ -224,6 +239,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb tcpListener.start(queue: .global(qos: .utility)) } + private static func generateEndpointID() -> [UInt8] { let userDefaultsKey = UserDefaultsKeys.endpointID.rawValue @@ -248,6 +264,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb return id } + private func initMDNS() { let nameBytes: [UInt8] = [ 0x23, // PCP @@ -271,17 +288,20 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb } } + func obtainUserConsent(for transfer: TransferMetadata, from device: RemoteDeviceInfo, connection _: InboundNearbyConnection) { guard let delegate = mainAppDelegate else { return } delegate.obtainUserConsent(for: transfer, from: device) } - + + func connectionWasTerminated(connection: InboundNearbyConnection, error: Error?) { guard let delegate = mainAppDelegate else { return } delegate.incomingTransfer(id: connection.id, didFinishWith: error) activeConnections.removeValue(forKey: connection.id) } + public func submitUserConsent(transferID: String, accept: Bool, storeInTemp: Bool = false) { guard let conn = activeConnections[transferID] else { return } @@ -289,6 +309,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb conn.submitUserConsent(accepted: accept, storeInTemp: storeInTemp) } + public func startDeviceDiscovery() { log("Device discovery requested.") @@ -323,6 +344,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb discoveryRefCount += 1 } + public func stopDeviceDiscovery() { discoveryRefCount -= 1 assert(discoveryRefCount >= 0) @@ -336,6 +358,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb } } + public func addShareExtensionDelegate(_ delegate: ShareExtensionDelegate) { shareExtensionDelegates.append(delegate) for service in foundServices.values { @@ -344,15 +367,18 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb } } + public func removeShareExtensionDelegate(_ delegate: ShareExtensionDelegate) { shareExtensionDelegates.removeAll(where: { $0 === delegate }) } + public func cancelOutgoingTransfer(id: String) { guard let transfer = outgoingTransfers[id] else { return } transfer.connection.cancel() } + private func endpointID(for service: NWBrowser.Result) -> String? { guard case let NWEndpoint.service(name: serviceName, type: _, domain: _, interface: _) = service.endpoint else { return nil } guard let nameData = Data.dataFromUrlSafeBase64(serviceName) else { return nil } @@ -365,6 +391,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb return endpointID } + private func addFoundDevice(service: NWBrowser.Result) { log("found service \(service)") for interface in service.interfaces { @@ -394,6 +421,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb } } + private func removeFoundDevice(service: NWBrowser.Result) { guard let endpointID = endpointID(for: service) else { return } guard let _ = foundServices.removeValue(forKey: endpointID) else { return } @@ -402,6 +430,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb } } + public func startOutgoingTransfer(deviceID: String, delegate: ShareExtensionDelegate, urls: [URL], textToSend: String?) { guard let info = foundServices[deviceID] else { return } let tcp = NWProtocolTCP.Options() @@ -414,12 +443,14 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb conn.start() } + func outboundConnectionWasEstablished(connection: OutboundNearbyConnection) { guard let transfer = outgoingTransfers[connection.id] else { return } DispatchQueue.main.async { transfer.delegate.connectionWasEstablished(pinCode: connection.pinCode!) } } + func outboundConnectionTransferAccepted(connection: OutboundNearbyConnection) { guard let transfer = outgoingTransfers[connection.id] else { return } @@ -428,6 +459,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb } } + func outboundConnection(connection: OutboundNearbyConnection, transferProgress: Double) { guard let transfer = outgoingTransfers[connection.id] else { return } DispatchQueue.main.async { @@ -435,6 +467,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb } } + func outboundConnection(connection: OutboundNearbyConnection, failedWithError: Error) { guard let transfer = outgoingTransfers[connection.id] else { return } DispatchQueue.main.async { @@ -442,6 +475,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb } outgoingTransfers.removeValue(forKey: connection.id) } + func outboundConnectionTransferFinished(connection: OutboundNearbyConnection) { guard let transfer = outgoingTransfers[connection.id] else { return } @@ -451,6 +485,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb outgoingTransfers.removeValue(forKey: connection.id) } + public func getActiveConnectionsCount() -> Int { return activeConnections.count } diff --git a/QuickDrop.xcodeproj/project.pbxproj b/QuickDrop.xcodeproj/project.pbxproj index 077fac6..a520209 100644 --- a/QuickDrop.xcodeproj/project.pbxproj +++ b/QuickDrop.xcodeproj/project.pbxproj @@ -45,7 +45,6 @@ EB7CD1472D6FB0E800CB0CB5 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB7CD1442D6FB0C100CB0CB5 /* Logger.swift */; }; EB7F54122D78E96000989564 /* TutorialView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB7F54112D78E95C00989564 /* TutorialView.swift */; }; EB7F54142D78E9E700989564 /* LicenseWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB7F54132D78E9E400989564 /* LicenseWindow.swift */; }; - EB91F0EB2DEDC741006C1867 /* CableConnectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB91F0EA2DEDC73D006C1867 /* CableConnectionView.swift */; }; EB9237C42D7CDF8B00CA3A42 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 69D2C32B29E77F2200EC7E30 /* Localizable.strings */; }; EB9237C52D7CDF9000CA3A42 /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 69D2C33629E78DF400EC7E30 /* Localizable.stringsdict */; }; EB96ED8B2D7F7CF7004B3FF1 /* SmallSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB96ED8A2D7F7CF4004B3FF1 /* SmallSheetView.swift */; }; @@ -214,7 +213,6 @@ EB7CD1442D6FB0C100CB0CB5 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = ""; }; EB7F54112D78E95C00989564 /* TutorialView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TutorialView.swift; sourceTree = ""; }; EB7F54132D78E9E400989564 /* LicenseWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LicenseWindow.swift; sourceTree = ""; }; - EB91F0EA2DEDC73D006C1867 /* CableConnectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CableConnectionView.swift; sourceTree = ""; }; EB9237B52D7CDCE700CA3A42 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/ShareViewController.strings; sourceTree = ""; }; EB9237B72D7CDD7200CA3A42 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/ShareViewController.strings; sourceTree = ""; }; EB9237B92D7CDE3B00CA3A42 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/ShareViewController.strings; sourceTree = ""; }; @@ -345,7 +343,6 @@ EB7F54112D78E95C00989564 /* TutorialView.swift */, EB1A7E422DD4D8BD00A6D5A3 /* SelfTest */, EB7F54132D78E9E400989564 /* LicenseWindow.swift */, - EB91F0EA2DEDC73D006C1867 /* CableConnectionView.swift */, EB6F62D62D91F4AC00534EC2 /* SettingsView.swift */, EB36435F2D73A29F009CDFF8 /* AudioManager.swift */, EB6E743F2DD5CBFB00331466 /* IssueViews */, @@ -598,7 +595,6 @@ files = ( EBD2A2172D2860C100BCB8E2 /* WelcomeScreen.swift in Sources */, EB3643602D73A2A2009CDFF8 /* AudioManager.swift in Sources */, - EB91F0EB2DEDC741006C1867 /* CableConnectionView.swift in Sources */, EBC05C5B2E33937200EECC18 /* ErrorAlertHandler.swift in Sources */, EB96ED8C2D7F7E7B004B3FF1 /* SmallSheetView.swift in Sources */, EB7F54142D78E9E700989564 /* LicenseWindow.swift in Sources */, diff --git a/QuickDrop/CableConnectionView.swift b/QuickDrop/CableConnectionView.swift deleted file mode 100644 index 84ed10f..0000000 --- a/QuickDrop/CableConnectionView.swift +++ /dev/null @@ -1,110 +0,0 @@ -// -// CableConnectionView.swift -// QuickDrop -// -// Created by Leon Böttger on 02.06.25. -// - -//import SwiftUI -// -//struct CableConnectionView: View { -// let closeView: () -> Void -// -// @Environment(\.colorScheme) var colorScheme -// -// var body: some View { -// -// VStack { -// -// HStack { -// -// HStack(spacing: 5) { -// -// let imageSize: CGFloat = advertisesApp ? 20 : 25 -// -// Image(.quickDropIcon) -// .resizable() -// .aspectRatio(contentMode: .fit) -// .frame(width: imageSize, height: imageSize) -// -// if advertisesApp { -// Text("QuickDrop") -// } -// } -// .padding(.leading, 18) -// -// if !advertisesApp { -// Spacer() -// -// HStack { -// Text("ConnectWithQuickDropApp") -// .padding(5) -// .padding(.horizontal, 4) -// .background(Capsule().fill(colorScheme == .light ? .white : .white.opacity(0.15)).opacity(connectWithApp ? 1 : 0)) -// -// Text("ConnectWithoutApp") -// .padding(5) -// .padding(.horizontal, 4) -// .background(Capsule().fill(colorScheme == .light ? .white : .white.opacity(0.15)).opacity(connectWithApp ? 0 : 1)) -// } -// .padding(.horizontal, 1) -// .padding(4) -// .background(Capsule().fill(Color.gray.opacity(colorScheme == .light ? 0.2 : 0.15))) -// .onTapGesture { -// withAnimation { -// connectWithApp.toggle() -// } -// } -// .animation(.smooth, value:connectWithApp) -// } -// -// Spacer() -// -// Button(action: { -// closeView() -// }, label: { -// Image(systemName: "xmark") -// .font(.system(size: 20)) -// .foregroundColor(.gray) -// }) -// .buttonStyle(PlainButtonStyle()) -// } -// .padding(.trailing, 15) -// .padding(.leading, 10) -// .padding(.top, 15) -// .padding(.bottom, advertisesApp ? -10 : 0) -// -// Spacer() -// -// HStack { -// Spacer() -// -// Image(connectWithApp ? .qrApp : .QR) -// .resizable() -// .aspectRatio(1, contentMode: .fit) -// .frame(height: 160) -// -// Spacer() -// -// -// Text(getDescription().localized()) -// .padding(.top, 5) -// .padding(.horizontal) -// .fixedSize(horizontal: false, vertical: true) -// .multilineTextAlignment(.center) -// -// Spacer() -// } -// .padding(.horizontal) -// .padding(.bottom) -// -// Spacer() -// -// } -// .frame(width: qrCodeViewSize.width, height: qrCodeViewSize.height) -// } -//} -// -//#Preview { -// QrCodeView(advertisesApp: false, closeView: {}) -//} diff --git a/QuickDrop/IssueViews/ApIsolationIssueView.swift b/QuickDrop/IssueViews/ApIsolationIssueView.swift index 5787078..b123621 100644 --- a/QuickDrop/IssueViews/ApIsolationIssueView.swift +++ b/QuickDrop/IssueViews/ApIsolationIssueView.swift @@ -10,6 +10,8 @@ import Foundation import AppKit import Network +fileprivate let routerCheckQueue = DispatchQueue(label: "routerCheckQueue") + struct ApIsolationIssueView: View { @Environment(\.colorScheme) var colorScheme @@ -27,6 +29,7 @@ struct ApIsolationIssueView: View { } } + func checkIfApIsolationStillEnabled() { scanner.scan { isConnectionAllowed in if isConnectionAllowed { @@ -48,8 +51,6 @@ struct ApIsolationIssueView: View { } } -fileprivate let routerCheckQueue = DispatchQueue(label: "routerCheckQueue") - func openRouterSettingsPage() async { let routerIP: String? = await withCheckedContinuation { continuation in @@ -77,6 +78,8 @@ func openRouterSettingsPage() async { NSWorkspace.shared.open(url) } } + + /// Attempts to get the default gateway IP address (e.g., 192.168.1.1) /// and ensures it's reachable. Returns nil if unreachable or not found. func getDefaultGatewayIP() -> String? { @@ -98,6 +101,7 @@ func getDefaultGatewayIP() -> String? { return nil } + /// Executes a shell command and returns the output @discardableResult func shell(_ command: String) -> String { @@ -114,6 +118,7 @@ func shell(_ command: String) -> String { return String(data: data, encoding: .utf8) ?? "" } + /// Checks if a host (IP address or hostname) is reachable on port 80 func isHostReachable(_ host: String) -> Bool { let semaphore = DispatchSemaphore(value: 0) @@ -145,7 +150,6 @@ func isHostReachable(_ host: String) -> Bool { } - #Preview { ApIsolationIssueView(closeView: {}) .frame(width: issueViewWidth, height: issueViewHeight) diff --git a/QuickDrop/SettingsView.swift b/QuickDrop/SettingsView.swift index 541a4a8..8e6bade 100644 --- a/QuickDrop/SettingsView.swift +++ b/QuickDrop/SettingsView.swift @@ -10,6 +10,7 @@ import AppKit import NearbyShare struct SettingsView: View { + @AppStorage(UserDefaultsKeys.automaticallyAcceptFiles.rawValue) private var automaticallyAcceptFiles = false @AppStorage(UserDefaultsKeys.openFinderAfterReceiving.rawValue) private var openFinderAfterReceiving = false @AppStorage(UserDefaultsKeys.saveFolderBookmark.rawValue) private var saveFolderPath: Data = Data() @@ -49,6 +50,7 @@ struct SettingsView: View { } } + private func getSavedFolderPath() -> String? { if !saveFolderPath.isEmpty { var isStale = false @@ -62,6 +64,7 @@ struct SettingsView: View { return nil // No saved folder } + private func selectFolder() { let panel = NSOpenPanel() panel.title = "SaveFilesLocation".localized() diff --git a/ShareExtension/ShareViewController.swift b/ShareExtension/ShareViewController.swift index 8b2a805..8eab5d6 100644 --- a/ShareExtension/ShareViewController.swift +++ b/ShareExtension/ShareViewController.swift @@ -40,10 +40,12 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { private var qrCodeSheetView: NSPanel? = nil private var sheetAttachedWindow: NSWindow? = nil + override var nibName: NSNib.Name? { return NSNib.Name("ShareViewController") } + override func loadView() { super.loadView() @@ -116,6 +118,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { progressDeviceIconWrap!.layer!.masksToBounds = false } + override func viewDidLoad() { super.viewDidLoad() @@ -123,6 +126,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { NearbyConnectionManager.shared.addShareExtensionDelegate(self) } + override func viewWillDisappear() { log("ShareViewController: viewWillDisappear") @@ -134,6 +138,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { NearbyConnectionManager.shared.removeShareExtensionDelegate(self) } + @IBAction func cancel(_: AnyObject?) { if let device = chosenDevice { NearbyConnectionManager.shared.cancelOutgoingTransfer(id: device.id!) @@ -142,10 +147,12 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { extensionContext!.cancelRequest(withError: cancelError) } + @IBAction func dontSeeDeviceButton(_: AnyObject?) { openQrCodeView() } + private func openQrCodeView() { if qrCodeSheetView == nil { let contentView = SmallSheetView(type: .sendToDeviceQrCode) { @@ -170,6 +177,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { } } + private func closeQrCodeView() { if let mainWindow = sheetAttachedWindow, let qrCodeView = qrCodeSheetView { mainWindow.endSheet(qrCodeView) @@ -179,6 +187,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { } } + private func zipFolderAndSetUpIcon() { for url in urls { if url.isFileURL { @@ -241,6 +250,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { } } + func addDevice(device: RemoteDeviceInfo) { if foundDevices.isEmpty { loadingOverlay?.animator().isHidden = true @@ -251,6 +261,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { closeQrCodeView() } + func removeDevice(id: String) { if chosenDevice != nil { return @@ -267,6 +278,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { } } + func connectionWasEstablished(pinCode: String) { connectionEstablished = true @@ -276,6 +288,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { progressProgressBar?.doubleValue = 0 } + func connectionFailed(with error: Error) { progressProgressBar?.isIndeterminate = false progressProgressBar?.maxValue = 1000 @@ -293,19 +306,23 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { } } + func transferAccepted() { progressState?.stringValue = "Sending".localized() } + func transferProgress(progress: Double) { progressProgressBar!.doubleValue = progress * progressProgressBar!.maxValue } + func transferFinished() { progressState?.stringValue = "TransferFinished".localized() dismissDelayed() } + func selectDevice(device: RemoteDeviceInfo) { NearbyConnectionManager.shared.stopDeviceDiscovery() @@ -336,6 +353,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { DispatchQueue.main.asyncAfter(deadline: .now() + 10.0, execute: timeoutAlert) } + private func dismissDelayed() { DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { if let error = self.lastError { @@ -346,6 +364,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { } } + private func dicoverDevices() { let bundleIdentifier = "com.leonboettger.neardrop" let runningApps = NSWorkspace.shared.runningApplications @@ -379,6 +398,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { } } + private func scheduleAutomaticQrCodeView() { DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) { if self.foundDevices.isEmpty { @@ -388,6 +408,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate { } } + private func imageForDeviceType(type: RemoteDeviceInfo.DeviceType) -> NSImage { let imageName: String switch type { @@ -401,15 +422,19 @@ private func imageForDeviceType(type: RemoteDeviceInfo.DeviceType) -> NSImage { return NSImage(contentsOfFile: "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/\(imageName).icns")! } + extension ShareViewController: NSCollectionViewDataSource { + func numberOfSections(in _: NSCollectionView) -> Int { return 1 } + func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int { return foundDevices.count } + func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem { let item = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "DeviceListCell"), for: indexPath) @@ -426,6 +451,7 @@ extension ShareViewController: NSCollectionViewDataSource { return collectionViewItem } + func getDeviceName(device: RemoteDeviceInfo) -> String { if device.name.count <= 1 { return "Android" diff --git a/ShareExtension/SmallSheetView.swift b/ShareExtension/SmallSheetView.swift index d9f595d..87bf426 100644 --- a/ShareExtension/SmallSheetView.swift +++ b/ShareExtension/SmallSheetView.swift @@ -147,12 +147,14 @@ struct SmallSheetView: View { } } + enum SheetViewType { case sendToDeviceQrCode case downloadAndroidApp case downloadCableConnectionApp } + #Preview { SmallSheetView(type: .downloadCableConnectionApp, closeView: {}) }