Eilon / MauiHybridWebView

MIT License
206 stars 44 forks source link

Load local files from FileSystem.Current.AppDataDirectory #71

Open GorillaSpring opened 1 month ago

GorillaSpring commented 1 month ago

I download my HTML UI. This is based on configuration for the user. In addition an updated UI can be pushed out.

I need to be able to load html pages from FileSystem.Current.AppDataDirectory

Seems like you cannot write to the "Raw" directory.

If this is way out of scope, any pointers to modifying a fork would be super helpful.

My production platforms are iOS and Android, but I am using windows as a platform during dev.

Eilon commented 1 month ago

Hi @GorillaSpring , can you share more info on what you're trying to do? The Raw folder is part of the app itself, and ends up in the app's package file. In general, platforms don't support apps modifying themselves in that manner. If an app needs to save data, there are other locations for storing that data, such as in an Application Data folder, or a per-user folder.

GorillaSpring commented 1 month ago

@Eilon. Thanks for the response.

So, we have been in production (iOS and Android) for almost 4 years. I am not "modifying" the app at runtime, I am simply just styling it and hiding / showing features. All of this could be done with native / maui UI.

The production app is Xamarin native. (Note, I found forms very frustrating, so just stuck with native).

Our workflow:

The user installs the app. The app downloads an HTML ui from our server. This is Spanish if the device lang is Spanish, or English otherwise. (we only support EN and ES). The user either uses a code or logs in with an existing account. Based on the users config (this can include an overridden language) another ui package may be downloaded (partial HTML). Think green instead of orange and hiding and showing features. Bit more to it then that, but essentially that is the case.

** In addition ***

The App downloads a bunch of SCORM like courses. These are HTML based courses that are generated with a authoring tool. These can be quite big and a lot of data. The course that are downloaded can vary from user to user quite a bit.

To run these, I do need to pass in query strings.

As a quick note, we use one view per HTML view. This means that you still get the device navigation feel and features. Each view is essentially just a WebView, however some have other things on it.

All this works quite well. The HTML simply calls a JS bridge to communicate with the device. Almost everything works offline, and is synced up to the server as needed and when online.

Another quick note. The SAME HTML is used for the UI on our web server (Razor simply loads the div from the HTML).

So, being forced to move to MAUI, All I really need is a JSBridge. The other solutions (to hack the Navigated) do not work because of the SCORM like courses. Also, there are race conditions and the iOS browser cancels previous requests. Also, just a really bad hack for something MS should have included prior to dropping support for Xamarin.

I am going back to trying to make this work with .net8 : https://github.com/nmoschkin/MAUIWebViewExample

So, the reason for my long winded response is to give you an idea of how a hybrid ui may work.

One thing that will also come up (think it has in your comments) is if a app uses a resource created on the app and you want to show it. IE, pick a profile picture. I guess you would have to encode it and serve it up though the "proxy".

rbrundritt commented 1 month ago

As luck would have it I have a solution for this as I ran into a similar requirement a month ago (I needed to be able to load a webpage I had as an embedded resource). I have been pushing the limits of this control and am starting to clean up my workarounds and bring them back here. I just made a pull request that allows the proxy capability to be used with the MainFile. I saw this post just before making the PR, so I added a sample for this specific scenario. Here is the PR: https://github.com/Eilon/MauiHybridWebView/pull/73

GorillaSpring commented 1 month ago

@rbrundritt . Thank. I did manage to write my own. @Eilon 's solution was really helpful. I now know more about custom Maui controls then I ever wanted to. When I get a chance (in a few weeks at least), I will put up the solution. It is significantly simpler and works for my requirement. Will also work for server hosted files just fine.