Skip to content

Commit

Permalink
Merge branch 'release/3.0.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
theofanis committed Nov 25, 2024
2 parents 81d8993 + 2fbab3a commit aea319c
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 25 deletions.
15 changes: 12 additions & 3 deletions src/BolWallet/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace BolWallet;

public partial class App : Application, IRecipient<TargetNetworkChangedMessage>
public partial class App : Application, IRecipient<TargetNetworkChangedMessage>, IRecipient<DisplayErrorMessage>
{
private readonly INetworkPreferences _networkPreferences;
private ILogExtractor _logExtractor = null!;
Expand All @@ -14,7 +14,7 @@ public App(INetworkPreferences networkPreferences, IMessenger messenger)
_networkPreferences = networkPreferences;
InitializeComponent();

messenger.Register(this);
messenger.RegisterAll(this);
UserAppTheme = AppTheme.Light;

#if WINDOWS
Expand Down Expand Up @@ -84,5 +84,14 @@ public void Receive(TargetNetworkChangedMessage message)

private string CreateWindowTitle() => _networkPreferences.IsMainNet
? Constants.AppName
: $"{Constants.AppName} ({_networkPreferences.Name})";
: $"{Constants.AppName} ({_networkPreferences.Name})";

void IRecipient<DisplayErrorMessage>.Receive(DisplayErrorMessage message)
{
var text = message.Exception is null
? message.Message
: $"{message.Message}{Environment.NewLine}{Environment.NewLine}{message.Exception.ToString()}";

Current.Windows[0].Page.DisplayAlert("Error", text, "OK");
}
}
14 changes: 10 additions & 4 deletions src/BolWallet/BolWallet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>BolWallet</RootNamespace>
<UseMaui>true</UseMaui>
<MauiVersion>9.0.0</MauiVersion>
<MauiVersion>9.0.10</MauiVersion>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>

Expand All @@ -30,9 +30,10 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">android-arm;android-arm64;android-x86;android-x64</RuntimeIdentifiers> <DefaultLanguage>en-US</DefaultLanguage>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">android-arm;android-arm64;android-x86;android-x64</RuntimeIdentifiers>
<DefaultLanguage>en-US</DefaultLanguage>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net9.0-android|AnyCPU'">
<WarningsAsErrors />
</PropertyGroup>
Expand Down Expand Up @@ -78,8 +79,13 @@
<CodesignEntitlements>Platforms\MacCatalyst\Entitlements.plist</CodesignEntitlements>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net9.0-windows10.0.19041.0|AnyCPU'">
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows' and '$(Configuration)' == 'Release'">
<WarningsAsErrors />
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
</PropertyGroup>

<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows' and '$(RuntimeIdentifierOverride)' != ''">
<RuntimeIdentifier>$(RuntimeIdentifierOverride)</RuntimeIdentifier>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 5 additions & 3 deletions src/BolWallet/Extensions/LoggingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.Extensions.DependencyInjection;

