mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
3.8 KiB
3.8 KiB
Flow.Launcher.Avalonia/
Responsibility
The Flow.Launcher.Avalonia directory is the core of the Avalonia-based UI implementation for Flow Launcher. It handles the application lifecycle, the primary search interface, and provides compatibility layers for existing plugins that were originally designed for the WPF version. It serves as the main entry point for the Avalonia flavor of the application.
Design
- MVVM (Model-View-ViewModel): Separation of UI (
MainWindow.axaml) and logic (MainViewModel.cs). - Dependency Injection (DI): Uses
Microsoft.Extensions.DependencyInjectionandCommunityToolkit.Mvvm'sIocfor service management. - Bridge Pattern:
AvaloniaPublicAPIadapts theIPublicAPIinterface to work with Avalonia's infrastructure, allowing plugins to function without major modifications. - Singleton: Core services like
Settings,MainViewModel, andInternationalizationare registered as singletons within the DI container. - WPF Compatibility Shim: A unique architectural decision to run a background WPF
Applicationinstance to support legacy plugins that rely onSystem.Windows.Application.Current.
Key Classes
| Class | Purpose |
|---|---|
Program.cs |
Entry point. Initializes a background WPF Application instance for plugin compatibility before starting the Avalonia app. |
App.axaml.cs |
Manages application lifecycle, DI container configuration, settings loading, and plugin initialization. |
MainWindow.axaml.cs |
Code-behind for the primary search window. Handles window positioning, focus management, and keyboard shortcuts (Escape, Arrows). |
AvaloniaPublicAPI.cs |
Implementation of IPublicAPI. Provides plugins with access to Flow Launcher's core functionality (Querying, UI control, Clipboard, etc.) in the Avalonia context. |
Flow
Application Startup
Program.Main: InitializesSystem.Windows.Application(WPF) to provideApplication.Current.Resourcesfor legacy plugins.App.Initialize:- Loads user settings from JSON via
FlowLauncherJsonStorage. - Configures the DI container (
ConfigureDI). - Injects translations into application resources.
- Loads user settings from JSON via
App.OnFrameworkInitializationCompleted:- Resolves
MainViewModelfrom DI. - Instantiates
MainWindow. - Starts asynchronous plugin initialization (
InitializePluginsAsync).
- Resolves
Search Execution
- User input in
MainWindow'sQueryTextBoxupdatesMainViewModel.QueryTextvia binding. MainViewModel(inFlow.Launcher.Avalonia/ViewModel) triggersPluginManagerto query active plugins.- Results are returned and displayed in the UI.
Integration
Flow.Launcher.Core: Directly integrates withPluginManagerfor plugin lifecycle andInternationalizationfor multi-language support.Flow.Launcher.Infrastructure: Relies onUserSettings,Logger, andStringMatcher(fuzzy search logic).Flow.Launcher.Plugin: Implements theIPublicAPIinterface to allow plugins to interact with the Avalonia-hosted app.- WPF Ecosystem: Maintains a runtime dependency on WPF (
System.Windows) to ensure that plugins using WPF-specific resources orApplication.Currentdo not crash.
Avalonia vs WPF Implementation Details
- WPF Shim: Unlike the original WPF version, the Avalonia version must manually spin up a WPF environment in
Program.csto maintain plugin compatibility. - Window Positioning:
MainWindowuses Avalonia'sScreensAPI to center itself at 25% from the top of the primary screen, mimicking the WPF behavior. - Event Handling: Uses Avalonia-specific events like
DeactivatedandPointerPressedfor window management and dragging. - DI Strategy: Uses a modern
ServiceCollection-based DI approach compared to the older WPF implementation's service resolution.