SteveSandersonMS / WebWindow

.NET Core library to open native OS windows containing web UI on Windows, Mac, and Linux. Experimental.
Apache License 2.0
1.99k stars 214 forks source link

NavigationManager stops sworking after closing and opening the app without terminating the process blazor #106

Open eivarin opened 4 years ago

eivarin commented 4 years ago

The navigation manager stops working after closing and opening the app. I'm using a windows forms notify icon and a custom application context to keep the process open even if the webwindow is closed but then when I go to reopen the webwindow under the same process it opens normally in the page that I was previously, but when i go to click a div that triggers a NavigationManager.NavigateTo(LinkName); it doesn't change page. I tried to debug this and, when I clicked a div that changes the page before closing it did this: image then this image and then run something with the dispatcher which looks to be made for error checking. After closing and reopening the webwindow I try to clicks a div that changes the page it did the same thing again but then when i clicked it again it didnt even debugged anymore. Note that while the buttons did nothing the HTML and css still worked as the hovers where still working

eivarin commented 4 years ago

So i managed to fix this, but since it isn't a general bug just one very specific for me I won't make a PR for it. The problem was the instance of DesktopNavigationManager was being kept the same between opening and closing the webwindow..... what I did was:

In the DesktopNavigationManager.cs I removed the protection from the instance: from this public static readonly DesktopNavigationManager Instance = new DesktopNavigationManager(); to this public static DesktopNavigationManager Instance = new DesktopNavigationManager();

and added a line that creates a new instance for DesktopNavigationManager whenever the application closes:

try{
                    WebWindow.NavigateToUrl(BlazorAppScheme + "://app/");
                    WebWindow.WaitForExit();
}
finally{
                    appLifetimeCts.Cancel();
                    //my code
                    DesktopNavigationManager.Instance = new DesktopNavigationManager();
}