Skip to content

Commit a2a342c

Browse files
committed
add auto update
1 parent 9fb44a2 commit a2a342c

6 files changed

Lines changed: 529 additions & 98 deletions

File tree

Lines changed: 20 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,37 @@
1-
# This workflow uses actions that are not certified by GitHub.
2-
# They are provided by a third-party and are governed by
3-
# separate terms of service, privacy policy, and support
4-
# documentation.
5-
6-
# This workflow will build, test, sign and package a WPF or Windows Forms desktop application
7-
# built on .NET Core.
8-
# To learn how to migrate your existing application to .NET Core,
9-
# refer to https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework
10-
#
11-
# To configure this workflow:
12-
#
13-
# 1. Configure environment variables
14-
# GitHub sets default environment variables for every workflow run.
15-
# Replace the variables relative to your project in the "env" section below.
16-
#
17-
# 2. Signing
18-
# Generate a signing certificate in the Windows Application
19-
# Packaging Project or add an existing signing certificate to the project.
20-
# Next, use PowerShell to encode the .pfx file using Base64 encoding
21-
# by running the following Powershell script to generate the output string:
22-
#
23-
# $pfx_cert = Get-Content '.\SigningCertificate.pfx' -Encoding Byte
24-
# [System.Convert]::ToBase64String($pfx_cert) | Out-File 'SigningCertificate_Encoded.txt'
25-
#
26-
# Open the output file, SigningCertificate_Encoded.txt, and copy the
27-
# string inside. Then, add the string to the repo as a GitHub secret
28-
# and name it "Base64_Encoded_Pfx."
29-
# For more information on how to configure your signing certificate for
30-
# this workflow, refer to https://github.com/microsoft/github-actions-for-desktop-apps#signing
31-
#
32-
# Finally, add the signing certificate password to the repo as a secret and name it "Pfx_Key".
33-
# See "Build the Windows Application Packaging project" below to see how the secret is used.
34-
#
35-
# For more information on GitHub Actions, refer to https://github.com/features/actions
36-
# For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications,
37-
# refer to https://github.com/microsoft/github-actions-for-desktop-apps
38-
39-
name: .NET Core Desktop
1+
name: TimeTask CI
402

413
on:
424
push:
43-
branches: [ "master" ]
5+
branches: [ "master", "main" ]
446
pull_request:
45-
branches: [ "master" ]
7+
branches: [ "master", "main" ]
8+
workflow_dispatch:
9+
inputs:
10+
run_tests:
11+
description: "Run unit tests (off by default to avoid unstable desktop test failures)"
12+
required: false
13+
default: false
14+
type: boolean
4615

4716
jobs:
48-
4917
build:
50-
51-
strategy:
52-
matrix:
53-
configuration: [Debug, Release]
54-
55-
runs-on: windows-latest # For a list of available runner types, refer to
56-
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
57-
18+
runs-on: windows-latest
5819
env:
59-
Solution_Name: your-solution-name # Replace with your solution name, i.e. MyWpfApp.sln.
60-
Test_Project_Path: your-test-project-path # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj.
61-
Wap_Project_Directory: your-wap-project-directory-name # Replace with the Wap project directory relative to the solution, i.e. MyWpfApp.Package.
62-
Wap_Project_Path: your-wap-project-path # Replace with the path to your Wap project, i.e. MyWpf.App.Package\MyWpfApp.Package.wapproj.
63-
20+
Solution_Name: TimeTask.sln
21+
Build_Configuration: Release
6422
steps:
6523
- name: Checkout
6624
uses: actions/checkout@v4
67-
with:
68-
fetch-depth: 0
69-
70-
# Install the .NET Core workload
71-
- name: Install .NET Core
72-
uses: actions/setup-dotnet@v4
73-
with:
74-
dotnet-version: 8.0.x
7525

76-
# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
7726
- name: Setup MSBuild.exe
7827
uses: microsoft/setup-msbuild@v2
7928

