diff --git a/Flow.Launcher.Avalonia/ViewModel/SettingPages/PluginsSettingsViewModel.cs b/Flow.Launcher.Avalonia/ViewModel/SettingPages/PluginsSettingsViewModel.cs index 53c581ece..6ab1f043e 100644 --- a/Flow.Launcher.Avalonia/ViewModel/SettingPages/PluginsSettingsViewModel.cs +++ b/Flow.Launcher.Avalonia/ViewModel/SettingPages/PluginsSettingsViewModel.cs @@ -46,8 +46,32 @@ public partial class PluginItemViewModel : ObservableObject public PluginItemViewModel(PluginPair plugin) { _plugin = plugin; + + if (plugin.Plugin is ISettingProvider settingProvider) + { + try + { + // Create the WPF settings panel + SettingControl = settingProvider.CreateSettingPanel(); + HasSettings = SettingControl != null; + } + catch (System.Exception) + { + // TODO: Log error using logger + HasSettings = false; + } + } } + [ObservableProperty] + private object? _settingControl; + + [ObservableProperty] + private bool _hasSettings; + + [ObservableProperty] + private bool _isExpanded; + public string Name => _plugin.Metadata.Name; public string Description => _plugin.Metadata.Description; public string Author => _plugin.Metadata.Author; diff --git a/Flow.Launcher.Avalonia/Views/Controls/WpfControlHost.cs b/Flow.Launcher.Avalonia/Views/Controls/WpfControlHost.cs new file mode 100644 index 000000000..0b522fdca --- /dev/null +++ b/Flow.Launcher.Avalonia/Views/Controls/WpfControlHost.cs @@ -0,0 +1,61 @@ +using System; +using System.Runtime.InteropServices; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Platform; +using System.Windows.Interop; +using System.Windows; + +namespace Flow.Launcher.Avalonia.Views.Controls +{ + public class WpfControlHost : NativeControlHost + { + private HwndSource? _source; + + public static readonly StyledProperty ContentProperty = + AvaloniaProperty.Register(nameof(Content)); + + public object? Content + { + get => GetValue(ContentProperty); + set => SetValue(ContentProperty, value); + } + + protected override IPlatformHandle CreateNativeControlCore(IPlatformHandle parent) + { + var parameters = new HwndSourceParameters + { + ParentWindow = parent.Handle, + WindowStyle = 0x50000000, // WS_CHILD | WS_VISIBLE + PositionX = 0, + PositionY = 0, + }; + + _source = new HwndSource(parameters); + + if (Content != null) + { + _source.RootVisual = Content as System.Windows.Media.Visual; + } + + return new PlatformHandle(_source.Handle, "HwndSource"); + } + + protected override void DestroyNativeControlCore(IPlatformHandle control) + { + _source?.Dispose(); + _source = null; + base.DestroyNativeControlCore(control); + } + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + + if (change.Property == ContentProperty && _source != null) + { + _source.RootVisual = change.NewValue as System.Windows.Media.Visual; + } + } + } +} diff --git a/Flow.Launcher.Avalonia/Views/SettingPages/PluginsSettingsPage.axaml b/Flow.Launcher.Avalonia/Views/SettingPages/PluginsSettingsPage.axaml index 10be3cf52..a7d37fa2a 100644 --- a/Flow.Launcher.Avalonia/Views/SettingPages/PluginsSettingsPage.axaml +++ b/Flow.Launcher.Avalonia/Views/SettingPages/PluginsSettingsPage.axaml @@ -5,6 +5,7 @@ xmlns:ui="using:FluentAvalonia.UI.Controls" xmlns:vm="using:Flow.Launcher.Avalonia.ViewModel.SettingPages" xmlns:i18n="using:Flow.Launcher.Avalonia.Resource" + xmlns:controls="using:Flow.Launcher.Avalonia.Views.Controls" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="600" x:Class="Flow.Launcher.Avalonia.Views.SettingPages.PluginsSettingsPage" x:DataType="vm:PluginsSettingsViewModel"> @@ -23,23 +24,42 @@ ScrollViewer.HorizontalScrollBarVisibility="Disabled"> - - - - - - - + + + + + + + + + + + - - - - - + + + + + + + + + + + + + +