Merge branch 'master' into ios

# Conflicts:
#	QuickDrop.xcodeproj/project.pbxproj
#	QuickDrop/AppDelegate.swift
#	QuickDrop/Localizable.xcstrings
#	ShareExtension/ShareViewController.swift
This commit is contained in:
Leon Böttger committed 2025-08-20 10:28:45 +02:00
commit cf6d45520f
8 files changed
+1572 -4362

No files matched your search

+75 -49
View File
@@ -8,10 +8,8 @@
import Cocoa
import Foundation
import SwiftUI
import QRCode
class ShareViewController: NSViewController, OutboundAppDelegate {
class ShareViewController: NSViewController, ShareExtensionDelegate {
private var urls: [URL] = []
private var textToSend: String? = nil
private var foundDevices: [RemoteDeviceInfo] = []
@@ -48,12 +46,11 @@ class ShareViewController: NSViewController, OutboundAppDelegate {
override func loadView() {
super.loadView()
loadAttachments(with: extensionContext, loadedItems: { result in
log("Loaded attachments: \(result)")
self.urls = result.urls
self.textToSend = result.textToSend
self.filesLabel?.stringValue = result.shortDescription
@@ -96,7 +93,6 @@ class ShareViewController: NSViewController, OutboundAppDelegate {
override func viewDidLoad() {
super.viewDidLoad()
dicoverDevices()
@@ -132,27 +128,7 @@ class ShareViewController: NSViewController, OutboundAppDelegate {
private func openQrCodeView() {
if qrCodeSheetView == nil {
var image: Image? = nil
do {
let qrKey = NearbyConnectionManager.shared.generateQrCodeKey()
let qrCodeImage = try QRCode.build
.text("https://quickshare.google/qrcode#key=\(qrKey)")
.backgroundColor(CGColor(srgbRed: 1, green: 1, blue: 1, alpha: 0))
.quietZonePixelCount(3)
.onPixels.shape(.circle())
.eye.shape(.squircle())
.errorCorrection(.low)
.generate.image(dimension: 1000)
image = Image(nsImage: NSImage(cgImage: qrCodeImage, size: qrCodeImage.size))
}
catch {
log("Error generating QR code: \(error)")
}
let contentView = SmallSheetView(type: .sendToDeviceQrCode, dynamicQrCode: image) {
let contentView = SmallSheetView(type: .sendToDeviceQrCode) {
self.closeQrCodeView()
}
@@ -185,11 +161,71 @@ class ShareViewController: NSViewController, OutboundAppDelegate {
}
func addDevice(device: RemoteDeviceInfo) {
if chosenDevice != nil {
return
private func zipFolderAndSetUpIcon() {
for url in urls {
if url.isFileURL {
let isDirectory = UnsafeMutablePointer<ObjCBool>.allocate(capacity: 1)
if FileManager.default.fileExists(atPath: url.path, isDirectory: isDirectory) && isDirectory.pointee.boolValue {
do {
let zipUrl = try createZipAtTmp(zipFilename: url.lastPathComponent, fromDirectory: url)
let index = urls.firstIndex(of: url)
urls[index!] = zipUrl
} catch {
log("Error creating zip file: \(error)")
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
log("Canceling share request because URL \(url) is a directory")
AudioManager.playErrorSound()
let alert = NSAlert()
alert.alertStyle = .critical
alert.messageText = "TypeNotSupported".localized()
alert.informativeText = "TypeNotSupportedDescription".localized()
alert.addButton(withTitle: "TypeNotSupportedButton".localized())
alert.beginSheetModal(for: self.view.window!) { _ in
let cancelError = NSError(domain: NSCocoaErrorDomain, code: NSUserCancelledError, userInfo: nil)
self.extensionContext!.cancelRequest(withError: cancelError)
}
}
return
}
}
}
}
if let textToSend = textToSend {
let maxLength = 50
let cleanedText = textToSend.replacingOccurrences(of: "\n", with: " ").replacingOccurrences(of: "\r", with: "")
if cleanedText.count > maxLength {
let index = cleanedText.index(cleanedText.startIndex, offsetBy: maxLength)
filesLabel!.stringValue = String(cleanedText[..<index]) + "..."
} else {
filesLabel!.stringValue = cleanedText
}
filesIcon!.image = NSImage(named: NSImage.multipleDocumentsName)
}
else if urls.count == 1 {
if urls[0].isFileURL {
filesLabel!.stringValue = urls[0].lastPathComponent
filesIcon!.image = NSWorkspace.shared.icon(forFile: urls[0].path)
} else if urls[0].scheme == "http" || urls[0].scheme == "https" {
filesLabel!.stringValue = urls[0].absoluteString
filesIcon!.image = NSImage(named: NSImage.networkName)
}
} else {
filesLabel!.stringValue = String.localizedStringWithFormat("NFiles".localized(), urls.count)
filesIcon!.image = NSImage(named: NSImage.multipleDocumentsName)
}
}
func addDevice(device: RemoteDeviceInfo) {
if foundDevices.isEmpty {
loadingOverlay?.animator().isHidden = true
}
@@ -201,7 +237,6 @@ class ShareViewController: NSViewController, OutboundAppDelegate {
func removeDevice(id: String) {
if chosenDevice != nil {
return
}
@@ -218,12 +253,6 @@ class ShareViewController: NSViewController, OutboundAppDelegate {
}
func startTransferWithQrCode(device: RemoteDeviceInfo) {
closeQrCodeView()
selectDevice(device: device)
}
func connectionWasEstablished(pinCode: String) {
connectionEstablished = true
@@ -262,6 +291,7 @@ class ShareViewController: NSViewController, OutboundAppDelegate {
func selectDevice(device: RemoteDeviceInfo) {
NearbyConnectionManager.shared.stopDeviceDiscovery()
listViewWrapper?.animator().isHidden = true
dontSeeDeviceButton?.animator().isHidden = true
@@ -271,7 +301,6 @@ class ShareViewController: NSViewController, OutboundAppDelegate {
progressProgressBar?.startAnimation(nil)
progressState?.stringValue = "Connecting".localized()
chosenDevice = device
NearbyConnectionManager.shared.stopDeviceDiscovery()
NearbyConnectionManager.shared.startOutgoingTransfer(deviceID: device.id!, delegate: self, urls: urls, textToSend: textToSend)
let timeoutAlert = DispatchWorkItem {
@@ -305,7 +334,6 @@ class ShareViewController: NSViewController, OutboundAppDelegate {
private func dicoverDevices() {
let bundleIdentifier = "com.leonboettger.neardrop"
let runningApps = NSWorkspace.shared.runningApplications
@@ -318,13 +346,13 @@ class ShareViewController: NSViewController, OutboundAppDelegate {
let configuration = NSWorkspace.OpenConfiguration()
NSWorkspace.shared.openApplication(at: url, configuration: configuration) { app, error in
if let error = error {
log("Failed to launch application: \(error)")
print("Failed to launch application: \(error)")
} else {
log("Application launched successfully")
print("Application launched successfully")
}
}
} else {
log("Could not find application with bundle identifier \(bundleIdentifier)")
print("Could not find application with bundle identifier \(bundleIdentifier)")
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
@@ -340,7 +368,6 @@ class ShareViewController: NSViewController, OutboundAppDelegate {
private func scheduleAutomaticQrCodeView() {
DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) {
if self.foundDevices.isEmpty {
self.openQrCodeView()
@@ -394,10 +421,9 @@ extension ShareViewController: NSCollectionViewDataSource {
func getDeviceName(device: RemoteDeviceInfo) -> String {
if let name = device.name, name.count > 1 {
return name
if device.name.count <= 1 {
return "Android"
}
return "Android"
return device.name
}
}