This is a new one, I use this project with this code since… I started my MBP m1 last year. This specific code have not been changed recently and was working some days ago.
Xojo 2022r4.1 (and earlier) / Ventura 13.2
The error Message (and reason, same string) is: The BaseFile parametThe BaseFile parameter to LoadPage must be an existing file, not folder.
This is against what the LR said (both are valmid arg).
But, I do not care, I passed a file instead of a folder to get the same result.
I System.DebugLog the passed FolderItem (Data_FI) (NativePath) to be sure of what it Reference and, yes, I get the folder path or the file path…
What have I done (as of this night):
→ Close the project and Quit Xojo,
→ Clear the Cache folder contents,
→ Reboot,
→ Disk Utils (internal SSD, no external nor cloud, SMB anything)
→ Power Off the laptop,
→ Boot, fire Xojo (as the only application), load and run the project to get the same Exception.
I saved the html generated code from this Desktop application and load it with Safari without trouble.
Now, here we are: I cannot render the html code anymore…
For unknow reasons, the HTMLviewer does not show the images, while the manually saved html (loaded in Firefox) shows them (even Quick Look Finder’s display them !).
There are 2 possible issues with local images. Trying to show them stored in places in relative paths (even if declared as an absolute path) needing going backwards the root RelativeTo file, or… for macs, needs some entitlement to gain such loading access.
That’s why I was asking @Emile_Schwarz where they are stored. If they are local, you need to call a method to get permission (on macOS) to do so. This method, which uses Declares, was kindly provided to me by @Sam_Rowlands so he would need to authorise my passing it on.
The solution is to save html to a subfolder of specialfolder.applicationdata, and to copy the pictures there as well. Then instead of using LoadPage, use LoadURL.
Thank you all for your answers. I left internet soon after my last message (above).
In the heart of the night, I fired Xojo 15r1 and checked my files on my i5 mbp (check for file/folder privileges). It worked fine (excepted the project version was old…).
Minutes ago, and with fresh look, I fired Xojo 2021r2.1 and checked my code. In fact, I commented what worked without images yesterday, and tried to implement a different code until I realized where the code lies.
This seems to be an error (some may say a bug) I’ve done. Sometimes the brain (like computer) fall into error mode…
My project is now back at work. What I do not understand is how I could mis-match two variables… And I do that yesterday (I’ve made a fast check with a yesterday early morning version). May the France strike do something here ?
BTW: the code shared in the LR works fine for an html without data (images, css, whatever), but who, nowaday, have such html files ?
The passed FolderItem is located in the same folder the images folder resides and that was good / the html knows where the images are.
Remember: the saved - with a different method / button - worked fine, so I knew from the start the html was not in fault.
What said William that started with “All’s well…” ?
I’ve read about the CEF security problem. LoadPage(file) can be used. It will work.
The problem is that as local images in the filesystem must be loaded using the file protocol, the html code must be loaded from the file system too.
LoadPage(string, baseFile) wont work.
It doesn’t obey such rule, the code origin was the data: protocol, it probably could load data: resources but not file: ones.
Oh, that’s another issue. LoadPage(htmlCode, folderItem) causes this too. LoadPage(folderItem) fix. Due to CEF security. The macOS entitlement issue needing Sam’s hack to override it is another issue.
#if targetMacOS and xojoVersion >= 2020.01 then
// --- 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 Ohanaware.com
// Apple documentation for this API: https://developer.apple.com/documentation/webkit/wkwebview/1414973-loadfileurl?language=objc
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:" (Viewer as Ptr, URL as Integer, readAccessURL as Integer) as Integer
// --- Create a NSURL object from a Xojo Folderitem.
Var 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 se... For the purpose of just setting access rights, we ignore the return
// value as we don't need to display progress.
Call WKWebViewloadFileURL (h.handle, folderURL, folderURL)
#EndIf
.
Method signature is:
.
grantAccessToFolder (extends h as DesktopHTMLViewer, inFolder as folderItem)
I use this as follows (htmlbody has the html string, myViewer is the DesktopHTMLViewer in question, and ff is a folderitem pointing at the folder containing the images):
Var myViewer as DesktopHTMLViewer, htmlbody as String, ff as FolderItem
myViewer.grantAccesstoFolder (ff)
myViewer.LoadPage (htmlbody, ff)
I’m pretty sure I use file:// in the tags, I’ll have to check that but right now I’m being paged for supper.