80-
# Execute all unit tests in the solution
81-
- name: Execute unit tests
82-
run: dotnet test
83-
84-
# Restore the application to populate the obj folder with RuntimeIdentifiers
85-
- name: Restore the application
86-
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
87-
env:
88-
Configuration: ${{ matrix.configuration }}
89-
90-
# Decode the base 64 encoded pfx and save the Signing_Certificate
91-
- name: Decode the pfx
92-
run: |
93-
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.Base64_Encoded_Pfx }}")
94-
$certificatePath = Join-Path -Path $env:Wap_Project_Directory -ChildPath GitHubActionsWorkflow.pfx
95-
[IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte)
96-
97-
# Create the app package by building and packaging the Windows Application Packaging project
98-
- name: Create the app package
99-
run: msbuild $env:Wap_Project_Path /p:Configuration=$env:Configuration /p:UapAppxPackageBuildMode=$env:Appx_Package_Build_Mode /p:AppxBundle=$env:Appx_Bundle /p:PackageCertificateKeyFile=GitHubActionsWorkflow.pfx /p:PackageCertificatePassword=${{ secrets.Pfx_Key }}
100-
env:
101-
Appx_Bundle: Always
102-
Appx_Bundle_Platforms: x86|x64
103-
Appx_Package_Build_Mode: StoreUpload
104-
Configuration: ${{ matrix.configuration }}
29+
- name: Restore solution
30+
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Build_Configuration
10531

106-
# Remove the pfx
107-
- name: Remove the pfx
108-
run: Remove-Item -path $env:Wap_Project_Directory\GitHubActionsWorkflow.pfx
32+
- name: Build solution
33+
run: msbuild $env:Solution_Name /p:Configuration=$env:Build_Configuration /p:Platform="Any CPU" /m
10934

110-
# Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact
111-
- name: Upload build artifacts
112-
uses: actions/upload-artifact@v4
113-
with:
114-
name: MSIX Package
115-
path: ${{ env.Wap_Project_Directory }}\AppPackages
35+
- name: Execute unit tests (optional)
36+
if: ${{ github.event_name == 'workflow_dispatch' && inputs.run_tests == true }}
37+
run: dotnet test TimeTask.Tests/TimeTask.Tests.csproj -c $env:Build_Configuration --no-build

App.config

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
<!-- For OpenAI, empty means use library default. For other providers, this will be crucial. -->
1616
<add key="LlmModelName" value="glm-4-flash" />
1717
<add key="LlmRequestTimeoutSeconds" value="120" />
18+
<!-- 自动更新(优先使用 GitHub Releases) -->
19+
<add key="AutoUpdateEnabled" value="true" />
20+
<add key="AutoUpdateGithubOwner" value="YOUR_GITHUB_OWNER" />
21+
<add key="AutoUpdateGithubRepo" value="YOUR_GITHUB_REPO" />
22+
<!-- 可选:仅匹配包含该关键字的 zip 资产名称;留空则取第一个 zip -->
23+
<add key="AutoUpdateGithubAssetNameContains" value="" />
24+
<!-- true 时从 releases 列表中选最新(可含预发布);false 时走 latest(仅稳定版) -->
25+
<add key="AutoUpdateGithubIncludePrerelease" value="false" />
26+
<!-- 可选兜底:若未配置 GitHub,可改用自定义 manifest -->
27+
<add key="AutoUpdateManifestUrl" value="YOUR_UPDATE_MANIFEST_URL" />
28+
<add key="AutoUpdateCheckTimeoutSeconds" value="10" />
29+
<add key="AutoUpdateDownloadTimeoutSeconds" value="300" />
1830
<!-- 语音模型自动下载配置 -->
1931
<add key="SpeechModelAutoDownload" value="true" />
2032
<add key="SpeechModelName" value="vosk-model-cn-0.22" />

App.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public partial class App : Application
2424
// 通知管理器
2525
private NotificationManager _notificationManager;
2626

27+
// 自动更新服务
28+
private AutoUpdateService _autoUpdateService;
29+
2730
protected override void OnStartup(StartupEventArgs e)
2831
{
2932
base.OnStartup(e); // Call base implementation
@@ -34,6 +37,17 @@ protected override void OnStartup(StartupEventArgs e)
3437
VoiceListenerStatusCenter.Publish(VoiceListenerState.Unavailable, "语音监听不可用(启动初始化中)");
3538
FunAsrRuntimeManager.KickoffIfNeeded();
3639

40+
// 启动自动更新检查(后台执行)
41+
try
42+
{
43+
_autoUpdateService = new AutoUpdateService(Dispatcher);
44+
_autoUpdateService.StartBackgroundCheck();
45+
}
46+
catch (Exception ex)
47+
{
48+
VoiceRuntimeLog.Error("AutoUpdateService startup failed.", ex);
49+
}
50+
3751
// Check for API Key configuration
3852
string apiKey = System.Configuration.ConfigurationManager.AppSettings["OpenAIApiKey"];
3953
const string PlaceholderApiKey = "YOUR_API_KEY_GOES_HERE";

0 commit comments

Comments
 (0)