Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/desktop-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Build desktop packages

on:
push:
branches:
- main
- copilot/**
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
package:
name: Package (${{ matrix.os_name }})
runs-on: ${{ matrix.runner }}
env:
OMNIHOST_PACKAGES_USERNAME: ${{ github.actor }}
OMNIHOST_PACKAGES_TOKEN: ${{ secrets.OMNIHOST_PACKAGES_TOKEN }}
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-latest
os_name: linux
framework: net8.0
archive_name: lvgl-editor-desktop-linux
- runner: windows-latest
os_name: windows
framework: net8.0-windows
archive_name: lvgl-editor-desktop-windows
- runner: macos-latest
os_name: macos
framework: net8.0
archive_name: lvgl-editor-desktop-macos

steps:
- name: Check package feed credentials
id: package-feed
shell: bash
run: |
if [ -z "${OMNIHOST_PACKAGES_TOKEN}" ]; then
echo "enabled=false" >> "${GITHUB_OUTPUT}"
exit 0
fi

echo "enabled=true" >> "${GITHUB_OUTPUT}"

- name: Explain skipped packaging
if: steps.package-feed.outputs.enabled != 'true'
run: echo "desktop packaging skipped: set OMNIHOST_PACKAGES_TOKEN to enable OmniHost package restore."

- name: Checkout
if: steps.package-feed.outputs.enabled == 'true'
uses: actions/checkout@v4

- name: Setup Node.js
if: steps.package-feed.outputs.enabled == 'true'
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Setup .NET
if: steps.package-feed.outputs.enabled == 'true'
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Install web dependencies
if: steps.package-feed.outputs.enabled == 'true'
run: npm ci

- name: Build desktop web assets
if: steps.package-feed.outputs.enabled == 'true'
run: npm run build:desktop-web

- name: Publish desktop host
if: steps.package-feed.outputs.enabled == 'true'
run: dotnet publish ./desktop/LvglEditor.Desktop.csproj -c Release -f ${{ matrix.framework }} -o ./artifacts/${{ matrix.archive_name }}

- name: Create zip artifact
if: steps.package-feed.outputs.enabled == 'true'
uses: thedoctor0/zip-release@0.7.6
with:
type: zip
filename: ${{ matrix.archive_name }}.zip
directory: ./artifacts
path: ${{ matrix.archive_name }}

- name: Upload packaged artifact
if: steps.package-feed.outputs.enabled == 'true'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.archive_name }}
path: ./artifacts/${{ matrix.archive_name }}.zip
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ dist-ssr
*.sln
*.sw?
wasm/build/
bin/
obj/
/.vs
/desktop/.vs/LvglEditor.Desktop
15 changes: 15 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="github-maikebing" value="https://nuget.pkg.github.com/maikebing/index.json" />
</packageSources>

<packageSourceCredentials>
<github-maikebing>
<add key="Username" value="%OMNIHOST_PACKAGES_USERNAME%" />
<add key="ClearTextPassword" value="%OMNIHOST_PACKAGES_TOKEN%" />
</github-maikebing>
</packageSourceCredentials>
</configuration>
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,31 @@ VITE_BASE_PATH=/lvgl-editor/ VITE_ENABLE_COMPILE_PREVIEW=false npm run build:web

仓库内已提供 `.github/workflows/deploy-pages.yml`,默认会在推送到 `main` 时构建并发布到 GitHub Pages,同时关闭在线编译预览功能。

### 桌面版(OmniHost)

项目现已增加 `desktop/LvglEditor.Desktop`,使用 [OmniHost](https://github.com/maikebing/OmniHost) 将现有 Vite 前端包装为桌面应用。

```bash
# 先构建前端静态资源
npm ci
npm run build:desktop-web

# Linux
dotnet publish ./desktop/LvglEditor.Desktop/LvglEditor.Desktop.csproj -c Release -f net8.0

# Windows
dotnet publish ./desktop/LvglEditor.Desktop/LvglEditor.Desktop.csproj -c Release -f net8.0-windows
```

桌面壳默认启用 OmniHost 的 VSCode 风格内置标题栏,提供最大化、最小化和关闭按钮;编辑器内部额外增加了 VSCode 风格菜单栏(文件 / 编辑 / 视图 / 帮助)。

OmniHost 依赖当前通过 `maikebing` 的 GitHub Packages 分发,因此在本地或 CI 中构建桌面版前,需要设置:

- `OMNIHOST_PACKAGES_USERNAME`
- `OMNIHOST_PACKAGES_TOKEN`(需要具备读取 `maikebing/OmniHost` GitHub Packages 的权限)

仓库内已新增 `.github/workflows/desktop-packages.yml`,在配置好 `OMNIHOST_PACKAGES_TOKEN` secret 后,会在 Linux、macOS、Windows 三个平台分别构建并上传压缩包产物。由于 OmniHost 当前公开版本尚未提供 macOS 原生运行时,macOS 产物目前用于保持统一的构建与分发流程,运行时会给出平台限制提示。

## ⌨️ 快捷键

### 基本操作
Expand Down
38 changes: 38 additions & 0 deletions desktop/LvglEditor.Desktop.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net8.0-windows</TargetFrameworks>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>LvglEditor.Desktop</RootNamespace>
<AssemblyName>LvglEditor.Desktop</AssemblyName>
<Version>1.0.0</Version>
<NoWarn>MSB3277</NoWarn>
<UseAppHost>true</UseAppHost>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0-windows'">
<OutputType>WinExe</OutputType>
</PropertyGroup>

<ItemGroup>
<Content Include="..\..\dist\**\*">
<Link>wwwroot\%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="OmniHost" Version="1.0.0" />
<PackageReference Include="OmniHost.Gtk" Version="1.0.0" />
<PackageReference Include="OmniHost.WebKitGtk" Version="1.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-windows'">
<PackageReference Include="OmniHost.Windows" Version="1.0.0" />
<PackageReference Include="OmniHost.WebView2" Version="1.0.0" />
</ItemGroup>

</Project>
68 changes: 68 additions & 0 deletions desktop/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using OmniHost;
using OmniHost.Core;
using OmniHost.Gtk;
using OmniHost.WebKitGtk;
#if WINDOWS
using OmniHost.WebView2;
using OmniHost.Windows;
#endif

var builder = OmniApp.CreateBuilder(args)
.Configure(options =>
{
options.Title = "LVGL Editor";
options.CustomScheme = "app";
options.ContentRootPath = Path.Combine(AppContext.BaseDirectory, "wwwroot");
options.StartUrl = "app://localhost/index.html";
options.Width = 1440;
options.Height = 960;
options.StartMaximized = true;
options.ScrollBarMode = OmniScrollBarMode.Auto;
options.BuiltInTitleBarStyle = OmniBuiltInTitleBarStyle.VsCode;
options.WindowStyle = OperatingSystem.IsWindows()
? OmniWindowStyle.VsCode
: OmniWindowStyle.Frameless;
})
.UseDesktopApp(new LvglEditorDesktopApp());

ConfigureCurrentPlatform(builder);

await builder.Build().RunAsync();

static void ConfigureCurrentPlatform(OmniHostBuilder builder)
{
if (OperatingSystem.IsLinux())
{
builder
.UseAdapter(new WebKitGtkAdapterFactory())
.UseRuntime(new GtkRuntime());
return;
}

#if WINDOWS
if (OperatingSystem.IsWindows())
{
builder
.UseAdapter(new WebView2AdapterFactory())
.UseRuntime(new Win32Runtime());
return;
}
#endif

if (OperatingSystem.IsMacOS())
{
throw new PlatformNotSupportedException(
"OmniHost 当前版本尚未提供 macOS 原生运行时/适配器,当前构建仅用于保留统一的桌面打包产物。");
}

throw new PlatformNotSupportedException("当前平台暂不受支持。");
}

sealed class LvglEditorDesktopApp : IDesktopApp
{
public Task OnStartAsync(IWebViewAdapter adapter, CancellationToken cancellationToken = default)
=> Task.CompletedTask;

public Task OnClosingAsync(CancellationToken cancellationToken = default)
=> Task.CompletedTask;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "vite",
"build": "tsc -b && vite build",
"build:web": "vite build",
"build:desktop-web": "vite build",
"lint": "eslint .",
"preview": "vite preview",
"test": "vitest --run"
Expand Down
12 changes: 10 additions & 2 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@ body {

/* Header */
.app-header {
height: 48px;
display: flex;
flex-direction: column;
align-items: stretch;
padding: 0;
background: #1a1a2e;
flex-shrink: 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.app-command-bar {
min-height: 48px;
display: flex;
align-items: center;
padding: 0 16px;
gap: 16px;
flex-shrink: 0;
}

.app-logo {
Expand Down
Loading