示例#1
0
 public MainLayout()
 {
     Themes = new MudTheme[]
     {
         new(), // default
         new()  // dark
         {
             Palette = new Palette()
             {
                 Black                    = "#27272f",
                 Background               = "#32333d",
                 BackgroundGrey           = "#27272f",
                 Surface                  = "#373740",
                 DrawerBackground         = "#27272f",
                 DrawerText               = "rgba(255,255,255, 0.50)",
                 DrawerIcon               = "rgba(255,255,255, 0.50)",
                 AppbarBackground         = "#27272f",
                 AppbarText               = "rgba(255,255,255, 0.70)",
                 TextPrimary              = "rgba(255,255,255, 0.70)",
                 TextSecondary            = "rgba(255,255,255, 0.50)",
                 ActionDefault            = "#adadb1",
                 ActionDisabled           = "rgba(255,255,255, 0.26)",
                 ActionDisabledBackground = "rgba(255,255,255, 0.12)"
             },
         },
     };
     _currentTheme = Themes[0];
 }
示例#2
0
        private async Task ToggleTheme()
        {
            _isLightMode  = !_isLightMode;
            _currentTheme = !_isLightMode?GenerateDarkTheme() : new MudTheme();

            await OnThemeToggled.InvokeAsync(_currentTheme);
        }
