diff --git a/Presence.Desktop/App.axaml b/Presence.Desktop/App.axaml new file mode 100644 index 0000000..eea6afa --- /dev/null +++ b/Presence.Desktop/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Presence.Desktop/App.axaml.cs b/Presence.Desktop/App.axaml.cs new file mode 100644 index 0000000..2640ca7 --- /dev/null +++ b/Presence.Desktop/App.axaml.cs @@ -0,0 +1,37 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; +using Microsoft.Extensions.DependencyInjection; +using Presence.Desktop.DI; +using Presence.Desktop.ViewModels; +using Presence.Desktop.Views; + +namespace Presence.Desktop +{ + public partial class App : Application + { + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + var serviceCollection = new ServiceCollection(); + serviceCollection.AddCommonService(); + var services = serviceCollection.BuildServiceProvider(); + var mainViewModel = services.GetRequiredService(); + + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow + { + DataContext = mainViewModel, + }; + } + + base.OnFrameworkInitializationCompleted(); + } + + } +} \ No newline at end of file diff --git a/Presence.Desktop/Assets/avalonia-logo.ico b/Presence.Desktop/Assets/avalonia-logo.ico new file mode 100644 index 0000000..da8d49f Binary files /dev/null and b/Presence.Desktop/Assets/avalonia-logo.ico differ diff --git a/Presence.Desktop/DI/ServiceCollectionExtensions.cs b/Presence.Desktop/DI/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..ee4d117 --- /dev/null +++ b/Presence.Desktop/DI/ServiceCollectionExtensions.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using data; +using data.Repository; +using domain.Service; +using domain.UseCase; +using Microsoft.Extensions.DependencyInjection; +using Presence.Desktop.ViewModels; + +namespace Presence.Desktop.DI +{ + public static class ServiceCollectionExtensions + { + public static void AddCommonService(this IServiceCollection collection) + { + collection + .AddDbContext() + .AddSingleton() + .AddTransient() + .AddTransient(); + } + } +} diff --git a/Presence.Desktop/Presence.Desktop.csproj b/Presence.Desktop/Presence.Desktop.csproj new file mode 100644 index 0000000..92a908c --- /dev/null +++ b/Presence.Desktop/Presence.Desktop.csproj @@ -0,0 +1,34 @@ + + + WinExe + net8.0 + enable + true + app.manifest + true + + + + + + + + + + + + + + + None + All + + + + + + + + + + diff --git a/Presence.Desktop/Program.cs b/Presence.Desktop/Program.cs new file mode 100644 index 0000000..9d4a474 --- /dev/null +++ b/Presence.Desktop/Program.cs @@ -0,0 +1,24 @@ +using Avalonia; +using Avalonia.ReactiveUI; +using System; + +namespace Presence.Desktop +{ + internal sealed class Program + { + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace() + .UseReactiveUI(); + } +} diff --git a/Presence.Desktop/ViewLocator.cs b/Presence.Desktop/ViewLocator.cs new file mode 100644 index 0000000..74b8a57 --- /dev/null +++ b/Presence.Desktop/ViewLocator.cs @@ -0,0 +1,32 @@ +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using Presence.Desktop.ViewModels; +using System; + +namespace Presence.Desktop +{ + public class ViewLocator : IDataTemplate + { + + public Control? Build(object? param) + { + if (param is null) + return null; + + var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + var type = Type.GetType(name); + + if (type != null) + { + return (Control)Activator.CreateInstance(type)!; + } + + return new TextBlock { Text = "Not Found: " + name }; + } + + public bool Match(object? data) + { + return data is ViewModelBase; + } + } +} diff --git a/Presence.Desktop/ViewModels/MainWindowViewModel.cs b/Presence.Desktop/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..f92cbe7 --- /dev/null +++ b/Presence.Desktop/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,15 @@ +using domain.UseCase; + +namespace Presence.Desktop.ViewModels +{ + public class MainWindowViewModel : ViewModelBase + { + private readonly IGroupUseCase _groupService; + public MainWindowViewModel(IGroupUseCase groupService) + { + _groupService = groupService; + } + + public string Greeting { get; } = "Welcome to Avalonia!"; + } +} diff --git a/Presence.Desktop/ViewModels/ViewModelBase.cs b/Presence.Desktop/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..66c82c5 --- /dev/null +++ b/Presence.Desktop/ViewModels/ViewModelBase.cs @@ -0,0 +1,8 @@ +using ReactiveUI; + +namespace Presence.Desktop.ViewModels +{ + public class ViewModelBase : ReactiveObject + { + } +} diff --git a/Presence.Desktop/Views/MainWindow.axaml b/Presence.Desktop/Views/MainWindow.axaml new file mode 100644 index 0000000..a158e7f --- /dev/null +++ b/Presence.Desktop/Views/MainWindow.axaml @@ -0,0 +1,20 @@ + + + + + + + + + + diff --git a/Presence.Desktop/Views/MainWindow.axaml.cs b/Presence.Desktop/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..2619e70 --- /dev/null +++ b/Presence.Desktop/Views/MainWindow.axaml.cs @@ -0,0 +1,12 @@ +using Avalonia.Controls; + +namespace Presence.Desktop.Views +{ + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/Presence.Desktop/app.manifest b/Presence.Desktop/app.manifest new file mode 100644 index 0000000..9c877cb --- /dev/null +++ b/Presence.Desktop/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + +