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

This commit is contained in:
Shlomo
2024-09-09 16:38:52 +03:00
committed by GitHub
parent fc810d1598
commit ab52d6e1cd
6 changed files with 16 additions and 19 deletions
+4 -6
View File
@@ -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]
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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/>
+1 -1
View File
@@ -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/>
+8 -9
View File
@@ -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
}
}
@@ -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/>