mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Meta - Replace WPF projects with Avalonia projects
This commit is contained in:
1 parent
fcf0376a9a
commit
d7f3ee1190
1110 files changed
+10872
-52240
No files matched your search
@@ -0,0 +1,11 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Root.DefaultTitleBarView">
|
||||
<Button Classes="title-bar-button" Command="{Binding ShowDebugger}" VerticalAlignment="Top" HorizontalAlignment="Right">
|
||||
<avalonia:MaterialIcon Kind="Bug"></avalonia:MaterialIcon>
|
||||
</Button>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,19 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Artemis.UI.Screens.Root
|
||||
{
|
||||
public partial class DefaultTitleBarView : UserControl
|
||||
{
|
||||
public DefaultTitleBarView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Shared;
|
||||
|
||||
namespace Artemis.UI.Screens.Root
|
||||
{
|
||||
public class DefaultTitleBarViewModel : ViewModelBase
|
||||
{
|
||||
private readonly IDebugService _debugService;
|
||||
|
||||
public DefaultTitleBarViewModel(IDebugService debugService)
|
||||
{
|
||||
_debugService = debugService;
|
||||
}
|
||||
|
||||
public void ShowDebugger()
|
||||
{
|
||||
_debugService.ShowDebugger();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:reactiveUi="http://reactiveui.net"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Root.RootView">
|
||||
<reactiveUi:RoutedViewHost Router="{Binding Router}">
|
||||
<reactiveUi:RoutedViewHost.PageTransition>
|
||||
<CrossFade Duration="0.1" />
|
||||
</reactiveUi:RoutedViewHost.PageTransition>
|
||||
</reactiveUi:RoutedViewHost>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,18 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Root
|
||||
{
|
||||
public class RootView : ReactiveUserControl<RootViewModel>
|
||||
{
|
||||
public RootView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.Sidebar;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Services.MainWindow;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Platform;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Root
|
||||
{
|
||||
public class RootViewModel : ActivatableViewModelBase, IScreen, IMainWindowProvider
|
||||
{
|
||||
private readonly IAssetLoader _assetLoader;
|
||||
private readonly DefaultTitleBarViewModel _defaultTitleBarViewModel;
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly IDebugService _debugService;
|
||||
private readonly IClassicDesktopStyleApplicationLifetime _lifeTime;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private readonly ISidebarVmFactory _sidebarVmFactory;
|
||||
private readonly IWindowService _windowService;
|
||||
private SidebarViewModel? _sidebarViewModel;
|
||||
private TrayIcon? _trayIcon;
|
||||
private TrayIcons? _trayIcons;
|
||||
private ViewModelBase? _titleBarViewModel;
|
||||
|
||||
public RootViewModel(ICoreService coreService,
|
||||
ISettingsService settingsService,
|
||||
IRegistrationService registrationService,
|
||||
IWindowService windowService,
|
||||
IMainWindowService mainWindowService,
|
||||
IDebugService debugService,
|
||||
IAssetLoader assetLoader,
|
||||
DefaultTitleBarViewModel defaultTitleBarViewModel,
|
||||
ISidebarVmFactory sidebarVmFactory)
|
||||
{
|
||||
Router = new RoutingState();
|
||||
|
||||
_coreService = coreService;
|
||||
_settingsService = settingsService;
|
||||
_windowService = windowService;
|
||||
_debugService = debugService;
|
||||
_assetLoader = assetLoader;
|
||||
_defaultTitleBarViewModel = defaultTitleBarViewModel;
|
||||
_sidebarVmFactory = sidebarVmFactory;
|
||||
_lifeTime = (IClassicDesktopStyleApplicationLifetime) Application.Current!.ApplicationLifetime!;
|
||||
|
||||
coreService.StartupArguments = _lifeTime.Args.ToList();
|
||||
mainWindowService.ConfigureMainWindowProvider(this);
|
||||
|
||||
DisplayAccordingToSettings();
|
||||
Router.CurrentViewModel.Subscribe(UpdateTitleBarViewModel);
|
||||
Task.Run(() =>
|
||||
{
|
||||
coreService.Initialize();
|
||||
registrationService.RegisterBuiltInDataModelDisplays();
|
||||
registrationService.RegisterBuiltInDataModelInputs();
|
||||
registrationService.RegisterBuiltInPropertyEditors();
|
||||
registrationService.RegisterBuiltInNodeTypes();
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdateTitleBarViewModel(IRoutableViewModel? viewModel)
|
||||
{
|
||||
if (viewModel is MainScreenViewModel mainScreenViewModel && mainScreenViewModel.TitleBarViewModel != null)
|
||||
TitleBarViewModel = mainScreenViewModel.TitleBarViewModel;
|
||||
else
|
||||
TitleBarViewModel = _defaultTitleBarViewModel;
|
||||
}
|
||||
|
||||
|
||||
public SidebarViewModel? SidebarViewModel
|
||||
{
|
||||
get => _sidebarViewModel;
|
||||
set => RaiseAndSetIfChanged(ref _sidebarViewModel, value);
|
||||
}
|
||||
|
||||
public ViewModelBase? TitleBarViewModel
|
||||
{
|
||||
get => _titleBarViewModel;
|
||||
set => RaiseAndSetIfChanged(ref _titleBarViewModel, value);
|
||||
}
|
||||
|
||||
private void CurrentMainWindowOnClosed(object? sender, EventArgs e)
|
||||
{
|
||||
_lifeTime.MainWindow = null;
|
||||
SidebarViewModel = null;
|
||||
|
||||
OnMainWindowClosed();
|
||||
}
|
||||
|
||||
private void DisplayAccordingToSettings()
|
||||
{
|
||||
bool autoRunning = _coreService.StartupArguments.Contains("--autorun");
|
||||
bool minimized = _coreService.StartupArguments.Contains("--minimized");
|
||||
bool showOnAutoRun = _settingsService.GetSetting("UI.ShowOnStartup", true).Value;
|
||||
|
||||
// Always show the tray icon if ShowOnStartup is false or the user has no way to open the main window
|
||||
bool showTrayIcon = !showOnAutoRun || _settingsService.GetSetting("UI.ShowTrayIcon", true).Value;
|
||||
|
||||
if (showTrayIcon)
|
||||
ShowTrayIcon();
|
||||
|
||||
if (autoRunning && !showOnAutoRun || minimized)
|
||||
{
|
||||
// TODO: Auto-update
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowSplashScreen();
|
||||
_coreService.Initialized += (_, _) => Dispatcher.UIThread.InvokeAsync(OpenMainWindow);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowSplashScreen()
|
||||
{
|
||||
_windowService.ShowWindow<SplashViewModel>();
|
||||
}
|
||||
|
||||
private void ShowTrayIcon()
|
||||
{
|
||||
_trayIcon = new TrayIcon
|
||||
{
|
||||
Icon = new WindowIcon(_assetLoader.Open(new Uri("avares://Artemis.UI/Assets/Images/Logo/application.ico"))),
|
||||
Command = ReactiveCommand.Create(OpenMainWindow)
|
||||
};
|
||||
_trayIcon.Menu = (NativeMenu?) Application.Current!.FindResource("TrayIconMenu");
|
||||
_trayIcons = new TrayIcons {_trayIcon};
|
||||
TrayIcon.SetIcons(Application.Current!, _trayIcons);
|
||||
}
|
||||
|
||||
private void HideTrayIcon()
|
||||
{
|
||||
_trayIcon?.Dispose();
|
||||
TrayIcon.SetIcons(Application.Current!, null!);
|
||||
|
||||
_trayIcon = null;
|
||||
_trayIcons = null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public RoutingState Router { get; }
|
||||
|
||||
#region Tray commands
|
||||
|
||||
public void OpenScreen(string displayName)
|
||||
{
|
||||
OpenMainWindow();
|
||||
|
||||
// At this point there is a sidebar VM because the main window was opened
|
||||
SidebarViewModel!.SelectedSidebarScreen = SidebarViewModel.SidebarScreens.FirstOrDefault(s => s.DisplayName == displayName);
|
||||
}
|
||||
|
||||
public async Task OpenDebugger()
|
||||
{
|
||||
await Dispatcher.UIThread.InvokeAsync(() => _debugService.ShowDebugger());
|
||||
}
|
||||
|
||||
public async Task Exit()
|
||||
{
|
||||
// Don't freeze the UI right after clicking
|
||||
await Task.Delay(200);
|
||||
Utilities.Shutdown();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of IMainWindowProvider
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsMainWindowOpen => _lifeTime.MainWindow != null;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void OpenMainWindow()
|
||||
{
|
||||
if (_lifeTime.MainWindow == null)
|
||||
{
|
||||
SidebarViewModel = _sidebarVmFactory.SidebarViewModel(this);
|
||||
_lifeTime.MainWindow = new MainWindow {DataContext = this};
|
||||
_lifeTime.MainWindow.Show();
|
||||
_lifeTime.MainWindow.Closed += CurrentMainWindowOnClosed;
|
||||
}
|
||||
|
||||
_lifeTime.MainWindow.WindowState = WindowState.Normal;
|
||||
_lifeTime.MainWindow.Activate();
|
||||
OnMainWindowOpened();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void CloseMainWindow()
|
||||
{
|
||||
_lifeTime.MainWindow?.Close();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? MainWindowOpened;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? MainWindowClosed;
|
||||
|
||||
protected virtual void OnMainWindowOpened()
|
||||
{
|
||||
MainWindowOpened?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnMainWindowClosed()
|
||||
{
|
||||
MainWindowClosed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:svg="clr-namespace:Avalonia.Svg.Skia;assembly=Avalonia.Svg.Skia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Root.SplashView"
|
||||
Icon="/Assets/Images/Logo/application.ico"
|
||||
Title="Artemis 2.0"
|
||||
Height="450"
|
||||
Width="400"
|
||||
CanResize="False"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
ExtendClientAreaToDecorationsHint="True"
|
||||
ExtendClientAreaTitleBarHeightHint="450">
|
||||
<Grid RowDefinitions="250,50,Auto,*" IsHitTestVisible="False">
|
||||
<Image Grid.Column="0" Stretch="Uniform" Width="200">
|
||||
<Image.Source>
|
||||
<svg:SvgImage Source="/Assets/Images/Logo/bow.svg" />
|
||||
</Image.Source>
|
||||
</Image>
|
||||
<TextBlock Grid.Row="1"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Bottom"
|
||||
TextWrapping="Wrap">
|
||||
Artemis is initializing...
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Row="2" HorizontalAlignment="Center" Text="{Binding Status}" />
|
||||
<ProgressBar Grid.Row="3" IsIndeterminate="True" Margin="16 0" />
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Root
|
||||
{
|
||||
public class SplashView : ReactiveWindow<SplashViewModel>
|
||||
{
|
||||
public SplashView()
|
||||
{
|
||||
InitializeComponent();
|
||||
#if DEBUG
|
||||
this.AttachDevTools();
|
||||
#endif
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
Observable.FromEventPattern(x => ViewModel!.CoreService.Initialized += x, x => ViewModel!.CoreService.Initialized -= x)
|
||||
.Subscribe(_ => Dispatcher.UIThread.Post(Close))
|
||||
.DisposeWith(disposables);
|
||||
});
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared;
|
||||
using Humanizer;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Root
|
||||
{
|
||||
public class SplashViewModel : ViewModelBase
|
||||
{
|
||||
private string _status;
|
||||
|
||||
public SplashViewModel(ICoreService coreService, IPluginManagementService pluginManagementService)
|
||||
{
|
||||
CoreService = coreService;
|
||||
_status = "Initializing Core";
|
||||
|
||||
pluginManagementService.CopyingBuildInPlugins += OnPluginManagementServiceOnCopyingBuildInPluginsManagement;
|
||||
pluginManagementService.PluginLoading += OnPluginManagementServiceOnPluginManagementLoading;
|
||||
pluginManagementService.PluginLoaded += OnPluginManagementServiceOnPluginManagementLoaded;
|
||||
pluginManagementService.PluginEnabling += PluginManagementServiceOnPluginManagementEnabling;
|
||||
pluginManagementService.PluginEnabled += PluginManagementServiceOnPluginManagementEnabled;
|
||||
pluginManagementService.PluginFeatureEnabling += PluginManagementServiceOnPluginFeatureEnabling;
|
||||
pluginManagementService.PluginFeatureEnabled += PluginManagementServiceOnPluginFeatureEnabled;
|
||||
}
|
||||
|
||||
public ICoreService CoreService { get; }
|
||||
|
||||
public string Status
|
||||
{
|
||||
get => _status;
|
||||
set => RaiseAndSetIfChanged(ref _status, value);
|
||||
}
|
||||
|
||||
private void OnPluginManagementServiceOnPluginManagementLoaded(object? sender, PluginEventArgs args)
|
||||
{
|
||||
Status = "Initializing UI";
|
||||
}
|
||||
|
||||
private void OnPluginManagementServiceOnPluginManagementLoading(object? sender, PluginEventArgs args)
|
||||
{
|
||||
Status = "Loading plugin: " + args.Plugin.Info.Name;
|
||||
}
|
||||
|
||||
private void PluginManagementServiceOnPluginManagementEnabled(object? sender, PluginEventArgs args)
|
||||
{
|
||||
Status = "Initializing UI";
|
||||
}
|
||||
|
||||
private void PluginManagementServiceOnPluginManagementEnabling(object? sender, PluginEventArgs args)
|
||||
{
|
||||
Status = "Enabling plugin: " + args.Plugin.Info.Name;
|
||||
}
|
||||
|
||||
private void PluginManagementServiceOnPluginFeatureEnabling(object? sender, PluginFeatureEventArgs e)
|
||||
{
|
||||
Status = "Enabling: " + e.PluginFeature.GetType().Name.Humanize();
|
||||
}
|
||||
|
||||
private void PluginManagementServiceOnPluginFeatureEnabled(object? sender, PluginFeatureEventArgs e)
|
||||
{
|
||||
Status = "Initializing UI";
|
||||
}
|
||||
|
||||
private void OnPluginManagementServiceOnCopyingBuildInPluginsManagement(object? sender, EventArgs args)
|
||||
{
|
||||
Status = "Updating built-in plugins";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user