brockgr / websaver

Automatically exported from code.google.com/p/websaver
GNU General Public License v3.0
83 stars 13 forks source link

file:// protocol URL support #25

Open TomasHubelbauer opened 1 year ago

TomasHubelbauer commented 1 year ago

Hi, I tried building off of latest master and found that the screensaver works well for web URLs but I couldn't get it to load a local file:// protocol URL. Is there any way to make it support this?

There are some solutions here: https://stackoverflow.com/q/49638653/2715716. They rely on adding the local file to the app's bundle though. I would like to avoid that.

Is this the only way or is there is some kind of a flag I can toggle on the WKWebView or a capability I can add to the app to allow it to access files not in the XCode project.

I tried this:

- (void)loadUrl
{
    [webView.configuration.preferences setValue:@"TRUE" forKey:@"allowFileAccessFromFileURLs"];
    NSURL *url = [NSURL fileURLWithPath:@"/Users/…/index.html"];
    [webView loadFileURL:url.absoluteURL allowingReadAccessToURL:url.URLByDeletingLastPathComponent];

    lastLoad = [[NSDate alloc] init];
    DebugLog(@"reloaded %@",[lastLoad description]);
}

But I only get a blank screen. I don't know how to check the logs since the screen saver cannot be run from XCode. I also tried appending file:// to the URL string to no avail.

TomasHubelbauer commented 1 year ago

I looked around and it seems that in order to do this, there would need to be a separate launcher application for the screen saver or it would need to be ported to use the new .appex extension type of a thing. .saver bundles are now considered legacy in the macOS land. If .appex was used, one could configure its entitlements to add the capability to read local files, but .saver bundles cannot have their entitlements changed, they inherit the entitlements from legacyScreenSaver.appex which I am not sure what they are but the ability to read local files is not one of them, I've checked.