Skip to content

Commit

Permalink
Trim produced assemblies
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed May 20, 2024
1 parent e5bac8e commit 0d69d56
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- osx-arm64
- osx-x64

runs-on: ubuntu-latest
runs-on: ${{ startsWith(matrix.rid, 'win-') && 'windows-latest' || startsWith(matrix.rid, 'osx-') && 'macos-latest' || 'ubuntu-latest' }}
timeout-minutes: 10

permissions:
Expand Down
37 changes: 22 additions & 15 deletions YoutubeDownloader/Framework/ViewManager.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
using System;
using Avalonia.Controls;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using YoutubeDownloader.ViewModels;
using YoutubeDownloader.ViewModels.Components;
using YoutubeDownloader.ViewModels.Dialogs;
using YoutubeDownloader.Views;
using YoutubeDownloader.Views.Components;
using YoutubeDownloader.Views.Dialogs;

namespace YoutubeDownloader.Framework;

public partial class ViewManager
{
private Control? TryCreateView(ViewModelBase viewModel) =>
viewModel switch
{
MainViewModel => new MainView(),
DashboardViewModel => new DashboardView(),
AuthSetupViewModel => new AuthSetupView(),
DownloadMultipleSetupViewModel => new DownloadMultipleSetupView(),
DownloadSingleSetupViewModel => new DownloadSingleSetupView(),
MessageBoxViewModel => new MessageBoxView(),
SettingsViewModel => new SettingsView(),
_ => null
};

public Control? TryBindView(ViewModelBase viewModel)
{
var name = viewModel
.GetType()
.FullName?.Replace("ViewModel", "View", StringComparison.Ordinal);

if (string.IsNullOrWhiteSpace(name))
return null;

var type = Type.GetType(name);
if (type is null)
return null;

if (Activator.CreateInstance(type) is not Control view)
var view = TryCreateView(viewModel);
if (view is null)
return null;

view.DataContext ??= viewModel;

return view;
}
}
Expand Down
3 changes: 3 additions & 0 deletions YoutubeDownloader/Services/SettingsService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net;
using System.Text.Json;
Expand Down Expand Up @@ -48,6 +49,8 @@ public partial class SettingsService()

[ObservableProperty]
[property: JsonConverter(typeof(ContainerJsonConverter))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Container))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ContainerJsonConverter))]
private Container _lastContainer = Container.Mp4;

[ObservableProperty]
Expand Down
7 changes: 2 additions & 5 deletions YoutubeDownloader/Views/Components/DashboardView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
xmlns:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:materialStyles="clr-namespace:Material.Styles.Controls;assembly=Material.Styles"
x:Name="UserControl"
x:DataType="components:DashboardViewModel"
Loaded="UserControl_OnLoaded">
<Design.DataContext>
<components:DashboardViewModel />
</Design.DataContext>

<DockPanel>
<!-- Header -->
<StackPanel
Expand Down Expand Up @@ -315,7 +312,7 @@
<Button
Padding="4"
VerticalAlignment="Center"
Command="{Binding $parent[UserControl].DataContext.RestartDownloadCommand}"
Command="{Binding $parent[UserControl].((components:DashboardViewModel)DataContext).RestartDownloadCommand}"
CommandParameter="{Binding}"
IsVisible="{Binding IsCanceledOrFailed}"
Theme="{DynamicResource MaterialFlatButton}"
Expand Down
7 changes: 2 additions & 5 deletions YoutubeDownloader/Views/Dialogs/AuthSetupView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
xmlns:dialogs="clr-namespace:YoutubeDownloader.ViewModels.Dialogs"
xmlns:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
Height="450"
MinWidth="450">
<Design.DataContext>
<dialogs:AuthSetupViewModel />
</Design.DataContext>

MinWidth="450"
x:DataType="dialogs:AuthSetupViewModel">
<Grid RowDefinitions="Auto,*,Auto">
<!-- Title -->
<TextBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
xmlns:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
x:Name="UserControl"
Width="500"
x:DataType="dialogs:DownloadMultipleSetupViewModel"
Loaded="UserControl_OnLoaded">
<Design.DataContext>
<dialogs:DownloadMultipleSetupViewModel />
</Design.DataContext>

<Grid RowDefinitions="Auto,*,Auto,Auto">
<!-- Title -->
<TextBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
xmlns:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
x:Name="UserControl"
Width="500"
x:DataType="dialogs:DownloadSingleSetupViewModel"
Loaded="UserControl_OnLoaded">
<Design.DataContext>
<dialogs:DownloadSingleSetupViewModel />
</Design.DataContext>

<Grid RowDefinitions="Auto,*,Auto,Auto">
<!-- Info -->
<StackPanel
Expand Down
7 changes: 2 additions & 5 deletions YoutubeDownloader/Views/Dialogs/MessageBoxView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dialogs="clr-namespace:YoutubeDownloader.ViewModels.Dialogs"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
Width="500">
<Design.DataContext>
<dialogs:MessageBoxViewModel />
</Design.DataContext>

Width="500"
x:DataType="dialogs:MessageBoxViewModel">
<Grid RowDefinitions="Auto,*,Auto">
<!-- Title -->
<TextBlock
Expand Down
7 changes: 2 additions & 5 deletions YoutubeDownloader/Views/Dialogs/SettingsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dialogs="clr-namespace:YoutubeDownloader.ViewModels.Dialogs"
Width="380">
<Design.DataContext>
<dialogs:SettingsViewModel />
</Design.DataContext>

Width="380"
x:DataType="dialogs:SettingsViewModel">
<Grid RowDefinitions="Auto,*,Auto">
<TextBlock
Grid.Row="0"
Expand Down
5 changes: 1 addition & 4 deletions YoutubeDownloader/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
Height="620"
MinWidth="600"
MinHeight="400"
x:DataType="viewModels:MainViewModel"
Icon="/favicon.ico"
RenderOptions.BitmapInterpolationMode="HighQuality"
WindowStartupLocation="CenterScreen">
<Design.DataContext>
<viewModels:MainViewModel />
</Design.DataContext>

<!-- Hack: dialog host animations mess up webview positioning, so need to disable them -->
<dialogHostAvalonia:DialogHost
x:Name="DialogHost"
Expand Down
14 changes: 12 additions & 2 deletions YoutubeDownloader/YoutubeDownloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@
<OutputType>WinExe</OutputType>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationIcon>..\favicon.ico</ApplicationIcon>

<!-- App manifest is required to embed native windows, namely the WebBrowser control -->
<ApplicationManifest>app.manifest</ApplicationManifest>
<PublishTrimmed>true</PublishTrimmed>
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
<NoWarn>$(NoWarn);IL2104</NoWarn>
</PropertyGroup>

<!-- Avalonia-related settings -->
<PropertyGroup>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<!-- Warnings not valid when using compiled bindings -->
<NoWarn>$(NoWarn);IL2026</NoWarn>
<!-- Warnings about Material.Avalonia having peer dependencies -->
<NoWarn>$(NoWarn);IL2036</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 0d69d56

Please sign in to comment.