public static class LoggingExtensions
{
private const long MaxFileSizeLimitBytes = 1048576L;
private const long MaxFileSizeLimitBytes = 10_000_000;

public static IServiceCollection ConfigureSerilog(this IServiceCollection services)
{
Expand All @@ -35,10 +35,12 @@ public static IServiceCollection ConfigureSerilog(this IServiceCollection servic
outputTemplate,
filePath,
encoding: Encoding.UTF8,
flushToDiskInterval: TimeSpan.FromSeconds(1),
shared: true,
fileSizeLimitBytes: MaxFileSizeLimitBytes,
rollingInterval: RollingInterval.Day,
rollOnFileSizeLimit: true)
rollOnFileSizeLimit: true,
retainedFileCountLimit: 15,
retainedFileTimeLimit: TimeSpan.FromDays(15))
.WriteTo.Console(outputTemplate)
.CreateLogger();

Expand Down
17 changes: 17 additions & 0 deletions src/BolWallet/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Maui.LifecycleEvents;
using MudBlazor.Services;
using Plugin.Maui.Audio;
using Country = BolWallet.Models.Country;
Expand All @@ -28,6 +29,18 @@ public static MauiApp CreateMauiApp()
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit()
.ConfigureLifecycleEvents(AppLifeCycle =>
{
#if WINDOWS
AppLifeCycle.AddWindows(windows =>
{
windows.OnClosed((app, e) =>
{
Environment.Exit(0);
});
});
#endif
})
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
Expand All @@ -37,6 +50,9 @@ public static MauiApp CreateMauiApp()

builder.Services.AddSingleton<IAppVersion, AppVersion>();
builder.Services.AddMauiBlazorWebView();
#if DEBUG
builder.Services.AddBlazorWebViewDeveloperTools();
#endif

builder.Services.AddMudServices();

Expand Down Expand Up @@ -69,6 +85,7 @@ public static MauiApp CreateMauiApp()
RegisterPermissionServices(services);

services.AddSingleton(MediaPicker.Default);
builder.Services.AddSingleton<IFileSystem>(FileSystem.Current);
builder.Services.AddSingleton<IFileSaver>(FileSaver.Default);

services.AddSingleton<IDeviceDisplay>(DeviceDisplay.Current);
Expand Down
3 changes: 3 additions & 0 deletions src/BolWallet/Models/Messages/DisplayErrorMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace BolWallet.Models.Messages;

internal record DisplayErrorMessage(string Message, Exception Exception = null);
2 changes: 1 addition & 1 deletion src/BolWallet/Platforms/Windows/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">

<Identity Name="maui-package-name-placeholder" Publisher="CN=User Name" Version="3.0.0.0" />
<Identity Name="maui-package-name-placeholder" Publisher="CN=User Name" Version="3.0.0.1" />

<mp:PhoneIdentity PhoneProductId="91ADD539-7E17-4B6C-9E6D-310A654419CD" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

Expand Down
93 changes: 79 additions & 14 deletions src/BolWallet/Services/LogExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,111 @@
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Storage;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.Logging;

namespace BolWallet.Services;

public class LogExtractor : ILogExtractor, IRecipient<SaveLogfileMessage>
{
private readonly IMessenger _messenger;
private readonly TimeProvider _timeProvider;
private readonly IFileSystem _fileSystem;
private readonly IFileSaver _fileSaver;
private readonly ILogger _logger;

public LogExtractor(
IMessenger messenger,
TimeProvider timeProvider,
IFileSaver fileSaver)
IFileSystem fileSystem,
IFileSaver fileSaver,
ILogger<LogExtractor> logger)
{
messenger.Register<SaveLogfileMessage>(this);

_messenger = messenger;
_timeProvider = timeProvider;
_fileSystem = fileSystem;
_fileSaver = fileSaver;
_logger = logger;
}

public async Task ExtractLog(CancellationToken token = default)
{
var zipFileName = $"BolWalletLogs_{_timeProvider.GetUtcNow():yyyyMMddHHmmss}.zip";
var logDirectory = Path.Combine(FileSystem.AppDataDirectory,
"Logs",
AppInfo.Current.Name,
AppInfo.Current.VersionString);

using var stream = new MemoryStream();
ZipFile.CreateFromDirectory(logDirectory, stream);

var result = await _fileSaver.SaveAsync(zipFileName, stream, token);

if (result.IsSuccessful)
var now = _timeProvider.GetUtcNow();

var zipFileName = $"BolWalletLogs_{now:yyyyMMddHHmmss}.zip";
var zipFilePath = Path.Combine(_fileSystem.CacheDirectory, zipFileName);
DeleteFileIfExists(zipFilePath);

var tempLog = $"BolWalletLogs_Temp_{now:yyyyMMddHHmmss}.log";
var tempLogPath = Path.Combine(_fileSystem.CacheDirectory, tempLog);
DeleteFileIfExists(tempLogPath);

try
{
var logDirectory = Path.Combine(FileSystem.AppDataDirectory,
"Logs",
AppInfo.Current.Name,
AppInfo.Current.VersionString);

using var stream = new MemoryStream();

using (var zip = ZipFile.Open(zipFilePath, ZipArchiveMode.Create))
{
foreach (var file in Directory.GetFiles(logDirectory))
{
try
{
zip.CreateEntryFromFile(file, Path.GetFileName(file));
}
catch
{
File.Copy(file, tempLogPath);
zip.CreateEntryFromFile(tempLogPath, Path.GetFileName(file));
}
}
}

using var fileStream = File.OpenRead(zipFilePath);
var result = await _fileSaver.SaveAsync(zipFileName, fileStream, token);
if (result.IsSuccessful)
{
await Toast.Make($"File '{zipFileName}' saved successfully!").Show(token);
return;
}

if (result.FilePath == null)
{
_logger.LogInformation("Log extraction cancelled by user.");
return;
}

_messenger.Send(new DisplayErrorMessage("An error occurred while saving the logfile.", result.Exception));
}
catch (Exception ex)
{
_logger.LogError(ex, "Error extracting logs...");
_messenger.Send(new DisplayErrorMessage("An error occurred while saving the logfile.", ex));
}
finally
{
await Toast.Make($"File '{zipFileName}' saved successfully!").Show(token);
DeleteFileIfExists(zipFilePath);
DeleteFileIfExists(tempLogPath);
}
}

public void Receive(SaveLogfileMessage message)
{
_logger.LogInformation("Log extraction requested...");

MainThread.BeginInvokeOnMainThread(() => _ = ExtractLog());
}

private static void DeleteFileIfExists(string filePath)
{
if (File.Exists(filePath))
{
File.Delete(filePath);
}
}
}
6 changes: 6 additions & 0 deletions src/scripts/windows/publish-side-load.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)][string]$t
)

dotnet publish .\..\..\BolWallet\BolWallet.csproj -f net9.0-windows10.0.19041.0 -c Release --self-contained -p:RuntimeIdentifierOverride=win10-x64 -p:PackageCertificateThumbprint=$t

0 comments on commit aea319c

Please sign in to comment.