1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using Microsoft.AspNetCore.Components.WebView;
- using Microsoft.AspNetCore.Components.WebView.WindowsForms;
- using PCC.AppScaffold;
- using PCC.Common.EventBus;
- using PCC.Common.Logging;
- namespace PCC.Gui
- {
- public partial class PccMainForm : Form
- {
- private IEventBus _eventBus;
- private bool _isShuttingDown = false;
- public PccMainForm()
- {
- InitializeComponent();
- }
- private async void PccMainForm_Shown(object sender, EventArgs e)
- {
- ApplicationInitializationStatusLabel.Text = "Building host...";
- Application.DoEvents();
- HostHolder.BuildHost();
- _eventBus = HostHolder.EventBus;
- void UseEvh(UiShownEvent obj)
- {
- ApplicationInitializationPanel.Hide();
- _eventBus.UnSubscript<UiShownEvent>(UseEvh);
- #if DEBUG
- MainBlazorWebView.WebView.CoreWebView2.OpenDevToolsWindow();
- #endif
- }
- _eventBus.Subscript((Action<UiShownEvent>)UseEvh);
- async void LocalMethod(LoggingEvent le)
- {
- if (ApplicationInitializationPanel.Visible == false) return;
- ApplicationInitializationStatusLabel.Text = $"{le.LogLevel} {le.Content}";
- Application.DoEvents();
- }
- HostHolder.EventBus.Subscript<LoggingEvent>(LocalMethod);
- ApplicationInitializationStatusLabel.Text = "Starting host...";
- Application.DoEvents();
- await HostHolder.StartAsync();
- void OnUrlLoading(object? o, UrlLoadingEventArgs args)
- {
- MainBlazorWebView.UrlLoading -= OnUrlLoading;
- ApplicationInitializationStatusLabel.Text = "Loading UI...";
- Application.DoEvents();
- }
- MainBlazorWebView.UrlLoading += OnUrlLoading;
- MainBlazorWebView.HostPage = "wwwroot\\index-mud-ise.html";
- MainBlazorWebView.Services = HostHolder.ServiceProvider;
- MainBlazorWebView.RootComponents.Add<MudIse.MainMudIse>("#app");
- }
- private void PccMainForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (_isShuttingDown) return;
- _isShuttingDown = true;
- ApplicationInitializationPanel.Show();
- ApplicationInitializationTitleLabel.Text = "Application shutting down...";
- Application.DoEvents();
- HostHolder.StopAsync().Wait();
- ApplicationInitializationStatusLabel.Text = "Window will close after 3 second...";
- Application.DoEvents();
- Task.Delay(3000).Wait();
- }
- }
- }
|