Skip to content

Commit

Permalink
fixes Download bar and window buttons (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bod9001 authored Dec 13, 2024
1 parent 16b7292 commit 1c0be75
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
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 Down Expand Up @@ -130,18 +132,19 @@ public async Task CheckAndDownloadLatestVersion(Download Download)

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 @@ public async Task CheckAndDownloadLatestVersion(Download Download)

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 @@ private void ExtractTar(Stream tarStream, string destinationPath)
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

0 comments on commit 1c0be75

Please sign in to comment.