Sandbox, local pages and DesktopHTMLViewer

Anyone have an updated code working with last version of XOJO and DesktopHTMLViewer.

I cannot display the content from a local website when an app is sandboxed

This code seems to fix it for old versions of Xojo,-Xojo-HTMLViewer-and-App-Sandbox.html

Pretty much everything I want to say would get me kicked off this forum and branded as a Troll, so I’ll show myself out, before it’s too late.


What kind of local website are you talking about ?

I use html files in all my apps to display help, and that includes apps sandboxed to go to the MAS.

Could you post your code ?

I just verified with DesktopHTMLViewer that it works with html files on my hard disk. The app is sandboxed as for the MAS.

Here is my code in a button:

Var f As FolderItem

f = FolderItem.ShowOpenFileDialog("text/html")
If f <> Nil Then
  MessageBox("Open failed.")
End If

The code works when you load a page but if you save the file path and read it from a prefs, the content is not loaded. I’m tried all solutions like adding file:/// . Blank page.

If you always load from Resources, for instance, you can simply save the name of the file instead of the url.

If the path changes, perhaps you can do something like:

var f as folderitem
f = new folderitem(path, folderitem.native)

If the new release is not working, and they broke the workaround, see if you can aply for the 90-day money back guarantee. it is not fair to waste money in something that is not working. See if you can use the old HTMLViewer

This is the code I use for the DesktopHTMLViewer. Just tested in 2022r3.2 and it worked.

Private Sub GrantAccessToFolder(inFolder as FolderItem)
  #if (TargetMacOS) AND (XojoVersion >= 2020.01) then
    // copied from
    // --- Originally created in July 2020. <--- Leave this info here so it's easier to track which version of the code.
    //     Published Sep 1st 2020.
    //     written by Sam Rowlands of
    //     Apple documentation for this API:
    Declare Function NSClassFromString Lib "Foundation" (inClassName As CFStringRef) As Integer
    Declare Function NSURLfileURLWithPathIsDirectory Lib "Foundation" Selector "fileURLWithPath:isDirectory:" (NSURLClass As Integer, path As CFStringRef, directory As Boolean) As Integer
    Declare Function WKWebViewloadFileURL Lib "WebKit" Selector "loadFileURL:allowingReadAccessToURL:" (HTMLViewer As Ptr, URL As Integer, readAccessURL As Integer) As Integer
    // --- Create a NSURL object from a Xojo Folderitem.
    DIM folderURL As Integer = NSURLfileURLWithPathIsDirectory(NSClassFromString("NSURL"), inFolder.NativePath, inFolder.IsFolder)
    // --- This bit is not technically correct. The first parameter after the instance should actually be the page that you're trying to load.
    //     But as we're not loading a page per say... For the purpose of just setting access rights, we ignore the return
    //     value as we don't need to display progress.
    Call WKWebViewloadFileURL(me.Handle, folderURL, folderURL)
End Sub

1 Like

If you use MBS Xojo Plugins, you can go from a DesktopHTMLViewer to a WKWebViewMBS.

And this allows you to use LoadFileURL function:
LoadFileURL(File as FolderItem, readAccessItem as FolderItem)