Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes Download bar for TTS and window buttons #232

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions UnitystationLauncher/Services/TTSService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
using System.IO;
using System.IO.Compression;
using System.Net.Http;
using System.Reactive.Concurrency;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Controls.Shapes;
using Mono.Unix;
using ReactiveUI;
using Serilog;
using SharpCompress.Archives;
using SharpCompress.Archives.Tar;
Expand All @@ -26,7 +28,7 @@

public class TTSService : ITTSService
{
private static string _nameConfig = @"CodeScanList.json";

Check warning on line 31 in UnitystationLauncher/Services/TTSService.cs

View workflow job for this annotation

GitHub Actions / Build Windows

The field 'TTSService._nameConfig' is assigned but its value is never used

Check warning on line 31 in UnitystationLauncher/Services/TTSService.cs

View workflow job for this annotation

GitHub Actions / Build Linux Flatpak

The field 'TTSService._nameConfig' is assigned but its value is never used

Check warning on line 31 in UnitystationLauncher/Services/TTSService.cs

View workflow job for this annotation

GitHub Actions / Build Linux

The field 'TTSService._nameConfig' is assigned but its value is never used

Check warning on line 31 in UnitystationLauncher/Services/TTSService.cs

View workflow job for this annotation

GitHub Actions / Build MacOS

The field 'TTSService._nameConfig' is assigned but its value is never used

Check warning on line 31 in UnitystationLauncher/Services/TTSService.cs

View workflow job for this annotation

GitHub Actions / test

The field 'TTSService._nameConfig' is assigned but its value is never used

private readonly HttpClient _httpClient;

Expand Down Expand Up @@ -130,18 +132,19 @@

Download.Active = true;
Download.DownloadState = DownloadState.InProgress;

HttpResponseMessage request = await _httpClient.GetAsync(ApiUrls.TTSFiles + "/" + zip,
HttpCompletionOption.ResponseHeadersRead);

Download.Size = request.Content.Headers.ContentLength ??
throw new ContentLengthNullException(ApiUrls.TTSFiles + "/" + zip);
using Stream responseStream = await request.Content.ReadAsStreamAsync();
Log.Information("Download connection established");
await using ProgressStream progressStream = new(responseStream);
using IDisposable logProgressDisposable = InstallationService.LogProgress(progressStream, Download);

using IDisposable progressDisposable =
progressStream.Progress.Subscribe(p => { Download.Downloaded = p; });
Download.Size = request.Content.Headers.ContentLength ??
throw new ContentLengthNullException(ApiUrls.TTSFiles + "/" + zip);

using IDisposable progressDisposable = progressStream.Progress.Subscribe(p => { Download.Downloaded = p; });

await Task.Run(() => ExtractTo(progressStream, LocalVersion, Download));
}
Expand All @@ -157,18 +160,20 @@

private void ExtractTo(Stream progressStream, string LocalVersion, Download Download)
{
Download.DownloadState = DownloadState.Extracting;

switch (_environmentService.GetCurrentEnvironment())
{
case CurrentEnvironment.WindowsStandalone:
{
ZipArchive archive = new(progressStream);
Download.DownloadState = DownloadState.Extracting;
archive.ExtractToDirectory(LocalVersion, true);
break;
}
case CurrentEnvironment.LinuxStandalone or CurrentEnvironment.LinuxFlatpak:
{
using var decompressedStream = DecompressXz(progressStream); // Decompress XZ stream to get .tar

ExtractTar(decompressedStream, LocalVersion);
break;
}
Expand Down Expand Up @@ -220,11 +225,13 @@
return _environmentService.GetCurrentEnvironment() switch
{
CurrentEnvironment.WindowsStandalone
=> (Path.Combine(installationBasePath, "tts", "python-3.10.11.amd64", "python.exe"), Path.Combine(installationBasePath, "tts", "scripts")),
=> (Path.Combine(installationBasePath, "tts", "python-3.10.11.amd64", "python.exe"),
Path.Combine(installationBasePath, "tts", "scripts")),
CurrentEnvironment.MacOsStandalone
=> throw new NotImplementedException("tts Mac Support not implemented"),
CurrentEnvironment.LinuxStandalone or CurrentEnvironment.LinuxFlatpak
=> (Path.Combine(installationBasePath, "tts", "bin", "python"), Path.Combine(installationBasePath, "tts", "bin")),
=> (Path.Combine(installationBasePath, "tts", "bin", "python"),
Path.Combine(installationBasePath, "tts", "bin")),
_ => (null, null)
};
}
Expand Down
30 changes: 15 additions & 15 deletions UnitystationLauncher/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
MinWidth="800"
MinHeight="555"
Background="#19212c"
x:DataType="viewModels:MainWindowViewModel">

x:DataType="viewModels:MainWindowViewModel"
SystemDecorations="None">

<Design.DataContext>
<viewModels:MainWindowViewModel/>
<viewModels:MainWindowViewModel />
</Design.DataContext>
<Grid>
<Grid.RowDefinitions>
Expand All @@ -40,13 +41,13 @@
</TextBlock>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Width="40" Name="MinimizeButton" ToolTip.Tip="Minimize">
<!-- Minimize Button -->
<Button Width="50" Height="30" Name="MinimizeButton" ToolTip.Tip="Minimize">
<Button.Styles>
<Style Selector="Button">
<Setter Property="BorderThickness" Value="0" />
</Style>
<Style
Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="#44AAAAAA" />
</Style>
<Style
Expand All @@ -59,16 +60,14 @@
Fill="White"
Data="M2048 1229v-205h-2048v205h2048z" />
</Button>
<Button Width="40" Name="MaximizeButton">
<ToolTip.Tip>
<ToolTip Content="{Binding MaximizeToolTip}" />
</ToolTip.Tip>

<!-- Maximize/Restore Button -->
<Button Width="50" Height="30" Name="MaximizeButton" ToolTip.Tip="Maximize">
<Button.Styles>
<Style Selector="Button">
<Setter Property="BorderThickness" Value="0" />
</Style>
<Style
Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="#44AAAAAA" />
</Style>
<Style
Expand All @@ -81,13 +80,14 @@
Fill="#dedede"
Data="{Binding MaximizeIcon}" />
</Button>
<Button Width="40" Name="CloseButton" ToolTip.Tip="Close">

<!-- Close Button -->
<Button Width="50" Height="30" Name="CloseButton" ToolTip.Tip="Close">
<Button.Styles>
<Style Selector="Button">
<Setter Property="BorderThickness" Value="0" />
</Style>
<Style
Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="#99810a0f" />
</Style>
<Style
Expand Down
Loading