Giter Club home page Giter Club logo

macos_secure_bookmarks's Introduction

macos_secure_bookmarks

Pub

Flutter plugin to create secure bookmarks to keep access to files in sandboxed apps.

Usage

Creating Security Scoped Bookmarks

// First let the user choose a file, e.g. using the file chooser plugin.

showOpenPanel((result, files) {
  if (result != FileChooserResult.ok || files.isEmpty) {
    return;
  }
  
  // Now create a security scoped bookmark
  final secureBookmarks = SecureBookmarks();
  final bookmark = await secureBookmarks.bookmark(File(_file));
  
  // Now store the bookmark somewhere for later invocations
});

Resolving and accessing bookmarks

// resolve bookmark from persistet 'bookmark' string from earlier
final resolvedFile = await _secureBookmarks.resolveBookmark(_bookmark);
// resolved is now a File object, but before accessing it, call:
await startAccessingSecurityScopedResource(resolvedFile);

// now read/write the file

// and later give up access.
await stopAccessingSecurityScopedResource(resolvedFile);

macos_secure_bookmarks's People

Contributors

hpoul avatar sbhamad avatar sensuikan1973 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

macos_secure_bookmarks's Issues

`await _secureBookmarks.resolveBookmark(bookmark);` should automatically detect the correct `FileSystemEntity` before returning it.

await _secureBookmarks.resolveBookmark(bookmark); should automatically detect the correct FileSystemEntity before returning it.
I don't know if isDirectory needs to be set to true before knowing the particular path represented. (after the resolution)

Also, the fact that isDirectory is optional makes the option hidden for new users.

I think isDirectory should disappear and resolveBookmark need to be smarter during the resolution.

TIMEOUT is wanted in swift code for non-existing file

I'm now working with MacOS app and this package is very helpful to access files outside sandbox environment.

However, once I removed a bookmarked file and try to resolve its bookmark,
resolveBookmark process not ended.

To make matters worse is it cannot be caught by Future.timeout,
perhaps because it runs on Platform side and no signals are sent to Dart side until bookmark resolved.

So I think timeout should be implemented in Swift, and given to Dart as an argument.

I would appreciate it if you could consider.

Confusing error message when using a File that wasn't built from a bookmark.

When you pass in a File that you don't have a bookmark for to startAccessingSecurityScopedResource, the error message says

expected file argument to be string

When the actual problem is that you don't have a bookmark for this file. Since the API allows arbitrary files to be passed in, it would be great if the error message was better for this situation.

I'm not familiar with Swift so I don't really want to fix it myself, but I'm happy to send a PR to update the documentation if you don't want to fix this.

Thanks! Super happy I found this plugin.

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

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)

the readme is not correct

the readme is not correct:

// resolve bookmark from persistet 'bookmark' string from earlier
final resolvedFile = await _secureBookmarks.resolveBookmark(_bookmark);
// resolved is now a File object, but before accessing it, call:
await startAccessingSecurityScopedResource(resolvedFile);

should be:

// resolve bookmark from persistet 'bookmark' string from earlier
final resolvedFile = await _secureBookmarks.resolveBookmark(_bookmark);
// resolved is now a File object, but before accessing it, call:
await _secureBookmarks.startAccessingSecurityScopedResource(resolvedFile);

MissingPluginException when using `flutter test`

MissingPluginException when using flutter test

    return await _secureBookmarks.bookmark(fileSystemEntity);
MissingPluginException (MissingPluginException(No implementation found for method bookmarkData on channel codeux.design/macos_secure_bookmarks))

won't build for macOS with error

Im getting this error when trying to run on macOS, some help would be appreciated

SecureBookmarksPlugin.swift:60:15: error: initializer for conditional binding must
have Optional type, not 'URL'
[        ]         guard let url = try URL(resolvingBookmarkData: bookmark, options: .withSecurityScope, bookmarkDataIsStale: &isStale) else {
[        ]               ^

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.