feat.airapp sdk

This commit is contained in:
lincube
2026-06-08 02:39:44 +08:00
parent 1a6f129e78
commit 7db72fbcd0
36 changed files with 2617 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "LanMountainDesktop Team",
"classifications": ["LanMountainDesktop", "AirApp", "Component"],
"identity": "LanMountainDesktop.AirApp.Component",
"name": "LanMountainDesktop AirApp - Desktop Component",
"shortName": "lmd-airapp-component",
"tags": {
"language": "C#",
"type": "project"
},
"sourceName": "LanMountainDesktop.AirApp.ComponentTemplate",
"preferNameDirectory": true,
"symbols": {
"ComponentId": {
"type": "parameter",
"datatype": "string",
"defaultValue": "my-widget",
"replaces": "my-widget",
"description": "The unique identifier for the component"
},
"ComponentName": {
"type": "parameter",
"datatype": "string",
"defaultValue": "My Widget",
"replaces": "My Widget",
"description": "The display name for the component"
},
"AuthorName": {
"type": "parameter",
"datatype": "string",
"defaultValue": "Your Name",
"replaces": "Your Name",
"description": "The author name"
}
}
}

View File

@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LanMountainDesktop.AirAppSdk" Version="6.0.0" />
</ItemGroup>
<!-- Include airapp.json in output -->
<ItemGroup>
<None Update="airapp.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,40 @@
using LanMountainDesktop.AirAppSdk;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace LanMountainDesktop.AirApp.ComponentTemplate;
/// <summary>
/// AirApp entry point.
/// </summary>
[AirAppEntrance]
public sealed class MyAirApp : AirAppBase
{
public override void Initialize(HostBuilderContext context, IServiceCollection services)
{
// Register the desktop component
services.AddAirAppComponent<MyWidget>(
"my-widget",
"My Widget",
options =>
{
options.Description = "A sample desktop component";
options.DefaultWidth = 2;
options.DefaultHeight = 2;
options.ResizeMode = AirAppComponentResizeMode.Both;
options.Category = "Custom";
options.IconKey = "AppGeneric";
});
}
public override Task OnStartedAsync(IAirAppRuntimeContext context)
{
context.Logger.Info("My AirApp started successfully!");
return Task.CompletedTask;
}
public override Task OnStoppingAsync()
{
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,81 @@
using Avalonia.Controls;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Threading;
using LanMountainDesktop.AirAppSdk;
namespace LanMountainDesktop.AirApp.ComponentTemplate;
/// <summary>
/// Desktop component widget implementation.
/// </summary>
public sealed class MyWidget : AirAppWidgetBase
{
private readonly TextBlock _titleText;
private readonly TextBlock _timeText;
private readonly DispatcherTimer _timer;
public MyWidget()
{
// Create UI
_titleText = new TextBlock
{
Text = "My Widget",
FontSize = 16,
FontWeight = FontWeight.Bold,
HorizontalAlignment = HorizontalAlignment.Center
};
_timeText = new TextBlock
{
FontSize = 24,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
var panel = new StackPanel
{
Spacing = 8,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
panel.Children.Add(_titleText);
panel.Children.Add(_timeText);
Content = panel;
// Setup timer to update time
_timer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1)
};
_timer.Tick += (s, e) => UpdateTime();
}
protected override void OnAttachedCore()
{
Context.Logger.Info($"Widget attached: {Context.ComponentId} at {Context.PlacementId}");
UpdateTime();
_timer.Start();
}
protected override void OnDetachedCore()
{
Context.Logger.Info($"Widget detached: {Context.ComponentId}");
_timer.Stop();
}
protected override void OnAppearanceChangedCore(AirAppAppearanceSnapshot snapshot)
{
// Respond to theme changes
_titleText.Foreground = new SolidColorBrush(snapshot.ForegroundColor);
_timeText.Foreground = new SolidColorBrush(snapshot.AccentColor);
Context.Logger.Info($"Appearance changed: DarkMode={snapshot.IsDarkMode}");
}
private void UpdateTime()
{
_timeText.Text = DateTime.Now.ToString("HH:mm:ss");
}
}

View File

@@ -0,0 +1,31 @@
# LanMountainDesktop.AirApp.ComponentTemplate
A desktop component AirApp for LanMountainDesktop.
## Build
```bash
dotnet build -c Release
```
This will produce a `.laapp` package in `bin/Release/net10.0/`.
## Install
Copy the `.laapp` file to LanMountainDesktop's plugins directory or install via the AirApp Market.
## Development
To test your component during development:
1. Build the project
2. Run LanMountainDesktop with debug mode:
```bash
dotnet run --project path/to/LanMountainDesktop.csproj -- --debug-airapp path/to/your/bin/Debug/net10.0
```
## Customize
- Edit `MyWidget.cs` to modify the component UI and behavior
- Edit `airapp.json` to change metadata
- Add more components by creating additional widget classes and registering them in `MyAirApp.cs`

View File

@@ -0,0 +1,21 @@
{
"id": "com.example.LanMountainDesktop.AirApp.ComponentTemplate",
"name": "LanMountainDesktop.AirApp.ComponentTemplate",
"version": "1.0.0",
"apiVersion": "6.0.0",
"author": "Your Name",
"description": "A desktop component AirApp for LanMountainDesktop",
"entranceAssembly": "LanMountainDesktop.AirApp.ComponentTemplate.dll",
"runtime": {
"mode": "in-process",
"capabilities": ["desktop-component"]
},
"components": [
{
"id": "my-widget",
"name": "My Widget",
"defaultWidth": 2,
"defaultHeight": 2
}
]
}