|
572 | 572 | private string qrCodeScannerWidth = "90%"; |
573 | 573 |
|
574 | 574 | private readonly string manualRegistrationDescTooltip = "Manually registering a 2FA secret is useful for example if your device has no camera to scan the QR code with, or if you want more control over how the entry is going to be labelled inside your TFACGUI chain.\n\nMake sure to enter everything correctly and label everything in an easily recognizable fashion!"; |
| 575 | + |
| 576 | + private static event Action? Looped; |
575 | 577 |
|
576 | 578 | protected override async Task OnInitializedAsync() |
577 | 579 | { |
|
581 | 583 |
|
582 | 584 | gridView = await JS.InvokeAsync<string>(Constants.InteropFunctionNames.GET_LOCALSTORAGE_VALUE, Constants.LocalStorageIds.GRID_VIEW, "true") != "false"; |
583 | 585 |
|
584 | | - for (;;) |
| 586 | + bool workerApiSupported = await JS.InvokeAsync<bool>(Constants.InteropFunctionNames.IS_WORKER_AVAILABLE); |
| 587 | + |
| 588 | + if (workerApiSupported) |
585 | 589 | { |
586 | | - if (changedFocusedState) |
587 | | - { |
588 | | - changedFocusedState = false; |
| 590 | + await JS.InvokeVoidAsync(Constants.InteropFunctionNames.START_LOOP_WORKER); |
589 | 591 |
|
590 | | - if (focused) |
| 592 | + Looped += OnLoopCycle; |
| 593 | + } |
| 594 | + else |
| 595 | + { |
| 596 | + for (;;) |
| 597 | + { |
| 598 | + if (changedFocusedState) |
591 | 599 | { |
592 | | - userData = await UserDataService.GetUserData(); |
| 600 | + changedFocusedState = false; |
| 601 | + |
| 602 | + if (focused) |
| 603 | + { |
| 604 | + userData = await UserDataService.GetUserData(); |
| 605 | + } |
593 | 606 | } |
594 | | - } |
595 | 607 |
|
596 | | - StateHasChanged(); |
| 608 | + StateHasChanged(); |
597 | 609 |
|
598 | | - await Task.Delay(focused ? 128 : 256); |
| 610 | + await Task.Delay(focused ? 128 : 256); |
| 611 | + } |
599 | 612 | } |
600 | 613 | } |
601 | 614 |
|
|
612 | 625 | changedFocusedState = true; |
613 | 626 | } |
614 | 627 |
|
| 628 | + [JSInvokable] |
| 629 | + public static void OnLoopCycleWorkerCallback(string eventArgs) |
| 630 | + { |
| 631 | +#if DEBUG |
| 632 | + Console.WriteLine($"Loop cycle occurred. Event args: {eventArgs}"); |
| 633 | +#endif |
| 634 | + |
| 635 | + Looped?.Invoke(); |
| 636 | + } |
| 637 | + |
| 638 | + private void OnLoopCycle() |
| 639 | + { |
| 640 | + if (changedFocusedState) |
| 641 | + { |
| 642 | + changedFocusedState = false; |
| 643 | + |
| 644 | + if (focused) |
| 645 | + { |
| 646 | + Task.Run(async () => |
| 647 | + { |
| 648 | + userData = await UserDataService.GetUserData(); |
| 649 | + }); |
| 650 | + } |
| 651 | + } |
| 652 | + |
| 653 | + StateHasChanged(); |
| 654 | + } |
| 655 | + |
615 | 656 | private async Task ResetManualRegistrationModalForm() |
616 | 657 | { |
617 | 658 | await JS.InvokeVoidAsync(Constants.InteropFunctionNames.SET_INPUT_VALUE, Constants.ElementIds.TOTP_CONFIG_ENTRY_NAME, string.Empty); |
|
0 commit comments