Skip to content

Commit

Permalink
Port from WPF to Avalonia (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrxx99 authored Apr 3, 2024
1 parent 01fe6b3 commit c09bc00
Show file tree
Hide file tree
Showing 49 changed files with 1,213 additions and 1,295 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Version>999.9.9-dev</Version>
<Company>Tyrrrz</Company>
<Copyright>Copyright (C) Oleksii Holub</Copyright>
Expand Down
11 changes: 6 additions & 5 deletions YoutubeDownloader.sln
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2015
# Visual Studio Version 17
VisualStudioVersion = 17.7.33920.267
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YoutubeDownloader", "YoutubeDownloader\YoutubeDownloader.csproj", "{AF6D645E-DDDD-4034-B644-D5328CC893C1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YoutubeDownloader", "YoutubeDownloader\YoutubeDownloader.csproj", "{AF6D645E-DDDD-4034-B644-D5328CC893C1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{131C2561-E5A1-43E8-BF38-40E2E23DB0A4}"
ProjectSection(SolutionItems) = preProject
Changelog.md = Changelog.md
Directory.Build.props = Directory.Build.props
License.txt = License.txt
Readme.md = Readme.md
Directory.Build.props = Directory.Build.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YoutubeDownloader.Core", "YoutubeDownloader.Core\YoutubeDownloader.Core.csproj", "{5122A9DE-232C-4DA8-AD76-8B72AA377D5E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YoutubeDownloader.Core", "YoutubeDownloader.Core\YoutubeDownloader.Core.csproj", "{5122A9DE-232C-4DA8-AD76-8B72AA377D5E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
546 changes: 91 additions & 455 deletions YoutubeDownloader/App.xaml

Large diffs are not rendered by default.

104 changes: 84 additions & 20 deletions YoutubeDownloader/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
using System;
using System;
using System.Net;
using System.Reflection;
using System.Windows.Media;
using MaterialDesignThemes.Wpf;
using YoutubeDownloader.Utils;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Input.Platform;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Avalonia.Styling;
using AvaloniaWebView;
using Material.Styles.Themes;
using Microsoft.Extensions.DependencyInjection;
using PropertyChanged;
using YoutubeDownloader.Services;
using YoutubeDownloader.ViewModels;
using YoutubeDownloader.ViewModels.Framework;
using YoutubeDownloader.Views;
using YoutubeDownloader.Views.Framework;

namespace YoutubeDownloader;

public partial class App
{
private static Assembly Assembly { get; } = Assembly.GetExecutingAssembly();

public static string Name { get; } = Assembly.GetName().Name!;
public static new string Name { get; } = Assembly.GetName().Name!;

public static Version Version { get; } = Assembly.GetName().Version!;

Expand All @@ -21,26 +34,27 @@ public partial class App
public static string LatestReleaseUrl { get; } = ProjectUrl + "/releases/latest";
}

public partial class App
[DoNotNotify]
public partial class App : Application
{
private readonly IServiceProvider _serviceProvider;

private static Theme LightTheme { get; } =
Theme.Create(
new MaterialDesignLightTheme(),
MediaColor.FromHex("#343838"),
MediaColor.FromHex("#F9A825")
);
Theme.Create(Theme.Light, Color.Parse("#343838"), Color.Parse("#F9A825"));

private static Theme DarkTheme { get; } =
Theme.Create(
new MaterialDesignDarkTheme(),
MediaColor.FromHex("#E8E8E8"),
MediaColor.FromHex("#F9A825")
);
Theme.Create(Theme.Dark, Color.Parse("#E8E8E8"), Color.Parse("#F9A825"));

public App()
{
_serviceProvider = ConfigureServices();
}

public static void SetLightTheme()
{
var paletteHelper = new PaletteHelper();
paletteHelper.SetTheme(LightTheme);
Current!.RequestedThemeVariant = ThemeVariant.Light;
var theme = Current.LocateMaterialTheme<MaterialThemeBase>();
theme.CurrentTheme = LightTheme;

Current.Resources["SuccessBrush"] = new SolidColorBrush(Colors.DarkGreen);
Current.Resources["CanceledBrush"] = new SolidColorBrush(Colors.DarkOrange);
Expand All @@ -49,11 +63,61 @@ public static void SetLightTheme()

public static void SetDarkTheme()
{
var paletteHelper = new PaletteHelper();
paletteHelper.SetTheme(DarkTheme);
Current!.RequestedThemeVariant = ThemeVariant.Dark;
var theme = Current.LocateMaterialTheme<MaterialThemeBase>();
theme.CurrentTheme = DarkTheme;

Current.Resources["SuccessBrush"] = new SolidColorBrush(Colors.LightGreen);
Current.Resources["CanceledBrush"] = new SolidColorBrush(Colors.Orange);
Current.Resources["FailedBrush"] = new SolidColorBrush(Colors.OrangeRed);
}

public override void Initialize()
{
// Increase maximum concurrent connections
ServicePointManager.DefaultConnectionLimit = 20;

AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
var rootViewModel = ActivatorUtilities.CreateInstance<RootViewModel>(_serviceProvider);

desktop.MainWindow = new RootView { DataContext = rootViewModel, };
}

base.OnFrameworkInitializationCompleted();
}

public override void RegisterServices()
{
base.RegisterServices();

AvaloniaWebViewBuilder.Initialize(config => config.IsInPrivateModeEnabled = true);
}

private ServiceProvider ConfigureServices()
{
var services = new ServiceCollection();

services.AddSingleton<SettingsService>();
services.AddSingleton<UpdateService>();
services.AddSingleton<IViewManager, ViewManager>();
services.AddSingleton<DialogManager>();
services.AddSingleton<IViewModelFactory, ViewModelFactory>();
services.AddTransient<IClipboard>(sp =>
sp.GetRequiredService<IViewManager>().GetTopLevel()!.Clipboard!
);
services.AddTransient<IApplicationLifetime>(sp => Current!.ApplicationLifetime!);
services.AddTransient<IControlledApplicationLifetime>(_ =>
(Current!.ApplicationLifetime! as IControlledApplicationLifetime)!
);

services.AddSingleton(_ => Current!.PlatformSettings!);

return services.BuildServiceProvider(true);
}
}
104 changes: 0 additions & 104 deletions YoutubeDownloader/Behaviors/MultiSelectionListBoxBehavior.cs

This file was deleted.

This file was deleted.

49 changes: 0 additions & 49 deletions YoutubeDownloader/Bootstrapper.cs

This file was deleted.

41 changes: 0 additions & 41 deletions YoutubeDownloader/Converters/BoolToVisibilityConverter.cs

This file was deleted.

21 changes: 0 additions & 21 deletions YoutubeDownloader/Converters/InverseBoolConverter.cs

This file was deleted.

Loading

0 comments on commit c09bc00

Please sign in to comment.