Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi committed Jul 8, 2024
1 parent 90633a5 commit 2fa221b
Show file tree
Hide file tree
Showing 32 changed files with 110 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class AppErrorBoundary

protected override void OnInitialized()
{
showException = BuildConfiguration.IsDebug();
showException = AppEnvironment.IsDevelopment();
}

protected override async Task OnErrorAsync(Exception exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ await cookie.Set(new()
Name = ".AspNetCore.Culture",
Value = Uri.EscapeDataString($"c={SelectedCulture}|uic={SelectedCulture}"),
MaxAge = 30 * 24 * 3600,
Secure = BuildConfiguration.IsRelease()
Secure = AppEnvironment.IsDevelopment() is false
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,10 @@ public static void AddClientConfigurations(this IConfigurationBuilder builder)
var assembly = Assembly.Load("Boilerplate.Client.Core");
builder.AddJsonStream(assembly.GetManifestResourceStream("Boilerplate.Client.Core.appsettings.json")!);

if (BuildConfiguration.IsDebug())
var settings = assembly.GetManifestResourceStream($"Boilerplate.Client.Core.appsettings.{AppEnvironment.Name}.json");
if (settings is not null)
{
var settings = assembly.GetManifestResourceStream("Boilerplate.Client.Core.appsettings.Debug.json");
if (settings is not null)
{
builder.AddJsonStream(settings);
}
}
else
{
var settings = assembly.GetManifestResourceStream("Boilerplate.Client.Core.appsettings.Release.json");
if (settings is not null)
{
builder.AddJsonStream(settings);
}
builder.AddJsonStream(settings);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public static IServiceCollection AddClientCoreProjectServices(this IServiceColle
// .UseModel(OfflineDbContextModel.Instance)
.UseSqlite($"Data Source={dbPath}");

options.EnableSensitiveDataLogging(BuildConfiguration.IsDebug())
.EnableDetailedErrors(BuildConfiguration.IsDebug());
options.EnableSensitiveDataLogging(AppEnvironment.IsDevelopment())
.EnableDetailedErrors(AppEnvironment.IsDevelopment());
});
//#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class AppRenderMode
public static IComponentRenderMode NoPrerenderBlazorWebAssembly => new InteractiveWebAssemblyRenderMode(prerender: false);

public static IComponentRenderMode Current =>
BuildConfiguration.IsDebug()
AppEnvironment.IsDevelopment()
? BlazorServer // For better development experience.
: Auto; // For better production experience.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ await cookie.Set(new()
Value = response.AccessToken,
MaxAge = rememberMe is true ? response.ExpiresIn : null, // to create a session cookie
SameSite = SameSite.Strict,
Secure = BuildConfiguration.IsRelease()
Secure = AppEnvironment.IsDevelopment() is false
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Handle(Exception exp, IDictionary<string, object?>? parameters = nul

protected virtual void Handle(Exception exception, Dictionary<string, object> parameters)
{
var isDebug = BuildConfiguration.IsDebug();
var isDebug = AppEnvironment.IsDevelopment();

string exceptionMessage = (exception as KnownException)?.Message ??
(isDebug ? exception.ToString() : Localizer[nameof(AppStrings.UnknownException)]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
<BitLabel>App Version:</BitLabel>
<BitLabel>@appVersion</BitLabel>
</BitStack>
<BitStack Horizontal Gap=".5rem">
<BitLabel>OS:</BitLabel>
<BitLabel>@os</BitLabel>
</BitStack>
<BitStack Horizontal Gap=".5rem">
<BitLabel>OEM:</BitLabel>
<BitLabel>@oem</BitLabel>
</BitStack>
<BitStack Horizontal Gap=".5rem">
<BitLabel>Environment:</BitLabel>
<BitLabel>@AppEnvironment.Name</BitLabel>
</BitStack>
<BitStack Horizontal Gap=".5rem">
<BitLabel>Process Id:</BitLabel>
<BitLabel>@processId</BitLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public partial class AboutPage
private string appName = default!;
private string appVersion = default!;
private string processId = default!;
private string os = default!;
private string oem = default!;

protected async override Task OnInitAsync()
{
Expand All @@ -20,6 +22,8 @@ protected async override Task OnInitAsync()
appVersion = AppInfo.Version.ToString();
#endif
processId = Environment.ProcessId.ToString();
os = $"{DeviceInfo.Current.Platform} {DeviceInfo.Current.VersionString}";
oem = DeviceInfo.Current.Manufacturer;

await base.OnInitAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private async Task CheckForUpdates()
}
}
}
catch (InvalidOperationException) when ((OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst() || OperatingSystem.IsMacOS()) && BuildConfiguration.IsDebug()) { }
catch (InvalidOperationException) when ((OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst() || OperatingSystem.IsMacOS()) && AppEnvironment.IsDevelopment()) { }
catch (FileNotFoundException) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void ConfigureServices(this MauiAppBuilder builder)

services.AddMauiBlazorWebView();

if (BuildConfiguration.IsDebug())
if (AppEnvironment.IsDevelopment())
{
services.AddBlazorWebViewDeveloperTools();
}
Expand All @@ -43,7 +43,7 @@ public static void ConfigureServices(this MauiAppBuilder builder)

builder.Logging.AddConfiguration(configuration.GetSection("Logging"));

if (BuildConfiguration.IsDebug())
if (AppEnvironment.IsDevelopment())
{
builder.Logging.AddDebug();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static void SetupBlazorWebView()
webView.DefaultBackgroundColor = Microsoft.UI.Colors.Black;
}

if (BuildConfiguration.IsRelease())
if (AppEnvironment.IsDevelopment() is false)
{
webView.EnsureCoreWebView2Async()
.AsTask()
Expand All @@ -118,7 +118,7 @@ private static void SetupBlazorWebView()
webView.ScrollView.Bounces = false;
webView.Opaque = false;

if (BuildConfiguration.IsDebug())
if (AppEnvironment.IsDevelopment())
{
if ((DeviceInfo.Current.Platform == DevicePlatform.MacCatalyst && DeviceInfo.Current.Version >= new Version(13, 3))
|| (DeviceInfo.Current.Platform == DevicePlatform.iOS && DeviceInfo.Current.Version >= new Version(16, 4)))
Expand All @@ -143,7 +143,7 @@ private static void SetupBlazorWebView()
settings.JavaScriptCanOpenWindowsAutomatically =
settings.DomStorageEnabled = true;

if (BuildConfiguration.IsDebug())
if (AppEnvironment.IsDevelopment())
{
settings.MixedContentMode = Android.Webkit.MixedContentHandling.AlwaysAllow;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private async Task<int> StartImplementation()
{
ApplicationName = "LocalHttpServer",
ContentRootPath = Directory.GetCurrentDirectory(),
EnvironmentName = BuildConfiguration.IsDebug() ? Environments.Development : Environments.Production,
EnvironmentName = AppEnvironment.Name,
WebRootPath = Path.Combine(AppContext.BaseDirectory, "wwwroot")
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);

AppEnvironment.Name = builder.HostEnvironment.Environment;

#if BlazorWebAssemblyStandalone
builder.RootComponents.Add<Routes>("#app-container");
builder.RootComponents.Add<HeadOutlet>("head::after");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
<BitLabel>App Version:</BitLabel>
<BitLabel>@appVersion</BitLabel>
</BitStack>
<BitStack Horizontal Gap=".5rem">
<BitLabel>OS:</BitLabel>
<BitLabel>@os</BitLabel>
</BitStack>
<BitStack Horizontal Gap=".5rem">
<BitLabel>Environment:</BitLabel>
<BitLabel>@AppEnvironment.Name</BitLabel>
</BitStack>
<BitStack Horizontal Gap=".5rem">
<BitLabel>Process Id:</BitLabel>
<BitLabel>@processId</BitLabel>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
using System.Reflection;
using System.Runtime.InteropServices;

namespace Boilerplate.Client.Windows.Components.Pages;

public partial class AboutPage
{
private string appName = default!;
private string appVersion = default!;
private string os = default!;
private string processId = default!;

protected async override Task OnInitAsync()
{
var asm = typeof(AboutPage).Assembly;
appName = asm.GetCustomAttribute<AssemblyTitleAttribute>()!.Title;
appVersion = asm.GetName().Version!.ToString();
os = RuntimeInformation.OSDescription;
processId = Environment.ProcessId.ToString();

await base.OnInitAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public MainWindow()
{
await BlazorWebView.WebView.EnsureCoreWebView2Async();
var settings = BlazorWebView.WebView.CoreWebView2.Settings;
if (BuildConfiguration.IsRelease())
if (AppEnvironment.IsDevelopment() is false)
{
settings.IsZoomControlEnabled = false;
settings.AreBrowserAcceleratorKeysEnabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void ConfigureServices(this IServiceCollection services)
});

services.AddWpfBlazorWebView();
if (BuildConfiguration.IsDebug())
if (AppEnvironment.IsDevelopment())
{
services.AddBlazorWebViewDeveloperTools();
}
Expand All @@ -43,7 +43,7 @@ public static void ConfigureServices(this IServiceCollection services)
loggingBuilder.AddConfiguration(configuration.GetSection("Logging"));
loggingBuilder.AddEventLog();
loggingBuilder.AddEventSourceLogger();
if (BuildConfiguration.IsDebug())
if (AppEnvironment.IsDevelopment())
{
loggingBuilder.AddDebug();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private async Task<int> StartImplementation()
{
ApplicationName = "LocalHttpServer",
ContentRootPath = Directory.GetCurrentDirectory(),
EnvironmentName = BuildConfiguration.IsDebug() ? Environments.Development : Environments.Production,
EnvironmentName = AppEnvironment.Name,
WebRootPath = Path.Combine(AppContext.BaseDirectory, "wwwroot")
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

<PwaEnabled Condition=" '$(BlazorWebAssemblyStandalone)' == 'true' ">true</PwaEnabled>

<!-- See Boilerplate.Shared.AppEnvironment for more info. -->
<Environment Condition="'$(Environment)' == '' AND '$(Configuration)' == 'Debug'">Development</Environment>
<Environment Condition="'$(Environment)' == '' AND '$(Configuration)' == 'Release'">Production</Environment>

<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('-ios'))">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('-mac'))">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('-android'))">24.0</SupportedOSPlatformVersion>
Expand All @@ -34,6 +38,7 @@
<DefineConstants Condition=" '$(MultilingualEnabled)' == 'true' ">$(DefineConstants);MultilingualEnabled</DefineConstants>
<DefineConstants Condition=" '$(BlazorWebAssemblyStandalone)' == 'true' ">$(DefineConstants);BlazorWebAssemblyStandalone</DefineConstants>
<DefineConstants Condition=" '$(PwaEnabled)' == 'true' ">$(DefineConstants);PwaEnabled</DefineConstants>
<DefineConstants>$(DefineConstants);$(Environment)</DefineConstants>
</PropertyGroup>
<!--/+:msbuild-conditional:noEmit -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ public static async Task Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);

AppEnvironment.Name = builder.Environment.EnvironmentName;

builder.Configuration.AddSharedConfigurations();

// The following line (using the * in the URL), allows the emulators and mobile devices to access the app using the host IP address.
if (BuildConfiguration.IsDebug() && OperatingSystem.IsWindows())
if (AppEnvironment.IsDevelopment() && OperatingSystem.IsWindows())
{
builder.WebHost.UseUrls("http://localhost:5031", "http://*:5031");
}
Expand All @@ -21,7 +23,7 @@ public static async Task Main(string[] args)

var app = builder.Build();

if (BuildConfiguration.IsDebug())
if (AppEnvironment.IsDevelopment())
{
await using var scope = app.Services.CreateAsyncScope();
var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class AppSecureJwtDataFormat(AppSettings appSettings, TokenValidationPara
}
catch (Exception ex)
{
if (BuildConfiguration.IsDebug())
if (AppEnvironment.IsDevelopment())
{
Console.WriteLine(ex); // since we do not have access to any logger at this point!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ private static void ConfigureServices(this WebApplicationBuilder builder)

var services = builder.Services;
var configuration = builder.Configuration;
var env = builder.Environment;

AddBlazor(builder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ public static async Task Main(string[] args)
ContentRootPath = AppContext.BaseDirectory
});

AppEnvironment.Name = builder.Environment.EnvironmentName;

builder.Configuration.AddClientConfigurations();

// The following line (using the * in the URL), allows the emulators and mobile devices to access the app using the host IP address.
if (BuildConfiguration.IsDebug() && OperatingSystem.IsWindows())
if (AppEnvironment.IsDevelopment() && OperatingSystem.IsWindows())
{
builder.WebHost.UseUrls("http://localhost:5030", "http://*:5030");
}
Expand All @@ -26,7 +28,7 @@ public static async Task Main(string[] args)

var app = builder.Build();

if (BuildConfiguration.IsDebug())
if (AppEnvironment.IsDevelopment())
{
await using var scope = app.Services.CreateAsyncScope();
var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,10 @@ public static void AddSharedConfigurations(this IConfigurationBuilder builder)
var assembly = Assembly.Load("Boilerplate.Shared");
builder.AddJsonStream(assembly.GetManifestResourceStream("Boilerplate.Shared.appsettings.json")!);

if (BuildConfiguration.IsDebug())
var settings = assembly.GetManifestResourceStream($"Boilerplate.Shared.appsettings.{AppEnvironment.Name}.json");
if (settings is not null)
{
var settings = assembly.GetManifestResourceStream("Boilerplate.Shared.appsettings.Debug.json");
if (settings is not null)
{
builder.AddJsonStream(settings);
}
}
else
{
var settings = assembly.GetManifestResourceStream("Boilerplate.Shared.appsettings.Release.json");
if (settings is not null)
{
builder.AddJsonStream(settings);
}
builder.AddJsonStream(settings);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static string GetServerAddress(this IConfiguration configuration)
{
var serverAddress = configuration.GetValue("ServerAddress", defaultValue: "/")!;

if (BuildConfiguration.IsDebug() &&
if (AppEnvironment.IsDevelopment() &&
serverAddress.Contains("localhost", StringComparison.InvariantCultureIgnoreCase) &&
OperatingSystem.IsAndroid())
{
Expand Down
Loading

0 comments on commit 2fa221b

Please sign in to comment.