mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-21 13:55:58 +00:00
FIx warning
This commit is contained in:
1 parent
04b5b4228b
commit
f3f6616280
5 files changed
+86
-78
No files matched your search
Binary file not shown.
Binary file not shown.
@@ -825,8 +825,8 @@
|
|||||||
MTL_FAST_MATH = YES;
|
MTL_FAST_MATH = YES;
|
||||||
ONLY_ACTIVE_ARCH = YES;
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
SDKROOT = macosx;
|
SDKROOT = macosx;
|
||||||
SHARED_BUILD = 40;
|
SHARED_BUILD = 41;
|
||||||
SHARED_VERSION = 1.9.1;
|
SHARED_VERSION = 1.9.2;
|
||||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
};
|
};
|
||||||
@@ -884,8 +884,8 @@
|
|||||||
MTL_ENABLE_DEBUG_INFO = NO;
|
MTL_ENABLE_DEBUG_INFO = NO;
|
||||||
MTL_FAST_MATH = YES;
|
MTL_FAST_MATH = YES;
|
||||||
SDKROOT = macosx;
|
SDKROOT = macosx;
|
||||||
SHARED_BUILD = 40;
|
SHARED_BUILD = 41;
|
||||||
SHARED_VERSION = 1.9.1;
|
SHARED_VERSION = 1.9.2;
|
||||||
SWIFT_COMPILATION_MODE = wholemodule;
|
SWIFT_COMPILATION_MODE = wholemodule;
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-O";
|
SWIFT_OPTIMIZATION_LEVEL = "-O";
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,10 +16,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 connectionEstablished = false
|
private var connectionEstablished = false
|
||||||
private var timeoutDispatchWorkItem: DispatchWorkItem? = nil
|
private var timeoutDispatchWorkItem: DispatchWorkItem? = nil
|
||||||
|
|
||||||
@IBOutlet var filesIcon: NSImageView?
|
@IBOutlet var filesIcon: NSImageView?
|
||||||
@IBOutlet var filesLabel: NSTextField?
|
@IBOutlet var filesLabel: NSTextField?
|
||||||
@IBOutlet var loadingOverlay: NSStackView?
|
@IBOutlet var loadingOverlay: NSStackView?
|
||||||
@@ -35,22 +35,22 @@ class ShareViewController: NSViewController, ShareExtensionDelegate {
|
|||||||
@IBOutlet var progressDeviceIconWrap: NSView?
|
@IBOutlet var progressDeviceIconWrap: NSView?
|
||||||
@IBOutlet var progressDeviceSecondaryIcon: NSImageView?
|
@IBOutlet var progressDeviceSecondaryIcon: NSImageView?
|
||||||
@IBOutlet var dontSeeDeviceButton: NSButton?
|
@IBOutlet var dontSeeDeviceButton: NSButton?
|
||||||
|
|
||||||
private var qrCodeSheetView: NSPanel? = nil
|
private var qrCodeSheetView: NSPanel? = nil
|
||||||
private var sheetAttachedWindow: NSWindow? = nil
|
private var sheetAttachedWindow: NSWindow? = nil
|
||||||
|
|
||||||
override var nibName: NSNib.Name? {
|
override var nibName: NSNib.Name? {
|
||||||
return NSNib.Name("ShareViewController")
|
return NSNib.Name("ShareViewController")
|
||||||
}
|
}
|
||||||
|
|
||||||
override func loadView() {
|
override func loadView() {
|
||||||
super.loadView()
|
super.loadView()
|
||||||
|
|
||||||
let item = extensionContext!.inputItems[0] as! NSExtensionItem
|
let item = extensionContext!.inputItems[0] as! NSExtensionItem
|
||||||
if let attachments = item.attachments {
|
if let attachments = item.attachments {
|
||||||
if let text = item.attributedContentText?.string, attachments.isEmpty {
|
if let text = item.attributedContentText?.string, attachments.isEmpty {
|
||||||
textToSend = text
|
textToSend = text
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.zipFolderAndSetUpIcon()
|
self.zipFolderAndSetUpIcon()
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate {
|
|||||||
} else if let url = data as? NSURL {
|
} else if let url = data as? NSURL {
|
||||||
self.urls.append(url as URL)
|
self.urls.append(url as URL)
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.urls.count == attachments.count {
|
if self.urls.count == attachments.count {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.zipFolderAndSetUpIcon()
|
self.zipFolderAndSetUpIcon()
|
||||||
@@ -80,29 +80,29 @@ class ShareViewController: NSViewController, ShareExtensionDelegate {
|
|||||||
extensionContext!.cancelRequest(withError: cancelError)
|
extensionContext!.cancelRequest(withError: cancelError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
contentWrap!.addSubview(listViewWrapper!)
|
contentWrap!.addSubview(listViewWrapper!)
|
||||||
contentWrap!.addSubview(loadingOverlay!)
|
contentWrap!.addSubview(loadingOverlay!)
|
||||||
contentWrap!.addSubview(progressView!)
|
contentWrap!.addSubview(progressView!)
|
||||||
progressView!.isHidden = true
|
progressView!.isHidden = true
|
||||||
|
|
||||||
listViewWrapper!.translatesAutoresizingMaskIntoConstraints = false
|
listViewWrapper!.translatesAutoresizingMaskIntoConstraints = false
|
||||||
loadingOverlay!.translatesAutoresizingMaskIntoConstraints = false
|
loadingOverlay!.translatesAutoresizingMaskIntoConstraints = false
|
||||||
progressView!.translatesAutoresizingMaskIntoConstraints = false
|
progressView!.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
NSLayoutConstraint(item: listViewWrapper!, attribute: .width, relatedBy: .equal, toItem: contentWrap, attribute: .width, multiplier: 1, constant: 0),
|
NSLayoutConstraint(item: listViewWrapper!, attribute: .width, relatedBy: .equal, toItem: contentWrap, attribute: .width, multiplier: 1, constant: 0),
|
||||||
NSLayoutConstraint(item: listViewWrapper!, attribute: .height, relatedBy: .equal, toItem: contentWrap, attribute: .height, multiplier: 1, constant: 0),
|
NSLayoutConstraint(item: listViewWrapper!, attribute: .height, relatedBy: .equal, toItem: contentWrap, attribute: .height, multiplier: 1, constant: 0),
|
||||||
|
|
||||||
NSLayoutConstraint(item: loadingOverlay!, attribute: .width, relatedBy: .equal, toItem: contentWrap, attribute: .width, multiplier: 1, constant: 0),
|
NSLayoutConstraint(item: loadingOverlay!, attribute: .width, relatedBy: .equal, toItem: contentWrap, attribute: .width, multiplier: 1, constant: 0),
|
||||||
NSLayoutConstraint(item: loadingOverlay!, attribute: .centerY, relatedBy: .equal, toItem: contentWrap, attribute: .centerY, multiplier: 1, constant: 0),
|
NSLayoutConstraint(item: loadingOverlay!, attribute: .centerY, relatedBy: .equal, toItem: contentWrap, attribute: .centerY, multiplier: 1, constant: 0),
|
||||||
|
|
||||||
NSLayoutConstraint(item: progressView!, attribute: .width, relatedBy: .equal, toItem: contentWrap, attribute: .width, multiplier: 1, constant: 0),
|
NSLayoutConstraint(item: progressView!, attribute: .width, relatedBy: .equal, toItem: contentWrap, attribute: .width, multiplier: 1, constant: 0),
|
||||||
NSLayoutConstraint(item: progressView!, attribute: .centerY, relatedBy: .equal, toItem: contentWrap, attribute: .centerY, multiplier: 1, constant: 0),
|
NSLayoutConstraint(item: progressView!, attribute: .centerY, relatedBy: .equal, toItem: contentWrap, attribute: .centerY, multiplier: 1, constant: 0),
|
||||||
])
|
])
|
||||||
|
|
||||||
largeProgress!.startAnimation(nil)
|
largeProgress!.startAnimation(nil)
|
||||||
|
|
||||||
let flowLayout = NSCollectionViewFlowLayout()
|
let flowLayout = NSCollectionViewFlowLayout()
|
||||||
flowLayout.itemSize = NSSize(width: 75, height: 90)
|
flowLayout.itemSize = NSSize(width: 75, height: 90)
|
||||||
flowLayout.sectionInset = NSEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
|
flowLayout.sectionInset = NSEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
|
||||||
@@ -110,29 +110,29 @@ class ShareViewController: NSViewController, ShareExtensionDelegate {
|
|||||||
flowLayout.minimumLineSpacing = 10
|
flowLayout.minimumLineSpacing = 10
|
||||||
listView!.collectionViewLayout = flowLayout
|
listView!.collectionViewLayout = flowLayout
|
||||||
listView!.dataSource = self
|
listView!.dataSource = self
|
||||||
|
|
||||||
progressDeviceIconWrap!.wantsLayer = true
|
progressDeviceIconWrap!.wantsLayer = true
|
||||||
progressDeviceIconWrap!.layer!.masksToBounds = false
|
progressDeviceIconWrap!.layer!.masksToBounds = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
dicoverDevices()
|
dicoverDevices()
|
||||||
NearbyConnectionManager.shared.addShareExtensionDelegate(self)
|
NearbyConnectionManager.shared.addShareExtensionDelegate(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillDisappear() {
|
override func viewWillDisappear() {
|
||||||
log("ShareViewController: viewWillDisappear")
|
log("ShareViewController: viewWillDisappear")
|
||||||
|
|
||||||
timeoutDispatchWorkItem?.cancel()
|
timeoutDispatchWorkItem?.cancel()
|
||||||
|
|
||||||
if chosenDevice == nil {
|
if chosenDevice == nil {
|
||||||
NearbyConnectionManager.shared.stopDeviceDiscovery()
|
NearbyConnectionManager.shared.stopDeviceDiscovery()
|
||||||
}
|
}
|
||||||
NearbyConnectionManager.shared.removeShareExtensionDelegate(self)
|
NearbyConnectionManager.shared.removeShareExtensionDelegate(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func cancel(_: AnyObject?) {
|
@IBAction func cancel(_: AnyObject?) {
|
||||||
if let device = chosenDevice {
|
if let device = chosenDevice {
|
||||||
NearbyConnectionManager.shared.cancelOutgoingTransfer(id: device.id!)
|
NearbyConnectionManager.shared.cancelOutgoingTransfer(id: device.id!)
|
||||||
@@ -140,44 +140,44 @@ class ShareViewController: NSViewController, ShareExtensionDelegate {
|
|||||||
let cancelError = NSError(domain: NSCocoaErrorDomain, code: NSUserCancelledError, userInfo: nil)
|
let cancelError = NSError(domain: NSCocoaErrorDomain, code: NSUserCancelledError, userInfo: nil)
|
||||||
extensionContext!.cancelRequest(withError: cancelError)
|
extensionContext!.cancelRequest(withError: cancelError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func dontSeeDeviceButton(_: AnyObject?) {
|
@IBAction func dontSeeDeviceButton(_: AnyObject?) {
|
||||||
openQrCodeView()
|
openQrCodeView()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func openQrCodeView() {
|
private func openQrCodeView() {
|
||||||
if qrCodeSheetView == nil {
|
if qrCodeSheetView == nil {
|
||||||
let contentView = QrCodeView {
|
let contentView = QrCodeView {
|
||||||
self.closeQrCodeView()
|
self.closeQrCodeView()
|
||||||
}
|
}
|
||||||
|
|
||||||
let hostingView = NSHostingView(rootView: contentView)
|
let hostingView = NSHostingView(rootView: contentView)
|
||||||
|
|
||||||
let panel = NSPanel(contentRect: NSRect(x: 0, y: 0, width: qrCodeViewSize.width, height: qrCodeViewSize.height),
|
let panel = NSPanel(contentRect: NSRect(x: 0, y: 0, width: qrCodeViewSize.width, height: qrCodeViewSize.height),
|
||||||
styleMask: [.titled, .closable, .utilityWindow],
|
styleMask: [.titled, .closable, .utilityWindow],
|
||||||
backing: .buffered,
|
backing: .buffered,
|
||||||
defer: false)
|
defer: false)
|
||||||
|
|
||||||
panel.contentView = hostingView
|
panel.contentView = hostingView
|
||||||
|
|
||||||
qrCodeSheetView = panel
|
qrCodeSheetView = panel
|
||||||
|
|
||||||
if let mainWindow = NSApp.mainWindow {
|
if let mainWindow = NSApp.mainWindow {
|
||||||
sheetAttachedWindow = mainWindow
|
sheetAttachedWindow = mainWindow
|
||||||
mainWindow.beginSheet(panel) { _ in }
|
mainWindow.beginSheet(panel) { _ in }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func closeQrCodeView() {
|
private func closeQrCodeView() {
|
||||||
if let mainWindow = sheetAttachedWindow, let qrCodeView = qrCodeSheetView {
|
if let mainWindow = sheetAttachedWindow, let qrCodeView = qrCodeSheetView {
|
||||||
mainWindow.endSheet(qrCodeView)
|
mainWindow.endSheet(qrCodeView)
|
||||||
|
|
||||||
qrCodeSheetView = nil
|
qrCodeSheetView = nil
|
||||||
sheetAttachedWindow = nil
|
sheetAttachedWindow = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func zipFolderAndSetUpIcon() {
|
private func zipFolderAndSetUpIcon() {
|
||||||
for url in urls {
|
for url in urls {
|
||||||
if url.isFileURL {
|
if url.isFileURL {
|
||||||
@@ -185,38 +185,38 @@ class ShareViewController: NSViewController, ShareExtensionDelegate {
|
|||||||
if FileManager.default.fileExists(atPath: url.path, isDirectory: isDirectory) && isDirectory.pointee.boolValue {
|
if FileManager.default.fileExists(atPath: url.path, isDirectory: isDirectory) && isDirectory.pointee.boolValue {
|
||||||
do {
|
do {
|
||||||
let zipUrl = try createZipAtTmp(zipFilename: url.lastPathComponent, fromDirectory: url)
|
let zipUrl = try createZipAtTmp(zipFilename: url.lastPathComponent, fromDirectory: url)
|
||||||
|
|
||||||
let index = urls.firstIndex(of: url)
|
let index = urls.firstIndex(of: url)
|
||||||
urls[index!] = zipUrl
|
urls[index!] = zipUrl
|
||||||
} catch {
|
} catch {
|
||||||
log("Error creating zip file: \(error)")
|
log("Error creating zip file: \(error)")
|
||||||
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||||
log("Canceling share request because URL \(url) is a directory")
|
log("Canceling share request because URL \(url) is a directory")
|
||||||
|
|
||||||
let alert = NSAlert()
|
let alert = NSAlert()
|
||||||
alert.alertStyle = .critical
|
alert.alertStyle = .critical
|
||||||
|
|
||||||
alert.messageText = "TypeNotSupported".localized()
|
alert.messageText = "TypeNotSupported".localized()
|
||||||
alert.informativeText = "TypeNotSupportedDescription".localized()
|
alert.informativeText = "TypeNotSupportedDescription".localized()
|
||||||
alert.addButton(withTitle: "TypeNotSupportedButton".localized())
|
alert.addButton(withTitle: "TypeNotSupportedButton".localized())
|
||||||
|
|
||||||
alert.beginSheetModal(for: self.view.window!) { _ in
|
alert.beginSheetModal(for: self.view.window!) { _ in
|
||||||
let cancelError = NSError(domain: NSCocoaErrorDomain, code: NSUserCancelledError, userInfo: nil)
|
let cancelError = NSError(domain: NSCocoaErrorDomain, code: NSUserCancelledError, userInfo: nil)
|
||||||
self.extensionContext!.cancelRequest(withError: cancelError)
|
self.extensionContext!.cancelRequest(withError: cancelError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let textToSend = textToSend {
|
if let textToSend = textToSend {
|
||||||
let maxLength = 50
|
let maxLength = 50
|
||||||
let cleanedText = textToSend.replacingOccurrences(of: "\n", with: " ").replacingOccurrences(of: "\r", with: "")
|
let cleanedText = textToSend.replacingOccurrences(of: "\n", with: " ").replacingOccurrences(of: "\r", with: "")
|
||||||
|
|
||||||
if cleanedText.count > maxLength {
|
if cleanedText.count > maxLength {
|
||||||
let index = cleanedText.index(cleanedText.startIndex, offsetBy: maxLength)
|
let index = cleanedText.index(cleanedText.startIndex, offsetBy: maxLength)
|
||||||
filesLabel!.stringValue = String(cleanedText[..<index]) + "..."
|
filesLabel!.stringValue = String(cleanedText[..<index]) + "..."
|
||||||
@@ -239,17 +239,17 @@ class ShareViewController: NSViewController, ShareExtensionDelegate {
|
|||||||
filesIcon!.image = NSImage(named: NSImage.multipleDocumentsName)
|
filesIcon!.image = NSImage(named: NSImage.multipleDocumentsName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addDevice(device: RemoteDeviceInfo) {
|
func addDevice(device: RemoteDeviceInfo) {
|
||||||
if foundDevices.isEmpty {
|
if foundDevices.isEmpty {
|
||||||
loadingOverlay?.animator().isHidden = true
|
loadingOverlay?.animator().isHidden = true
|
||||||
}
|
}
|
||||||
foundDevices.append(device)
|
foundDevices.append(device)
|
||||||
listView?.animator().insertItems(at: [[0, foundDevices.count - 1]])
|
listView?.animator().insertItems(at: [[0, foundDevices.count - 1]])
|
||||||
|
|
||||||
closeQrCodeView()
|
closeQrCodeView()
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeDevice(id: String) {
|
func removeDevice(id: String) {
|
||||||
if chosenDevice != nil {
|
if chosenDevice != nil {
|
||||||
return
|
return
|
||||||
@@ -265,22 +265,22 @@ class ShareViewController: NSViewController, ShareExtensionDelegate {
|
|||||||
loadingOverlay?.animator().isHidden = false
|
loadingOverlay?.animator().isHidden = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectionWasEstablished(pinCode: String) {
|
func connectionWasEstablished(pinCode: String) {
|
||||||
connectionEstablished = true
|
connectionEstablished = true
|
||||||
|
|
||||||
progressState?.stringValue = String(format: NSLocalizedString("PinCode", value: "PIN: %@", comment: ""), arguments: [pinCode])
|
progressState?.stringValue = String(format: NSLocalizedString("PinCode", value: "PIN: %@", comment: ""), arguments: [pinCode])
|
||||||
progressProgressBar?.isIndeterminate = false
|
progressProgressBar?.isIndeterminate = false
|
||||||
progressProgressBar?.maxValue = 1000
|
progressProgressBar?.maxValue = 1000
|
||||||
progressProgressBar?.doubleValue = 0
|
progressProgressBar?.doubleValue = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectionFailed(with error: Error) {
|
func connectionFailed(with error: Error) {
|
||||||
progressProgressBar?.isIndeterminate = false
|
progressProgressBar?.isIndeterminate = false
|
||||||
progressProgressBar?.maxValue = 1000
|
progressProgressBar?.maxValue = 1000
|
||||||
progressProgressBar?.doubleValue = 0
|
progressProgressBar?.doubleValue = 0
|
||||||
lastError = error
|
lastError = error
|
||||||
|
|
||||||
if let ne = (error as? NearbyError), case let .canceled(reason) = ne {
|
if let ne = (error as? NearbyError), case let .canceled(reason) = ne {
|
||||||
switch reason {
|
switch reason {
|
||||||
case .userRejected:
|
case .userRejected:
|
||||||
@@ -298,29 +298,29 @@ class ShareViewController: NSViewController, ShareExtensionDelegate {
|
|||||||
dismissDelayed()
|
dismissDelayed()
|
||||||
} else {
|
} else {
|
||||||
let alert = NSAlert(error: error)
|
let alert = NSAlert(error: error)
|
||||||
|
|
||||||
alert.beginSheetModal(for: view.window!) { _ in
|
alert.beginSheetModal(for: view.window!) { _ in
|
||||||
self.extensionContext!.cancelRequest(withError: error)
|
self.extensionContext!.cancelRequest(withError: error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func transferAccepted() {
|
func transferAccepted() {
|
||||||
progressState?.stringValue = NSLocalizedString("Sending", value: "Sending...", comment: "")
|
progressState?.stringValue = NSLocalizedString("Sending", value: "Sending...", comment: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func transferProgress(progress: Double) {
|
func transferProgress(progress: Double) {
|
||||||
progressProgressBar!.doubleValue = progress * progressProgressBar!.maxValue
|
progressProgressBar!.doubleValue = progress * progressProgressBar!.maxValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func transferFinished() {
|
func transferFinished() {
|
||||||
progressState?.stringValue = NSLocalizedString("TransferFinished", value: "Transfer finished", comment: "")
|
progressState?.stringValue = NSLocalizedString("TransferFinished", value: "Transfer finished", comment: "")
|
||||||
dismissDelayed()
|
dismissDelayed()
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectDevice(device: RemoteDeviceInfo) {
|
func selectDevice(device: RemoteDeviceInfo) {
|
||||||
NearbyConnectionManager.shared.stopDeviceDiscovery()
|
NearbyConnectionManager.shared.stopDeviceDiscovery()
|
||||||
|
|
||||||
listViewWrapper?.animator().isHidden = true
|
listViewWrapper?.animator().isHidden = true
|
||||||
dontSeeDeviceButton?.animator().isHidden = true
|
dontSeeDeviceButton?.animator().isHidden = true
|
||||||
progressView?.animator().isHidden = false
|
progressView?.animator().isHidden = false
|
||||||
@@ -330,24 +330,24 @@ class ShareViewController: NSViewController, ShareExtensionDelegate {
|
|||||||
progressState?.stringValue = NSLocalizedString("Connecting", value: "Connecting...", comment: "")
|
progressState?.stringValue = NSLocalizedString("Connecting", value: "Connecting...", comment: "")
|
||||||
chosenDevice = device
|
chosenDevice = device
|
||||||
NearbyConnectionManager.shared.startOutgoingTransfer(deviceID: device.id!, delegate: self, urls: urls, textToSend: textToSend)
|
NearbyConnectionManager.shared.startOutgoingTransfer(deviceID: device.id!, delegate: self, urls: urls, textToSend: textToSend)
|
||||||
|
|
||||||
let timeoutAlert = DispatchWorkItem {
|
let timeoutAlert = DispatchWorkItem {
|
||||||
if !self.connectionEstablished {
|
if !self.connectionEstablished {
|
||||||
let alert = NSAlert()
|
let alert = NSAlert()
|
||||||
alert.alertStyle = .critical
|
alert.alertStyle = .critical
|
||||||
|
|
||||||
alert.messageText = "TimeoutTitle".localized()
|
alert.messageText = "TimeoutTitle".localized()
|
||||||
alert.informativeText = "TimeoutDescription".localized()
|
alert.informativeText = "TimeoutDescription".localized()
|
||||||
alert.addButton(withTitle: "TimeoutButton".localized())
|
alert.addButton(withTitle: "TimeoutButton".localized())
|
||||||
|
|
||||||
alert.beginSheetModal(for: self.view.window!) { _ in }
|
alert.beginSheetModal(for: self.view.window!) { _ in }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
timeoutDispatchWorkItem = timeoutAlert
|
timeoutDispatchWorkItem = timeoutAlert
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 10.0, execute: timeoutAlert)
|
DispatchQueue.main.asyncAfter(deadline: .now() + 10.0, execute: timeoutAlert)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func dismissDelayed() {
|
private func dismissDelayed() {
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
|
||||||
if let error = self.lastError {
|
if let error = self.lastError {
|
||||||
@@ -357,21 +357,29 @@ class ShareViewController: NSViewController, ShareExtensionDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func dicoverDevices() {
|
private func dicoverDevices() {
|
||||||
let bundleIdentifier = "com.leonboettger.neardrop"
|
let bundleIdentifier = "com.leonboettger.neardrop"
|
||||||
let runningApps = NSWorkspace.shared.runningApplications
|
let runningApps = NSWorkspace.shared.runningApplications
|
||||||
|
|
||||||
// Check if the app is already running
|
// Check if the app is already running
|
||||||
let isRunning = runningApps.contains { $0.bundleIdentifier == bundleIdentifier }
|
let isRunning = runningApps.contains { $0.bundleIdentifier == bundleIdentifier }
|
||||||
|
|
||||||
if !isRunning {
|
if !isRunning {
|
||||||
log("Launching main app")
|
log("Launching main app")
|
||||||
NSWorkspace.shared.launchApplication(withBundleIdentifier: bundleIdentifier,
|
if let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleIdentifier) {
|
||||||
options: [.default],
|
let configuration = NSWorkspace.OpenConfiguration()
|
||||||
additionalEventParamDescriptor: nil,
|
NSWorkspace.shared.openApplication(at: url, configuration: configuration) { app, error in
|
||||||
launchIdentifier: nil)
|
if let error = error {
|
||||||
|
print("Failed to launch application: \(error)")
|
||||||
|
} else {
|
||||||
|
print("Application launched successfully")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("Could not find application with bundle identifier \(bundleIdentifier)")
|
||||||
|
}
|
||||||
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||||
NearbyConnectionManager.shared.startDeviceDiscovery()
|
NearbyConnectionManager.shared.startDeviceDiscovery()
|
||||||
self.scheduleAutomaticQrCodeView()
|
self.scheduleAutomaticQrCodeView()
|
||||||
@@ -382,7 +390,7 @@ class ShareViewController: NSViewController, ShareExtensionDelegate {
|
|||||||
scheduleAutomaticQrCodeView()
|
scheduleAutomaticQrCodeView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func scheduleAutomaticQrCodeView() {
|
private func scheduleAutomaticQrCodeView() {
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) {
|
||||||
if self.foundDevices.isEmpty {
|
if self.foundDevices.isEmpty {
|
||||||
@@ -409,27 +417,27 @@ extension ShareViewController: NSCollectionViewDataSource {
|
|||||||
func numberOfSections(in _: NSCollectionView) -> Int {
|
func numberOfSections(in _: NSCollectionView) -> Int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int {
|
func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int {
|
||||||
return foundDevices.count
|
return foundDevices.count
|
||||||
}
|
}
|
||||||
|
|
||||||
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
|
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
|
||||||
let item = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "DeviceListCell"), for: indexPath)
|
let item = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "DeviceListCell"), for: indexPath)
|
||||||
|
|
||||||
guard let collectionViewItem = item as? DeviceListCell else { return item }
|
guard let collectionViewItem = item as? DeviceListCell else { return item }
|
||||||
|
|
||||||
let device = foundDevices[indexPath[1]]
|
let device = foundDevices[indexPath[1]]
|
||||||
|
|
||||||
collectionViewItem.textField?.stringValue = getDeviceName(device: device)
|
collectionViewItem.textField?.stringValue = getDeviceName(device: device)
|
||||||
collectionViewItem.imageView?.image = imageForDeviceType(type: device.type)
|
collectionViewItem.imageView?.image = imageForDeviceType(type: device.type)
|
||||||
collectionViewItem.clickHandler = {
|
collectionViewItem.clickHandler = {
|
||||||
self.selectDevice(device: device)
|
self.selectDevice(device: device)
|
||||||
}
|
}
|
||||||
|
|
||||||
return collectionViewItem
|
return collectionViewItem
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDeviceName(device: RemoteDeviceInfo) -> String {
|
func getDeviceName(device: RemoteDeviceInfo) -> String {
|
||||||
if device.name.count <= 1 {
|
if device.name.count <= 1 {
|
||||||
return "Android"
|
return "Android"
|
||||||
|
|||||||
Reference in new issue
Block a user