Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[SOLVED] error when invoking start and stop a resource access #6

Closed
sbhamad opened this issue Dec 30, 2021 · 4 comments
Closed

[SOLVED] error when invoking start and stop a resource access #6

sbhamad opened this issue Dec 30, 2021 · 4 comments

Comments

@sbhamad
Copy link
Contributor

sbhamad commented Dec 30, 2021

Thanks for this great plugin. I however get an error whenever i invoke (start or stop) resource access methods prior to using the resource.

i successfully get a bookmark, and i am certain that the file i pass to the

await _secureBookmarksInstance.startAccessingSecurityScopedResource(file);

method is not null.

i also made sure to add the following entitlements to both debug and release .entitlements

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.security.app-sandbox</key>
	<true/>
	<key>com.apple.security.cs.allow-jit</key>
	<true/>
	<key>com.apple.security.network.server</key>
	<true/>
	<key>com.apple.security.network.client</key>
	<true/>
	<key>com.apple.security.files.bookmarks.app-scope</key>
	<true/>
	<key>com.apple.security.device.usb</key>
	<true/>

</dict>
</plist>

the error is:

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(InvalidArguments, expected file argument to be string., null, null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)

#2 SecureBookmarks.startAccessingSecurityScopedResource (package:macos_secure_bookmarks/macos_secure_bookmarks.dart:39:12)

#3 _MyHomePageState._requestAccessToDirectory (package:cc_macos/main.dart:177:5)

@hpoul
Copy link
Collaborator

hpoul commented Dec 30, 2021

Are you passing in the file object or the bookmark id as string?

@sbhamad
Copy link
Contributor Author

sbhamad commented Dec 30, 2021

as the method signature requires a File object, then i am passing a File object to the

await _secureBookmarksInstance.startAccessingSecurityScopedResource(file);

method, which in turn, by looking at its implementation code, derives the path from the file File object with file.absolute.path.

even if i wanted to pass the bookmark, i couldn't because of the method signature.

  /// Allows you to access the given file. (which was previously stored
  /// as security aware bookmark).
  /// You should call [stopAccessingSecurityScopedResource] afterwards.
  Future<bool> startAccessingSecurityScopedResource(File file) async {
    return await _channel.invokeMethod(
        'startAccessingSecurityScopedResource', {'file': file.absolute.path});
  }

maybe the problem is on the native side? because the method of obtaining a bookmark, which is identical in signature, successfully returns the bookmark String when i pass it THE SAME file File object.

look at the bookmark method having an identical signature:

  /// Create a security aware bookmark for the given [file].
  Future<String> bookmark(File file) async {
    return await _channel
        .invokeMethod('bookmarkData', {'file': file.absolute.path});
  }

@hpoul
Copy link
Collaborator

hpoul commented Dec 30, 2021

Okay the error message is pretty bogus.. it has been a long time since i last looked at it 🤷‍♂️
Can you paste your whole code you use.. also the whole log including the native debug output, there are a few print statements which should be visible in the log output

@sbhamad sbhamad changed the title error when invoking start and stop a resource access [SOLVED] error when invoking start and stop a resource access Dec 30, 2021
@sbhamad
Copy link
Contributor Author

sbhamad commented Dec 30, 2021

Turns out, you must resolve the bookmark first to obtain the file object, then you must pass that same resolved file object to the:

  /// Allows you to access the given file. (which was previously stored
  /// as security aware bookmark).
  /// You should call [stopAccessingSecurityScopedResource] afterwards.
  Future<bool> startAccessingSecurityScopedResource(File file) async {
    return await _channel.invokeMethod(
        'startAccessingSecurityScopedResource', {'file': file.absolute.path});
  }

I also think we should update the method signature to accept a FileSystemEntity object instead of a File object:

  Future<bool> startAccessingSecurityScopedResource(FileSystemEntity file) async {
    return await _channel.invokeMethod(
        'startAccessingSecurityScopedResource', {'file': file.absolute.path});
  }

This enables passing both Directory and File objects. It works for me, i modified the signature locally and it works since the underlying invoked method is only interested in the absolute path of the FileSystemEntity object.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants