DevEjectionSeat.razor 862 B

12345678910111213141516171819202122232425262728293031323334
  1. @if (_isRunning)
  2. {
  3. @ChildContent
  4. }
  5. else
  6. {
  7. <h1 class="loading">Dev Ejection Seat Working</h1>
  8. }
  9. @code
  10. {
  11. [Parameter]
  12. public RenderFragment? ChildContent { get; set; }
  13. private IJSObjectReference? module;
  14. private bool _isRunning = true;
  15. protected override async Task OnAfterRenderAsync(bool firstRender)
  16. {
  17. await base.OnAfterRenderAsync(firstRender);
  18. if (firstRender == false) return;
  19. module = await JS.InvokeAsync<IJSObjectReference>("import", "./Gui/Blazor/DevEjectionSeat.razor.js");
  20. await module.InvokeVoidAsync("SetBeforeUnloadEventHandler", DotNetObjectReference.Create(this), nameof(BeforeUnloadEventHandler));
  21. }
  22. [JSInvokable]
  23. public void BeforeUnloadEventHandler()
  24. {
  25. if (_isRunning == false) return;
  26. _isRunning = false;
  27. StateHasChanged();
  28. }
  29. }