Skip to content

Commit

Permalink
feat: update to bit 7.1.0 #27 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi authored Nov 9, 2023
1 parent 79d7d97 commit 8ca4616
Show file tree
Hide file tree
Showing 51 changed files with 1,363 additions and 893 deletions.
46 changes: 46 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"version": "0.2.0",
"compounds": [
{
"name": "Watch Api and Web",
"configurations": [
"Watch Api",
"Watch Web"
]
}
],
"configurations": [
{
"name": "Watch Api",
"type": "coreclr",
"request": "launch",
"cwd": "${workspaceFolder}/src/Server/Api",
"program": "dotnet",
"args": [
"watch",
"--project",
".",
"verbose"
],
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
{
"name": "Watch Web",
"type": "coreclr",
"request": "launch",
"cwd": "${workspaceFolder}/src/Client/Web",
"program": "dotnet",
"args": [
"watch",
"--project",
".",
"verbose"
],
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
]
}
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ Experience lightning-fast speeds and seamless integration as you dive into the w

1- Press `Ctrl + Shift + P` and run `watch sass`

2- Open new terminal in vscode and run:
2- Press `Ctrl + Shift + D` and choose `Watch Api and Web` as active debug profile and click on start debuggin button (F5)

`dotnet watch --project src/Server/Api/Bit.TemplatePlayground.Server.Api.csproj`

3- Open another terminal in vscode and run:

`dotnet watch --project src/Client/Web/Bit.TemplatePlayground.Client.Web.csproj`

4- Sign in using `[email protected]` and `123456` and explorer admin panel features!
3- Sign in using `[email protected]` and `123456` and explorer admin panel features!

Done!

Expand Down
6 changes: 4 additions & 2 deletions src/Client/App/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
x:Class="Bit.TemplatePlayground.Client.App.App"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:android="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;assembly=Microsoft.Maui.Controls"
xmlns:app="clr-namespace:Bit.TemplatePlayground.Client.App"
xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls">
xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
android:Application.WindowSoftInputModeAdjust="Resize">
<Application.Resources>
<ResourceDictionary>
<Style TargetType="ContentPage" ApplyToDerivedTypes="True">
<Style ApplyToDerivedTypes="True" TargetType="ContentPage">
<Setter Property="NavigationPage.HasNavigationBar" Value="False" />
<Setter Property="ios:Page.UseSafeArea" Value="False" />
</Style>
Expand Down
10 changes: 5 additions & 5 deletions src/Client/App/Bit.TemplatePlayground.Client.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Bit.BlazorUI" Version="7.0.0" />
<PackageReference Include="Bit.BlazorUI.Icons" Version="7.0.0" />
<PackageReference Include="Bit.BlazorUI.Assets" Version="7.0.0" />
<PackageReference Include="Bit.CodeAnalyzers" Version="7.0.0">
<PackageReference Include="Bit.BlazorUI" Version="7.1.0" />
<PackageReference Include="Bit.BlazorUI.Icons" Version="7.1.0" />
<PackageReference Include="Bit.BlazorUI.Assets" Version="7.1.0" />
<PackageReference Include="Bit.CodeAnalyzers" Version="7.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Bit.SourceGenerators" Version="7.0.0">
<PackageReference Include="Bit.SourceGenerators" Version="7.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
40 changes: 4 additions & 36 deletions src/Client/App/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
public partial class MainPage
{
private readonly IExceptionHandler _exceptionHandler;
private readonly IBitDeviceCoordinator _deviceCoordinator;

public MainPage(IExceptionHandler exceptionHandler)
public MainPage(IExceptionHandler exceptionHandler, IBitDeviceCoordinator deviceCoordinator)
{
_exceptionHandler = exceptionHandler;
_deviceCoordinator = deviceCoordinator;

InitializeComponent();

Expand Down Expand Up @@ -83,45 +85,11 @@ private void SetupBlazorWebView()

private void SetupStatusBar()
{

Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), async (handler, view) =>
{
try
{
#if ANDROID
var window = handler.PlatformView.Window;
if (window != null && Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
{
window.ClearFlags(Android.Views.WindowManagerFlags.TranslucentStatus);
window.AddFlags(Android.Views.WindowManagerFlags.DrawsSystemBarBackgrounds);
window.SetStatusBarColor(Android.Graphics.Color.Transparent);

window.DecorView.SystemUiVisibility = (Android.Views.StatusBarVisibility)(Android.Views.SystemUiFlags.LayoutFullscreen | Android.Views.SystemUiFlags.LayoutStable | Android.Views.SystemUiFlags.LightStatusBar);
if (AppInfo.Current.RequestedTheme == AppTheme.Dark)
{
window.DecorView.SystemUiVisibility &= ~(Android.Views.StatusBarVisibility)Android.Views.SystemUiFlags.LightStatusBar;
}
}
#elif MACCATALYST
var window = handler.PlatformView.WindowScene;
if (window != null)
{
window.Titlebar!.TitleVisibility = UIKit.UITitlebarTitleVisibility.Hidden;
}
#elif IOS
var statusBarStyle = AppInfo.Current.RequestedTheme == AppTheme.Dark ? UIKit.UIStatusBarStyle.LightContent : UIKit.UIStatusBarStyle.DarkContent;
await Device.InvokeOnMainThreadAsync(() =>
{
UIKit.UIApplication.SharedApplication.SetStatusBarStyle(statusBarStyle, false);
Platform.GetCurrentUIViewController().SetNeedsStatusBarAppearanceUpdate();
});
#elif WINDOWS
var window = handler.PlatformView;
if (window != null)
{
window.ExtendsContentIntoTitleBar = true;
}
#endif
await _deviceCoordinator.ApplyTheme(AppInfo.Current.RequestedTheme is AppTheme.Dark);
}
catch (Exception exp)
{
Expand Down
31 changes: 1 addition & 30 deletions src/Client/App/Platforms/Windows/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,4 @@
x:Class="Bit.TemplatePlayground.Client.App.Platforms.Windows.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui">
<maui:MauiWinUIApplication.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="WindowCaptionForeground">Gray</SolidColorBrush>
<SolidColorBrush x:Key="WindowCaptionBackground">Transparent</SolidColorBrush>
<SolidColorBrush x:Key="WindowCaptionForegroundDisabled">Gray</SolidColorBrush>
<SolidColorBrush x:Key="WindowCaptionBackgroundDisabled">Transparent</SolidColorBrush>
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="WindowCaptionForeground">Gray</SolidColorBrush>
<SolidColorBrush x:Key="WindowCaptionBackground">Transparent</SolidColorBrush>
<SolidColorBrush x:Key="WindowCaptionForegroundDisabled">Gray</SolidColorBrush>
<SolidColorBrush x:Key="WindowCaptionBackgroundDisabled">Transparent</SolidColorBrush>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<DataTemplate x:Key="MauiAppTitleBarContainerTemplate">
<Grid HorizontalAlignment="Stretch">
<ContentControl
x:Name="AppTitleBarContentControl"
Grid.Column="4"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
IsTabStop="False" />
</Grid>
</DataTemplate>
</ResourceDictionary>
</maui:MauiWinUIApplication.Resources>
</maui:MauiWinUIApplication>
xmlns:maui="using:Microsoft.Maui" />
25 changes: 15 additions & 10 deletions src/Client/App/Services/AppDeviceCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,31 @@ public double GetStatusBarHeight()
#endif
}

public async Task SetDeviceTheme(bool isDark)
public async Task ApplyTheme(bool isDark)
{
Application.Current!.UserAppTheme = isDark ? AppTheme.Dark : AppTheme.Light;
#if ANDROID
var window = Platform.CurrentActivity?.Window;
window!.DecorView!.SystemUiFlags = Android.Views.SystemUiFlags.LightStatusBar;
if (isDark)
{
window!.DecorView!.SystemUiVisibility &= ~(Android.Views.StatusBarVisibility)Android.Views.SystemUiFlags.LightStatusBar;
}
else
{
window!.DecorView!.SystemUiVisibility = (Android.Views.StatusBarVisibility)(Android.Views.SystemUiFlags.LayoutFullscreen | Android.Views.SystemUiFlags.LayoutStable | Android.Views.SystemUiFlags.LightStatusBar);
window!.DecorView!.SystemUiFlags &= ~Android.Views.SystemUiFlags.LightStatusBar;
}

window.SetStatusBarColor(isDark ? Android.Graphics.Color.ParseColor("#0D1117") : Android.Graphics.Color.White);
#elif IOS
var style = isDark ? UIKit.UIStatusBarStyle.LightContent : UIKit.UIStatusBarStyle.DarkContent;
await MainThread.InvokeOnMainThreadAsync(() =>
var statusBarStyle = isDark ? UIKit.UIStatusBarStyle.LightContent : UIKit.UIStatusBarStyle.DarkContent;
await Device.InvokeOnMainThreadAsync(() =>
{
UIKit.UIApplication.SharedApplication.SetStatusBarStyle(style, false);
Platform.GetCurrentUIViewController()?.SetNeedsStatusBarAppearanceUpdate();
UIKit.UIApplication.SharedApplication.SetStatusBarStyle(statusBarStyle, false);
Platform.GetCurrentUIViewController().SetNeedsStatusBarAppearanceUpdate();
});
#elif MACCATALYST
var window = UIKit.UIApplication.SharedApplication.Windows[0].WindowScene;
if (window != null)
{
window.Titlebar!.TitleVisibility = UIKit.UITitlebarTitleVisibility.Hidden;
}
#endif
}
}
6 changes: 4 additions & 2 deletions src/Client/Core/App.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ private async Task SetupBodyClasses()
var cssVariables = new Dictionary<string, string>();
var statusBarHeight = _bitDeviceCoordinator.GetStatusBarHeight();

if (OperatingSystem.IsIOS() && OperatingSystem.IsMacCatalyst() is false)
if (OperatingSystem.IsMacCatalyst() is false)
{
//This is handled in css using safe-area env() variables
//For iOS this is handled in css using safe-area env() variables
//For Android there's an issue with keyboard in fullscreen mode. more info: https://github.com/bitfoundation/bitplatform/issues/5626
//For Windows there's an issue with TitleBar. more info: https://github.com/bitfoundation/bitplatform/issues/5695
statusBarHeight = 0;
}

Expand Down
15 changes: 8 additions & 7 deletions src/Client/Core/Bit.TemplatePlayground.Client.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<UseMauiEssentials Condition=" '$(BlazorMode)' == 'BlazorHybrid' ">true</UseMauiEssentials>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -19,15 +19,15 @@
<Content Remove="appsettings.json" />
<EmbeddedResource Include="appsettings.json" />

<PackageReference Include="Bit.BlazorUI" Version="7.0.0" />
<PackageReference Include="Bit.BlazorUI.Icons" Version="7.0.0" />
<PackageReference Include="Bit.BlazorUI.Assets" Version="7.0.0" />
<PackageReference Include="Bit.BlazorUI.Extras" Version="7.0.0" />
<PackageReference Include="Bit.CodeAnalyzers" Version="7.0.0">
<PackageReference Include="Bit.BlazorUI" Version="7.1.0" />
<PackageReference Include="Bit.BlazorUI.Icons" Version="7.1.0" />
<PackageReference Include="Bit.BlazorUI.Assets" Version="7.1.0" />
<PackageReference Include="Bit.BlazorUI.Extras" Version="7.1.0" />
<PackageReference Include="Bit.CodeAnalyzers" Version="7.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Bit.SourceGenerators" Version="7.0.0">
<PackageReference Include="Bit.SourceGenerators" Version="7.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -51,6 +51,7 @@
</ItemGroup>

<ItemGroup Condition=" '$(BlazorMode)' == 'BlazorHybrid' ">
<PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.0-rc.2.9373" />
<Using Include="Microsoft.Maui" />
<Using Include="Microsoft.Maui.Graphics" />
<Using Include="Microsoft.Maui.Accessibility" />
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Core/Scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
public static setCookie(name: string, value: string, seconds: number) {
const date = new Date();
date.setSeconds(date.getSeconds() + seconds);
document.cookie = `${name}=${value};expires=${date.toUTCString()};path=/`;
document.cookie = `${name}=${value};expires=${date.toUTCString()};path=/;samesite=strict;`;
}

public static getCookie(name: string): string | null {
Expand Down
58 changes: 35 additions & 23 deletions src/Client/Core/Services/AppHttpClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,51 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
request.Headers.Add("Cookie", $".AspNetCore.Culture={cultureCookie}");
#endif

var response = await base.SendAsync(request, cancellationToken);
bool serverCommunicationSuccess = false;

if (response.StatusCode is HttpStatusCode.Unauthorized)
try
{
throw new UnauthorizedException();
}
var response = await base.SendAsync(request, cancellationToken);

if (response.IsSuccessStatusCode is false && response.Content.Headers.ContentType?.MediaType?.Contains("application/json", StringComparison.InvariantCultureIgnoreCase) is true)
{
if (response.Headers.TryGetValues("Request-ID", out IEnumerable<string>? values) && values is not null && values.Any())
{
RestErrorInfo restError = await response.Content.ReadFromJsonAsync(AppJsonContext.Default.RestErrorInfo, cancellationToken) ?? new();
serverCommunicationSuccess = true;

Type exceptionType = typeof(RestErrorInfo).Assembly.GetType(restError.ExceptionType ?? string.Empty) ?? typeof(UnknownException);
if (response.StatusCode is HttpStatusCode.Unauthorized)
{
throw new UnauthorizedException();
}

List<object> args = new()
if (response.IsSuccessStatusCode is false && response.Content.Headers.ContentType?.MediaType?.Contains("application/json", StringComparison.InvariantCultureIgnoreCase) is true)
{
if (response.Headers.TryGetValues("Request-ID", out IEnumerable<string>? values) && values is not null && values.Any())
{
typeof(KnownException).IsAssignableFrom(exceptionType)
? new LocalizedString(restError.Key ?? string.Empty, restError.Message ?? string.Empty)
: restError.Message ?? string.Empty
};
RestErrorInfo restError = (await response!.Content.ReadFromJsonAsync(AppJsonContext.Default.RestErrorInfo, cancellationToken))!;

if (exceptionType == typeof(ResourceValidationException))
{
args.Add(restError.Payload);
}
Type exceptionType = typeof(RestErrorInfo).Assembly.GetType(restError.ExceptionType ?? string.Empty) ?? typeof(UnknownException);

throw (Exception)(Activator.CreateInstance(exceptionType, args.ToArray()) ?? new Exception());
List<object?> args = new()
{
typeof(KnownException).IsAssignableFrom(exceptionType)
? new LocalizedString(restError.Key ?? string.Empty, restError.Message ?? string.Empty)
: restError.Message ?? string.Empty
};

if (exceptionType == typeof(ResourceValidationException))
{
args.Add(restError.Payload);
}

throw (Exception)(Activator.CreateInstance(exceptionType, args.ToArray()) ?? new Exception());
}
}
}

response.EnsureSuccessStatusCode();
response.EnsureSuccessStatusCode();

return response;
return response;
}
catch (Exception exp) when ((exp is HttpRequestException && serverCommunicationSuccess is false)
|| exp is TaskCanceledException tcExp && tcExp.InnerException is TimeoutException)
{
throw new RestException(nameof(AppStrings.UnableToConnectToServer), exp);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public interface IBitDeviceCoordinator
{
public double GetStatusBarHeight() { return 0; }

public async Task SetDeviceTheme(bool isDark) { }
public async Task ApplyTheme(bool isDark) { }

Check warning on line 10 in src/Client/Core/Services/Contracts/IBitDeviceCoordinator.cs

View workflow job for this annotation

GitHub Actions / build blazor server

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 10 in src/Client/Core/Services/Contracts/IBitDeviceCoordinator.cs

View workflow job for this annotation

GitHub Actions / build blazor api + web assembly

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 10 in src/Client/Core/Services/Contracts/IBitDeviceCoordinator.cs

View workflow job for this annotation

GitHub Actions / build blazor hybrid (android)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 10 in src/Client/Core/Services/Contracts/IBitDeviceCoordinator.cs

View workflow job for this annotation

GitHub Actions / build blazor hybrid (iOS)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 10 in src/Client/Core/Services/Contracts/IBitDeviceCoordinator.cs

View workflow job for this annotation

GitHub Actions / build blazor hybrid (windows)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 10 in src/Client/Core/Services/Contracts/IBitDeviceCoordinator.cs

View workflow job for this annotation

GitHub Actions / build blazor hybrid (maccatalyst)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
}
2 changes: 1 addition & 1 deletion src/Client/Core/Shared/Header.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private void OpenEditProfilePage()

private async Task ToggleTheme()
{
await _bitDeviceCoordinator.SetDeviceTheme(await _bitThemeManager.ToggleDarkLightAsync() == "dark");
await _bitDeviceCoordinator.ApplyTheme(await _bitThemeManager.ToggleDarkLightAsync() == "dark");
}

public void Dispose()
Expand Down
Loading

0 comments on commit 8ca4616

Please sign in to comment.