tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[feat] (macOS) (MAS) Security Scoped Resources via startAccessingSecurityScopedResource

Open stephan-fischer opened this issue 2 years ago • 8 comments

Describe the problem

For macOS it is important to have the functions startAccessingSecurityScopedResource() and stopAccessingSecurityScopedResource(). This is required for apps from the Apple MacStore.

Without it, you can't save folder or file selections in MacOS. This means that when a new file is accessed, a file dialog must be displayed again.

Describe the solution you'd like

The app API has following function

app.startAccessingSecurityScopedResource(bookmarkData)

bookmarkData string - The base64 encoded security scoped bookmark data returned by the dialog.open or dialog.save methods

Returns Function - This function must be called once you have finished accessing the security scoped file. If you do not remember to stop accessing the bookmark, kernel resources will be leaked and your app will lose its ability to reach outside the sandbox completely, until your app is restarted.

// Start accessing the file.
const stopAccessingSecurityScopedResource = app.startAccessingSecurityScopedResource(data)
// You can now access the file outside of the sandbox 🎉

// Remember to stop accessing the file once you've finished with it.
stopAccessingSecurityScopedResource()

Alternatives considered

No response

Additional context

No response

stephan-fischer avatar Mar 17 '22 08:03 stephan-fischer

This is a great finding! Thankyou for the insight.

nothingismagick avatar Mar 17 '22 13:03 nothingismagick

We may want to consider this from an upstream perspective at TAO or WRY though...

nothingismagick avatar Mar 17 '22 13:03 nothingismagick

@nothingismagick for this integration is also good to know if the app is running in the MacOS App Store (MAS). For that you can implement a boolean maybe in process like that:

process.mas // A boolean. For Mac App Store build, this property is true, for other builds it is undefined.

stephan-fischer avatar Mar 19 '22 13:03 stephan-fischer

This is a big must-have for our project. It's also important that dialog.open has an option to create and return security scoped bookmarks, like how it works for Electron's dialog.showOpenDialog.

terreng avatar Oct 22 '22 16:10 terreng

Thanks for the bump. @amrbashir what do you think?

nothingismagick avatar Oct 22 '22 16:10 nothingismagick

Better Mac App Store support is definitely something we should focus ASAP.

lucasfernog avatar Oct 22 '22 17:10 lucasfernog

This remains a critical must-have for any macOS App Store app that asks the user to select files or folders.

terreng avatar Sep 21 '23 21:09 terreng

Any news on this? Are there any changes in Tauri v2?

Andrew-web-coder avatar Feb 13 '24 12:02 Andrew-web-coder