示例#3
0
        protected override async Task OnInitializedAsync()
        {
            _interceptor.RegisterEvent();
            currentTheme = await _preferenceManager.GetCurrentThemeAsync();

            hubConnection = hubConnection.TryInitialize(_navigationManager);
            await hubConnection.StartAsync();

            hubConnection.On <string, string>("ReceiveChatNotification", (message, userId) =>
            {
                if (CurrentUserId == userId)
                {
                    _snackBar.Add(message, Severity.Info);
                }
            });
            hubConnection.On("RegenerateTokens", async() =>
            {
                try
                {
                    var token = await _authenticationManager.TryForceRefreshToken();
                    if (!string.IsNullOrEmpty(token))
                    {
                        _snackBar.Add("Refreshed Token.", Severity.Success);
                        _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    _snackBar.Add("You are Logged Out.", Severity.Error);
                    await _authenticationManager.Logout();
                    _navigationManager.NavigateTo("/");
                }
            });
        }
示例#4
0
        private async Task DarkMode()
        {
            bool isDarkMode = await _clientPreferenceManager.ToggleDarkModeAsync();

            _currentTheme = isDarkMode
                ? BlazorHeroTheme.DefaultTheme
                : BlazorHeroTheme.DarkTheme;
        }
示例#5
0
        protected override async Task OnInitializedAsync()
        {
            _currentTheme = BlazorHeroTheme.DefaultTheme;
            _currentTheme = await _clientPreferenceManager.GetCurrentThemeAsync();

            _rightToLeft = await _clientPreferenceManager.IsRTL();

            _interceptor.RegisterEvent();
        }
示例#6
0
        public void RotateTheme()
        {
            int current = Themes.IndexOf(_currentTheme);
            int next    = current == -1
                ? 0
                : current + 1 >= Themes.Count
                    ? 0
                    : current + 1;

            _currentTheme = Themes[next];
        }
示例#7
0
        public static MudTheme DocsTheme()
        {
            var theme = new MudTheme()
            {
                Palette          = DocsLightPalette,
                PaletteDark      = DocsDarkPalette,
                LayoutProperties = new LayoutProperties()
            };

            return(theme);
        }
示例#8
0
 private void SwithTheme()
 {
     if (_currentTheme == _defaultTheme)
     {
         _currentTheme = _darkTheme;
     }
     else
     {
         _currentTheme = _defaultTheme;
     }
 }
示例#9
0
        private async Task DarkMode()
        {
            bool isDarkMode = await _preferenceManager.ToggleDarkModeAsync();

            if (isDarkMode)
            {
                currentTheme = BlazorHeroTheme.DefaultTheme;
            }
            else
            {
                currentTheme = BlazorHeroTheme.DarkTheme;
            }
        }
示例#10
0
        public static MudTheme LandingPageTheme()
        {
            var theme = new MudTheme()
            {
                Palette          = LandingPageLightPalette,
                PaletteDark      = LandingPageDarkPalette,
                Shadows          = LandingPageShadows,
                LayoutProperties = LandingPageLayoutProperties,
                ZIndex           = new ZIndex(),
                Typography       = LandingPageTypography
            };

            return(theme);
        }
示例#11
0
        protected override async Task OnInitializedAsync()
        {
            currentTheme = BlazorHeroTheme.DefaultTheme;
            currentTheme = await _clientPreferenceManager.GetCurrentThemeAsync();

            _interceptor.RegisterEvent();
            hubConnection = hubConnection.TryInitialize(_navigationManager);
            await hubConnection.StartAsync();

            hubConnection.On <string, string, string>(ApplicationConstants.SignalR.ReceiveChatNotification, (message, receiverUserId, senderUserId) =>
            {
                if (CurrentUserId == receiverUserId)
                {
                    _jsRuntime.InvokeAsync <string>("PlayAudio", "notification");
                    _snackBar.Add(message, Severity.Info, config =>
                    {
                        config.VisibleStateDuration   = 10000;
                        config.HideTransitionDuration = 500;
                        config.ShowTransitionDuration = 500;
                        config.Action      = "Chat?";
                        config.ActionColor = Color.Primary;
                        config.Onclick     = snackbar =>
                        {
                            _navigationManager.NavigateTo($"chat/{senderUserId}");
                            return(Task.CompletedTask);
                        };
                    });
                }
            });
            hubConnection.On(ApplicationConstants.SignalR.ReceiveRegenerateTokens, async() =>
            {
                try
                {
                    var token = await _authenticationManager.TryForceRefreshToken();
                    if (!string.IsNullOrEmpty(token))
                    {
                        _snackBar.Add("Refreshed Token.", Severity.Success);
                        _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    _snackBar.Add("You are Logged Out.", Severity.Error);
                    await _authenticationManager.Logout();
                    _navigationManager.NavigateTo("/");
                }
            });
        }
        protected override async Task OnInitializedAsync()
        {
            _interceptor.RegisterEvent();
            currentTheme = await _preferenceManager.GetCurrentThemeAsync();

            hubConnection = hubConnection.TryInitialize(_navigationManager);
            await hubConnection.StartAsync();

            hubConnection.On <string, string>("ReceiveChatNotification", (message, userId) =>
            {
                if (CurrentUserId == userId)
                {
                    _snackBar.Add(message, Severity.Info);
                }
            });
        }
        protected override async Task OnInitializedAsync()
        {
            _interceptor.RegisterEvent();
            currentTheme = await _preferenceManager.GetCurrentThemeAsync();

            hubConnection = new HubConnectionBuilder()
                            .WithUrl(_navigationManager.ToAbsoluteUri("/chatHub"))
                            .Build();
            hubConnection.On <string, string>("ReceiveChatNotification", (message, userId) =>
            {
                if (CurrentUserId == userId)
                {
                    _snackBar.Add(message, Severity.Info, options => options.BackgroundBlurred = true);
                }
            });
            await hubConnection.StartAsync();
        }
示例#14
0
 public static string GetName(MudTheme theme)
 {
     return(theme == NightMode?nameof(NightMode) : nameof(Default));
 }
示例#15
0
 protected override async Task OnInitializedAsync()
 {
     currentTheme = await _preferenceManager.GetCurrentThemeAsync();
 }
示例#16
0
        protected override async Task OnInitializedAsync()
        {
            _currentTheme = BlazorHeroTheme.DefaultTheme;
            _currentTheme = await _clientPreferenceManager.GetCurrentThemeAsync();

            _rightToLeft = await _clientPreferenceManager.IsRTL();

            _interceptor.RegisterEvent();
            hubConnection = hubConnection.TryInitialize(_navigationManager);
            await hubConnection.StartAsync();

            hubConnection.On <string, string, string>(ApplicationConstants.SignalR.ReceiveChatNotification, (message, receiverUserId, senderUserId) =>
            {
                if (CurrentUserId == receiverUserId)
                {
                    _jsRuntime.InvokeAsync <string>("PlayAudio", "notification");
                    _snackBar.Add(message, Severity.Info, config =>
                    {
                        config.VisibleStateDuration   = 10000;
                        config.HideTransitionDuration = 500;
                        config.ShowTransitionDuration = 500;
                        config.Action      = localizer["Chat?"];
                        config.ActionColor = Color.Primary;
                        config.Onclick     = snackbar =>
                        {
                            _navigationManager.NavigateTo($"chat/{senderUserId}");
                            return(Task.CompletedTask);
                        };
                    });
                }
            });
            hubConnection.On(ApplicationConstants.SignalR.ReceiveRegenerateTokens, async() =>
            {
                try
                {
                    var token = await _authenticationManager.TryForceRefreshToken();
                    if (!string.IsNullOrEmpty(token))
                    {
                        _snackBar.Add(localizer["Refreshed Token."], Severity.Success);
                        _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    _snackBar.Add(localizer["You are Logged Out."], Severity.Error);
                    await _authenticationManager.Logout();
                    _navigationManager.NavigateTo("/");
                }
            });
            hubConnection.On <string, string>(ApplicationConstants.SignalR.LogoutUsersByRole, async(userId, roleId) =>
            {
                if (CurrentUserId != userId)
                {
                    var rolesResponse = await RoleManager.GetRolesAsync();
                    if (rolesResponse.Succeeded)
                    {
                        var role = rolesResponse.Data.FirstOrDefault(x => x.Id == roleId);
                        if (role != null)
                        {
                            var currentUserRolesResponse = await _userManager.GetRolesAsync(CurrentUserId);
                            if (currentUserRolesResponse.Succeeded && currentUserRolesResponse.Data.UserRoles.Any(x => x.RoleName == role.Name))
                            {
                                _snackBar.Add(localizer["You are logged out because the Permissions of one of your Roles have been updated."], Severity.Error);
                                await hubConnection.SendAsync(ApplicationConstants.SignalR.OnDisconnect, CurrentUserId);
                                await _authenticationManager.Logout();
                                _navigationManager.NavigateTo("/login");
                            }
                        }
                    }
                }
            });
        }
示例#17
0
 public void SetBaseTheme(MudTheme theme)
 {
     CurrentTheme = theme;
     OnMajorUpdateOccured();
 }
示例#18
0
 protected override async Task OnInitializedAsync()
 {
     _interceptor.RegisterEvent();
     currentTheme = await _preferenceManager.GetCurrentThemeAsync();
 }