-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor after Avalonia migration (#430)
- Loading branch information
Showing
75 changed files
with
1,876 additions
and
1,899 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CSharpier.MsBuild" Version="0.27.0" PrivateAssets="all" /> | ||
<PackageReference Include="CSharpier.MsBuild" Version="0.28.0" PrivateAssets="all" /> | ||
<PackageReference Include="Gress" Version="2.1.1" /> | ||
<PackageReference Include="JsonExtensions" Version="1.2.0" /> | ||
<PackageReference Include="Lazy.Fody" Version="1.11.0" PrivateAssets="all" /> | ||
<PackageReference Include="TagLibSharp" Version="2.3.0" /> | ||
<PackageReference Include="YoutubeExplode" Version="6.3.12" /> | ||
<PackageReference Include="YoutubeExplode.Converter" Version="6.3.12" /> | ||
<PackageReference Include="YoutubeExplode" Version="6.3.13" /> | ||
<PackageReference Include="YoutubeExplode.Converter" Version="6.3.13" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<Application | ||
x:Class="YoutubeDownloader.App" | ||
xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:dialogHostAvalonia="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia" | ||
xmlns:framework="clr-namespace:YoutubeDownloader.Framework" | ||
xmlns:materialAssists="clr-namespace:Material.Styles.Assists;assembly=Material.Styles" | ||
xmlns:materialControls="clr-namespace:Material.Styles.Controls;assembly=Material.Styles" | ||
xmlns:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia" | ||
xmlns:materialStyles="clr-namespace:Material.Styles.Themes;assembly=Material.Styles"> | ||
<Application.DataTemplates> | ||
<framework:ViewManager /> | ||
</Application.DataTemplates> | ||
|
||
<Application.Styles> | ||
<materialStyles:MaterialTheme /> | ||
<materialIcons:MaterialIconStyles /> | ||
<dialogHostAvalonia:DialogHostStyles /> | ||
|
||
<!-- Combo box --> | ||
<Style Selector="ComboBox"> | ||
<Setter Property="FontSize" Value="14" /> | ||
|
||
<Style Selector="^ /template/ Panel#PART_RootPanel"> | ||
<Setter Property="Height" Value="22" /> | ||
</Style> | ||
</Style> | ||
|
||
<!-- Context menu --> | ||
<Style Selector="ContextMenu"> | ||
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDividerBrush}" /> | ||
<Setter Property="BorderThickness" Value="1" /> | ||
</Style> | ||
|
||
<!-- Data grid --> | ||
<Style Selector="DataGrid"> | ||
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDividerBrush}" /> | ||
<Setter Property="AutoGenerateColumns" Value="False" /> | ||
<Setter Property="CanUserReorderColumns" Value="False" /> | ||
<Setter Property="CanUserResizeColumns" Value="False" /> | ||
<Setter Property="CanUserSortColumns" Value="True" /> | ||
<Setter Property="IsReadOnly" Value="True" /> | ||
<Setter Property="SelectionMode" Value="Single" /> | ||
</Style> | ||
|
||
<Style Selector="DataGridColumnHeader"> | ||
<Setter Property="AreSeparatorsVisible" Value="False" /> | ||
</Style> | ||
|
||
<Style Selector="DataGridRow"> | ||
<Style Selector="^:selected /template/ Rectangle#BackgroundRectangle"> | ||
<Setter Property="IsVisible" Value="False" /> | ||
</Style> | ||
<Style Selector="^:pointerover /template/ Rectangle#BackgroundRectangle"> | ||
<Setter Property="IsVisible" Value="False" /> | ||
</Style> | ||
</Style> | ||
|
||
<!-- Dialog host --> | ||
<Style Selector="dialogHostAvalonia|DialogHost"> | ||
<Setter Property="DialogMargin" Value="0" /> | ||
</Style> | ||
|
||
<Style Selector="dialogHostAvalonia|DialogOverlayPopupHost"> | ||
<Setter Property="Margin" Value="48" /> | ||
</Style> | ||
|
||
<!-- Snack bar host --> | ||
<Style Selector="materialControls|SnackbarHost"> | ||
<Setter Property="SnackbarHorizontalAlignment" Value="Stretch" /> | ||
<Setter Property="VerticalContentAlignment" Value="Center" /> | ||
|
||
<Style Selector="^ /template/ ItemsControl#PART_SnackbarHostItemsContainer materialControls|Card"> | ||
<Setter Property="Background" Value="{DynamicResource MaterialDarkBackgroundBrush}" /> | ||
<Setter Property="Foreground" Value="{DynamicResource MaterialDarkForegroundBrush}" /> | ||
</Style> | ||
|
||
<Style Selector="^ /template/ ItemsControl#PART_SnackbarHostItemsContainer Button"> | ||
<Setter Property="Foreground" Value="{DynamicResource SecondaryHueMidBrush}" /> | ||
</Style> | ||
</Style> | ||
|
||
<!-- Progress bar --> | ||
<Style Selector="ProgressBar"> | ||
<Setter Property="Minimum" Value="0" /> | ||
<Setter Property="Maximum" Value="1" /> | ||
<Setter Property="Foreground" Value="{DynamicResource MaterialSecondaryMidBrush}" /> | ||
<Setter Property="materialAssists:TransitionAssist.DisableTransitions" Value="True" /> | ||
|
||
<Style Selector="^:horizontal"> | ||
<Setter Property="MinHeight" Value="0" /> | ||
</Style> | ||
</Style> | ||
|
||
<!-- Slider --> | ||
<Style Selector="Slider"> | ||
<Style Selector="^ /template/ ProgressBar#PART_ProgressLayer"> | ||
<Style Selector="^:horizontal"> | ||
<Style Selector="^ Panel#PART_InnerPanel"> | ||
<Setter Property="Height" Value="2" /> | ||
|
||
<Style Selector="^ Border#PART_InactiveState"> | ||
<Setter Property="Margin" Value="0" /> | ||
<Setter Property="Height" Value="2" /> | ||
</Style> | ||
|
||
<Style Selector="^ Border#PART_Indicator"> | ||
<Setter Property="Margin" Value="0" /> | ||
</Style> | ||
</Style> | ||
</Style> | ||
</Style> | ||
|
||
<Style Selector="^ /template/ Track#PART_Track"> | ||
<Style Selector="^:horizontal"> | ||
<Setter Property="Margin" Value="4,0" /> | ||
</Style> | ||
|
||
<Style Selector="^ Border#PART_HoverEffect"> | ||
<Setter Property="Width" Value="24" /> | ||
<Setter Property="Height" Value="24" /> | ||
</Style> | ||
|
||
<Style Selector="^ Border#PART_ThumbGrip"> | ||
<Setter Property="Width" Value="12" /> | ||
<Setter Property="Height" Value="12" /> | ||
</Style> | ||
</Style> | ||
</Style> | ||
|
||
<!-- Text box --> | ||
<Style Selector="TextBox"> | ||
<Setter Property="Height" Value="22" /> | ||
<Setter Property="FontSize" Value="14" /> | ||
|
||
<Style Selector="^ /template/ Panel#PART_TextFieldPanel"> | ||
<Setter Property="MinHeight" Value="0" /> | ||
</Style> | ||
|
||
<Style Selector="^ /template/ Panel#PART_TextContainer"> | ||
<Setter Property="Margin" Value="0" /> | ||
</Style> | ||
</Style> | ||
|
||
<!-- Tooltip --> | ||
<Style Selector="ToolTip"> | ||
<Setter Property="TextElement.FontSize" Value="14" /> | ||
<Setter Property="TextElement.FontWeight" Value="Normal" /> | ||
<Setter Property="TextElement.FontStyle" Value="Normal" /> | ||
<Setter Property="TextElement.FontStretch" Value="Normal" /> | ||
</Style> | ||
|
||
<!-- Toggle switch --> | ||
<Style Selector="ToggleSwitch"> | ||
<Setter Property="materialAssists:ToggleSwitchAssist.SwitchThumbOffBackground" Value="{DynamicResource MaterialBackgroundBrush}" /> | ||
</Style> | ||
</Application.Styles> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
using System; | ||
using System.Net; | ||
using Avalonia; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.Markup.Xaml; | ||
using Avalonia.Media; | ||
using Avalonia.Platform; | ||
using Avalonia.Styling; | ||
using AvaloniaWebView; | ||
using Material.Styles.Themes; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using YoutubeDownloader.Framework; | ||
using YoutubeDownloader.Services; | ||
using YoutubeDownloader.ViewModels; | ||
using YoutubeDownloader.ViewModels.Components; | ||
using YoutubeDownloader.ViewModels.Dialogs; | ||
using YoutubeDownloader.Views; | ||
|
||
namespace YoutubeDownloader; | ||
|
||
public partial class App : Application, IDisposable | ||
{ | ||
private readonly ServiceProvider _services; | ||
private readonly MainViewModel _mainViewModel; | ||
|
||
public App() | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
// Framework | ||
services.AddSingleton<DialogManager>(); | ||
services.AddSingleton<SnackbarManager>(); | ||
services.AddSingleton<ViewManager>(); | ||
services.AddSingleton<ViewModelManager>(); | ||
|
||
// Services | ||
services.AddSingleton<SettingsService>(); | ||
services.AddSingleton<UpdateService>(); | ||
|
||
// View models | ||
services.AddTransient<MainViewModel>(); | ||
services.AddTransient<DashboardViewModel>(); | ||
services.AddTransient<DownloadViewModel>(); | ||
services.AddTransient<AuthSetupViewModel>(); | ||
services.AddTransient<DownloadMultipleSetupViewModel>(); | ||
services.AddTransient<DownloadSingleSetupViewModel>(); | ||
services.AddTransient<MessageBoxViewModel>(); | ||
services.AddTransient<SettingsViewModel>(); | ||
|
||
_services = services.BuildServiceProvider(true); | ||
_mainViewModel = _services.GetRequiredService<ViewModelManager>().CreateMainViewModel(); | ||
} | ||
|
||
public override void Initialize() | ||
{ | ||
// Increase maximum concurrent connections | ||
ServicePointManager.DefaultConnectionLimit = 20; | ||
|
||
AvaloniaXamlLoader.Load(this); | ||
} | ||
|
||
public override void OnFrameworkInitializationCompleted() | ||
{ | ||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) | ||
desktop.MainWindow = new MainView { DataContext = _mainViewModel }; | ||
|
||
base.OnFrameworkInitializationCompleted(); | ||
|
||
// Set custom theme colors | ||
SetDefaultTheme(); | ||
} | ||
|
||
public override void RegisterServices() | ||
{ | ||
base.RegisterServices(); | ||
|
||
AvaloniaWebViewBuilder.Initialize(config => config.IsInPrivateModeEnabled = true); | ||
} | ||
|
||
public void Dispose() => _services.Dispose(); | ||
} | ||
|
||
public partial class App | ||
{ | ||
public static void SetLightTheme() | ||
{ | ||
if (Current is null) | ||
return; | ||
|
||
Current.LocateMaterialTheme<MaterialThemeBase>().CurrentTheme = Theme.Create( | ||
Theme.Light, | ||
Color.Parse("#343838"), | ||
Color.Parse("#F9A825") | ||
); | ||
|
||
Current.Resources["SuccessBrush"] = new SolidColorBrush(Colors.DarkGreen); | ||
Current.Resources["CanceledBrush"] = new SolidColorBrush(Colors.DarkOrange); | ||
Current.Resources["FailedBrush"] = new SolidColorBrush(Colors.DarkRed); | ||
} | ||
|
||
public static void SetDarkTheme() | ||
{ | ||
if (Current is null) | ||
return; | ||
|
||
Current.LocateMaterialTheme<MaterialThemeBase>().CurrentTheme = Theme.Create( | ||
Theme.Dark, | ||
Color.Parse("#E8E8E8"), | ||
Color.Parse("#F9A825") | ||
); | ||
|
||
Current.Resources["SuccessBrush"] = new SolidColorBrush(Colors.LightGreen); | ||
Current.Resources["CanceledBrush"] = new SolidColorBrush(Colors.Orange); | ||
Current.Resources["FailedBrush"] = new SolidColorBrush(Colors.OrangeRed); | ||
} | ||
|
||
public static void SetDefaultTheme() | ||
{ | ||
if (Current is null) | ||
return; | ||
|
||
var isDark = Current.RequestedThemeVariant is not null | ||
? Current.RequestedThemeVariant == ThemeVariant.Dark | ||
: Current.PlatformSettings?.GetColorValues().ThemeVariant == PlatformThemeVariant.Dark; | ||
|
||
if (isDark) | ||
SetDarkTheme(); | ||
else | ||
SetLightTheme(); | ||
} | ||
} |
Oops, something went wrong.