add copy to clipboard button

This commit is contained in:
IsWaffle 2024-06-09 16:14:57 -04:00
parent 074ac6e826
commit 2110b185d2
5 changed files with 59 additions and 11 deletions

View File

@ -20,6 +20,7 @@
<entry key="SPTInstaller/CustomControls/UpdateInfoCard.axaml" value="SPTInstaller/SPTInstaller.csproj" /> <entry key="SPTInstaller/CustomControls/UpdateInfoCard.axaml" value="SPTInstaller/SPTInstaller.csproj" />
<entry key="SPTInstaller/Views/DetailedPreChecksView.axaml" value="SPTInstaller/SPTInstaller.csproj" /> <entry key="SPTInstaller/Views/DetailedPreChecksView.axaml" value="SPTInstaller/SPTInstaller.csproj" />
<entry key="SPTInstaller/Views/MainWindow.axaml" value="SPTInstaller/SPTInstaller.csproj" /> <entry key="SPTInstaller/Views/MainWindow.axaml" value="SPTInstaller/SPTInstaller.csproj" />
<entry key="SPTInstaller/Views/MessageView.axaml" value="SPTInstaller/SPTInstaller.csproj" />
<entry key="SPTInstaller/Views/PreChecksView.axaml" value="SPTInstaller/SPTInstaller.csproj" /> <entry key="SPTInstaller/Views/PreChecksView.axaml" value="SPTInstaller/SPTInstaller.csproj" />
</map> </map>
</option> </option>

View File

@ -12,7 +12,7 @@ namespace SPTInstaller;
public partial class App : Application public partial class App : Application
{ {
private readonly string _logPath = Path.Join(Environment.CurrentDirectory, "spt-installer_.log"); public static string LogPath = Path.Join(Environment.CurrentDirectory, "spt-installer.log");
public override void Initialize() public override void Initialize()
{ {
@ -21,9 +21,8 @@ public partial class App : Application
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information() .MinimumLevel.Information()
.WriteTo .WriteTo
.File(path: _logPath, .File(path: LogPath,
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information, restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information)
rollingInterval: RollingInterval.Day)
.CreateLogger(); .CreateLogger();
RxApp.DefaultExceptionHandler = Observer.Create<Exception>((exception) => RxApp.DefaultExceptionHandler = Observer.Create<Exception>((exception) =>
@ -42,9 +41,8 @@ public partial class App : Application
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug() .MinimumLevel.Debug()
.WriteTo .WriteTo
.File(path: _logPath, .File(path: LogPath,
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Debug, restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Debug)
rollingInterval: RollingInterval.Day)
.CreateLogger(); .CreateLogger();
System.Diagnostics.Trace.Listeners.Add(new SerilogTraceListener.SerilogTraceListener()); System.Diagnostics.Trace.Listeners.Add(new SerilogTraceListener.SerilogTraceListener());

View File

@ -10,8 +10,8 @@
<PackageIcon>icon.ico</PackageIcon> <PackageIcon>icon.ico</PackageIcon>
<ApplicationIcon>Assets\spt_installer.ico</ApplicationIcon> <ApplicationIcon>Assets\spt_installer.ico</ApplicationIcon>
<Configurations>Debug;Release;TEST</Configurations> <Configurations>Debug;Release;TEST</Configurations>
<AssemblyVersion>2.70</AssemblyVersion> <AssemblyVersion>2.71</AssemblyVersion>
<FileVersion>2.70</FileVersion> <FileVersion>2.71</FileVersion>
<Company>SPT</Company> <Company>SPT</Company>
</PropertyGroup> </PropertyGroup>

View File

@ -6,6 +6,9 @@ using SPTInstaller.Helpers;
using SPTInstaller.Interfaces; using SPTInstaller.Interfaces;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Input;
using Avalonia.Platform.Storage;
namespace SPTInstaller.ViewModels; namespace SPTInstaller.ViewModels;
@ -43,6 +46,47 @@ public class MessageViewModel : ViewModelBase
set => this.RaiseAndSetIfChanged(ref _cacheInfoText, value); set => this.RaiseAndSetIfChanged(ref _cacheInfoText, value);
} }
private string _clipCommandText;
public string ClipCommandText
{
get => _clipCommandText;
set => this.RaiseAndSetIfChanged(ref _clipCommandText, value);
}
public ICommand CopyLogFileToClipboard => ReactiveCommand.CreateFromTask(async () =>
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
try
{
if (desktop.MainWindow?.Clipboard == null)
{
ClipCommandText = "Could not get clipboard :(";
return;
}
var dataObject = new DataObject();
var logFile = await desktop.MainWindow.StorageProvider.TryGetFileFromPathAsync(App.LogPath);
if (logFile == null)
{
ClipCommandText = "Could not get log file :(";
return;
}
dataObject.Set(DataFormats.Files, new[] {logFile});
await desktop.MainWindow.Clipboard.SetDataObjectAsync(dataObject);
ClipCommandText = "Copied!";
}
catch (Exception ex)
{
ClipCommandText = ex.Message;
}
}
});
private StatusSpinner.SpinnerState _cacheCheckState; private StatusSpinner.SpinnerState _cacheCheckState;
public StatusSpinner.SpinnerState CacheCheckState public StatusSpinner.SpinnerState CacheCheckState
@ -64,6 +108,7 @@ public class MessageViewModel : ViewModelBase
{ {
ShowCloseButton = showCloseButton; ShowCloseButton = showCloseButton;
Message = result.Message; Message = result.Message;
ClipCommandText = "Copy installer log to clipboard";
Task.Run(() => Task.Run(() =>
{ {

View File

@ -15,7 +15,7 @@
</UserControl.Styles> </UserControl.Styles>
<Grid ColumnDefinitions="*,AUTO,*" RowDefinitions="*,AUTO,20,AUTO,*" <Grid ColumnDefinitions="*,AUTO,*" RowDefinitions="*,AUTO,20,AUTO,20,Auto,*"
Classes.error="{Binding HasErrors}"> Classes.error="{Binding HasErrors}">
<Label Grid.Column="1" Grid.Row="1" <Label Grid.Column="1" Grid.Row="1"
@ -35,7 +35,11 @@
VerticalContentAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
Padding="20 10" /> Padding="20 10" />
<cc:CacheInfo Grid.Row="4" Grid.ColumnSpan="3" Padding="10" Margin="10 0 0 0" <Button Grid.Row="5" Grid.Column="1" Classes="link" Content="{Binding ClipCommandText}"
Command="{Binding CopyLogFileToClipboard}" HorizontalAlignment="Center" VerticalAlignment="Center"
/>
<cc:CacheInfo Grid.Row="6" Grid.ColumnSpan="3" Padding="10" Margin="10 0 0 0"
VerticalAlignment="Bottom" VerticalAlignment="Bottom"
InfoText="{Binding CacheInfoText}" State="{Binding CacheCheckState}" /> InfoText="{Binding CacheInfoText}" State="{Binding CacheCheckState}" />
</Grid> </Grid>