Skip to content

An open-source cross-platform alternative to AirDrop

fix(macos): files dragged to the menu bar item was handled as text (#1757)

Shlomoab52d6e1cd03
diff --git a/app/macos/Runner/AppDelegate.swift b/app/macos/Runner/AppDelegate.swift
index 7dee4158..5676adb9 100644
--- a/app/macos/Runner/AppDelegate.swift
+++ b/app/macos/Runner/AppDelegate.swift
@@ -17,7 +17,7 @@ class AppDelegate: FlutterAppDelegate {
override func applicationDidFinishLaunching(_ notification: Notification) {
let controller = mainFlutterWindow?.contentViewController as! FlutterViewController
channel = FlutterMethodChannel(name: "main-delegate-channel", binaryMessenger: controller.engine.binaryMessenger)
- channel?.setMethodCallHandler(handle)
+ channel?.setMethodCallHandler(handleFlutterCall)
self.setupPendingItemsObservation()
@@ -26,14 +26,12 @@ class AppDelegate: FlutterAppDelegate {
private func setupPendingItemsObservation() {
self.pendingFilesObservation = Defaults.observe(.pendingFiles) { change in
- let pendingFileBookmarks = Defaults[.pendingFiles]
- guard !pendingFileBookmarks.isEmpty else { return }
+ guard !Defaults[.pendingFiles].isEmpty else { return }
self.sendPendingItemsToFlutter()
}
self.pendingStringsObservation = Defaults.observe(.pendingStrings) { change in
- let pendingStrings = Defaults[.pendingStrings]
- guard !pendingStrings.isEmpty else { return }
+ guard !Defaults[.pendingStrings].isEmpty else { return }
self.sendPendingItemsToFlutter()
}
}
@@ -115,7 +113,7 @@ class AppDelegate: FlutterAppDelegate {
}
// START: handle opened files
- private func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
+ private func handleFlutterCall(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
switch call.method {
case "getPendingFiles":
let pendingFileBookmarks = Defaults[.pendingFiles]
diff --git a/app/macos/Runner/ContentDropView.swift b/app/macos/Runner/ContentDropView.swift
index 152a0ec3..075c2c3b 100644
--- a/app/macos/Runner/ContentDropView.swift
+++ b/app/macos/Runner/ContentDropView.swift
@@ -38,7 +38,7 @@ class ContentDropView: NSView {
// Web URLs and text
if let items = pasteboard.readObjects(forClasses: [NSURL.self, NSString.self], options: nil) {
let strings = items.compactMap { item -> String? in
- if let url = item as? URL {
+ if let url = item as? URL, !url.isFileURL {
return url.absoluteString
} else if let string = item as? String {
return string
diff --git a/app/macos/Runner/DebugProfile.entitlements b/app/macos/Runner/DebugProfile.entitlements
index 66485d8a..3c83f71b 100644
--- a/app/macos/Runner/DebugProfile.entitlements
+++ b/app/macos/Runner/DebugProfile.entitlements
@@ -6,7 +6,7 @@
<true/>
<key>com.apple.security.application-groups</key>
<array>
- <string>com.localsend.shared_group</string>
+ <string>org.localsend.shared_group</string>
</array>
<key>com.apple.security.cs.allow-jit</key>
<true/>
diff --git a/app/macos/Runner/Release.entitlements b/app/macos/Runner/Release.entitlements
index 32c32845..8b9bacbe 100644
--- a/app/macos/Runner/Release.entitlements
+++ b/app/macos/Runner/Release.entitlements
@@ -6,7 +6,7 @@
<true/>
<key>com.apple.security.application-groups</key>
<array>
- <string>com.localsend.shared_group</string>
+ <string>org.localsend.shared_group</string>
</array>
<key>com.apple.security.files.downloads.read-write</key>
<true/>
diff --git a/app/macos/Runner/Shared.swift b/app/macos/Runner/Shared.swift
index b7f91463..895dc8cb 100644
--- a/app/macos/Runner/Shared.swift
+++ b/app/macos/Runner/Shared.swift
@@ -1,7 +1,7 @@
import Foundation
import Defaults
-let sharedDefaults = UserDefaults(suiteName: "com.localsend.shared_group")!
+let sharedDefaults = UserDefaults(suiteName: "org.localsend.shared_group")!
typealias FileBookmarkData = Data
extension Defaults.Keys {
@@ -13,28 +13,27 @@ extension Defaults.Keys {
Creates a minimal bookmark for a given file URL.
That allows the main app to access the file as a "User Selected File" later. Otherwise, the file will be successfully selected but an attempt to send it (that is, actually read it) will fail.
-
- - Important: We intentionally avoid creating a security-scoped bookmark (`.withSecurityScope` option) here, as security-scoped bookmarks cannot be transferred between apps or app extensions.
+
+ - Important: We intentionally avoid creating a security-scoped bookmark (`.withSecurityScope` option) here, as security-scoped bookmarks cannot be transferred between apps or app extensions.
- See:
- - [Open Radar: Security scoped bookmarks don't work with app groups](https://openradar.appspot.com/43055392)
- - [Reply from Apple DTS in Apple Developer Forums: Share security scoped bookmark in app group? (Alternative Answer)](https://developer.apple.com/forums/thread/66259?answerId=336402022#336402022)
- - [Detailed instructions in Apple Developer Forums: Share security scoped bookmark in app group? (Alternative Answer)](https://developer.apple.com/forums/thread/66259?answerId=278355022#278355022)
-
- - Note: The main app and the sharing plugin must have
- The same level of "User Selected File" permission (Read Only or Read/Write)
+
+ - Note: The main app and the sharing plugin must have
+ The same level of "User Selected File" permission (Read Only or Read/Write)
- Tag: create-bookmark-func
*/
func createBookmarkForFile(at url: URL) -> FileBookmarkData? {
do {
- let securityScopedBookmark = try (url as NSURL).bookmarkData(
+ return try (url as NSURL).bookmarkData(
options: .minimalBookmark,
includingResourceValuesForKeys: nil,
relativeTo: nil
)
- return securityScopedBookmark
} catch {
- print("Failed to create security-scoped bookmark for \(url): \(error)")
+ print("Failed to create bookmark for \(url): \(error)")
return nil
}
}
diff --git a/app/macos/ShareExtension/ShareExtension.entitlements b/app/macos/ShareExtension/ShareExtension.entitlements
index 4acd7515..bc6a2cc7 100644
--- a/app/macos/ShareExtension/ShareExtension.entitlements
+++ b/app/macos/ShareExtension/ShareExtension.entitlements
@@ -6,7 +6,7 @@
<true/>
<key>com.apple.security.application-groups</key>
<array>
- <string>com.localsend.shared_group</string>
+ <string>org.localsend.shared_group</string>
</array>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>