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
52 changes: 52 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,56 @@
<FileVersion>$(ForkBaseVersion).$(ForkRevision)</FileVersion>
<InformationalVersion>$(ForkBaseVersion).$(ForkRevision)</InformationalVersion>
</PropertyGroup>

<!--
GOXF fork: local test channel. Debug builds of DeskBox embed the git
commit they were built from (AssemblyMetadata ForkGitSha / ForkGitBranch)
so the app can compare it with the tip of origin/dev. Failure-tolerant:
no git / not a clone => nothing embedded, the app then reads .git at
runtime. Release / CI / installer builds skip it (opt in with
/p:ForkEmbedGitInfo=true).
-->
<PropertyGroup Condition="'$(MSBuildProjectName)' == 'DeskBox' and '$(ForkEmbedGitInfo)' == '' and '$(Configuration)' == 'Debug'">
<ForkEmbedGitInfo>true</ForkEmbedGitInfo>
</PropertyGroup>

<Target
Name="ForkEmbedGitInfoMetadata"
BeforeTargets="GetAssemblyAttributes"
Condition="'$(MSBuildProjectName)' == 'DeskBox' and '$(ForkEmbedGitInfo)' == 'true'">
<Exec
Command="git rev-parse HEAD"
WorkingDirectory="$(MSBuildThisFileDirectory)"
ConsoleToMSBuild="true"
EchoOff="true"
IgnoreExitCode="true"
IgnoreStandardErrorWarningFormat="true"
StandardOutputImportance="low"
StandardErrorImportance="low"
ContinueOnError="true">
<Output TaskParameter="ConsoleOutput" PropertyName="ForkGitShaRaw" />
<Output TaskParameter="ExitCode" PropertyName="ForkGitShaExitCode" />
</Exec>
<Exec
Command="git rev-parse --abbrev-ref HEAD"
WorkingDirectory="$(MSBuildThisFileDirectory)"
ConsoleToMSBuild="true"
EchoOff="true"
IgnoreExitCode="true"
IgnoreStandardErrorWarningFormat="true"
StandardOutputImportance="low"
StandardErrorImportance="low"
ContinueOnError="true">
<Output TaskParameter="ConsoleOutput" PropertyName="ForkGitBranchRaw" />
<Output TaskParameter="ExitCode" PropertyName="ForkGitBranchExitCode" />
</Exec>
<PropertyGroup>
<ForkGitSha Condition="'$(ForkGitShaExitCode)' == '0'">$([System.Text.RegularExpressions.Regex]::Match('$(ForkGitShaRaw)', '[0-9a-fA-F]{40,64}').Value)</ForkGitSha>
<ForkGitBranch Condition="'$(ForkGitBranchExitCode)' == '0'">$(ForkGitBranchRaw.Trim())</ForkGitBranch>
</PropertyGroup>
<ItemGroup>
<AssemblyMetadata Include="ForkGitSha" Value="$(ForkGitSha)" Condition="'$(ForkGitSha)' != ''" />
<AssemblyMetadata Include="ForkGitBranch" Value="$(ForkGitBranch)" Condition="'$(ForkGitSha)' != '' and '$(ForkGitBranch)' != ''" />
</ItemGroup>
</Target>
</Project>
88 changes: 63 additions & 25 deletions scripts/fork-dev-update.ps1
Original file line number Diff line number Diff line change
@@ -1,34 +1,72 @@
# GOXF fork:拉取最新测试代码,本地编译并运行 DeskBox(Debug)
# 用法:在仓库根目录右键「使用 PowerShell 运行」,或:
# powershell -ExecutionPolicy Bypass -File .\scripts\fork-dev-update.ps1 [-Branch dev]
param([string]$Branch = "dev")
# DeskBox 本地测试版的「更新并重启」也会调用本脚本(带 -GraceSeconds,先等 DeskBox 自己退出)。
# 出错时窗口不会自动关闭,按回车后关闭。
param(
[string]$Branch = "dev",
[int]$GraceSeconds = 0
)
$ErrorActionPreference = "Stop"
Set-Location (Split-Path $PSScriptRoot -Parent)

Write-Host "==> 关闭正在运行的 DeskBox" -ForegroundColor Cyan
Get-Process DeskBox -ErrorAction SilentlyContinue | Stop-Process -Force
Start-Sleep -Seconds 1
try {
Set-Location (Split-Path $PSScriptRoot -Parent)

Write-Host "==> 拉取 origin/$Branch" -ForegroundColor Cyan
git fetch origin $Branch
git checkout -B $Branch "origin/$Branch"
git log -1 --format="当前提交:%h %s (%cr)"
Write-Host "==> 关闭正在运行的 DeskBox" -ForegroundColor Cyan
if ($GraceSeconds -gt 0) {
Wait-Process -Name DeskBox -Timeout $GraceSeconds -ErrorAction SilentlyContinue
}
Get-Process DeskBox -ErrorAction SilentlyContinue | Stop-Process -Force
Start-Sleep -Seconds 1

$props = @("-p:Platform=x64", "-p:RuntimeIdentifier=win-x64", "-p:WindowsAppSDKSelfContained=true")
Write-Host "==> 拉取 origin/$Branch" -ForegroundColor Cyan
git fetch origin $Branch
if ($LASTEXITCODE -ne 0) { throw "git fetch 失败" }
git checkout -B $Branch "origin/$Branch"
if ($LASTEXITCODE -ne 0) { throw "git checkout 失败(本地是否有未提交的改动?)" }
git log -1 --format="当前提交:%h %s (%cr)"

if (-not (dotnet nuget list source | Select-String "nuget.org")) {
Write-Host "==> 添加 nuget.org 包源" -ForegroundColor Cyan
dotnet nuget add source "https://api.nuget.org/v3/index.json" -n nuget.org
$props = @("-p:Platform=x64", "-p:RuntimeIdentifier=win-x64", "-p:WindowsAppSDKSelfContained=true")

if (-not (dotnet nuget list source | Select-String "nuget.org")) {
Write-Host "==> 添加 nuget.org 包源" -ForegroundColor Cyan
dotnet nuget add source "https://api.nuget.org/v3/index.json" -n nuget.org
}
Write-Host "==> 还原依赖" -ForegroundColor Cyan
dotnet restore .\DeskBox.sln @props
if ($LASTEXITCODE -ne 0) { throw "restore 失败" }

Write-Host "==> 编译 Debug" -ForegroundColor Cyan
dotnet build .\src\DeskBox\DeskBox.csproj -c Debug --no-restore @props -v:minimal
if ($LASTEXITCODE -ne 0) { throw "编译失败" }

$exe = Get-ChildItem .\src\DeskBox\bin -Recurse -Filter DeskBox.exe | Sort-Object LastWriteTime -Descending | Select-Object -First 1
if (-not $exe) { throw "没找到 DeskBox.exe" }

# 桌面快捷方式「DeskBox 开发版.lnk」→ 刚编译的 DeskBox.exe(失败不影响启动)
try {
$desktop = [Environment]::GetFolderPath('Desktop')
$lnkPath = Join-Path $desktop "DeskBox 开发版.lnk"
$shell = New-Object -ComObject WScript.Shell
$lnk = $shell.CreateShortcut($lnkPath)
$lnk.TargetPath = $exe.FullName
$lnk.WorkingDirectory = $exe.DirectoryName
$lnk.IconLocation = "$($exe.FullName),0"
$lnk.Description = "DeskBox 本地开发版(dev 分支 Debug 构建)"
$lnk.Save()
Write-Host "==> 已更新桌面快捷方式:$lnkPath" -ForegroundColor Cyan
}
catch {
Write-Host "!! 创建桌面快捷方式失败(不影响运行):$($_.Exception.Message)" -ForegroundColor Yellow
}

Write-Host "==> 启动 $($exe.FullName)" -ForegroundColor Green
Start-Process $exe.FullName
}
catch {
Write-Host ""
Write-Host "!! 更新失败:$($_.Exception.Message)" -ForegroundColor Red
Write-Host " 修复后可重新运行:powershell -ExecutionPolicy Bypass -File .\scripts\fork-dev-update.ps1" -ForegroundColor Yellow
Read-Host "按回车关闭窗口"
exit 1
}
Write-Host "==> 还原依赖" -ForegroundColor Cyan
dotnet restore .\DeskBox.sln @props
if ($LASTEXITCODE -ne 0) { throw "restore 失败" }

Write-Host "==> 编译 Debug" -ForegroundColor Cyan
dotnet build .\src\DeskBox\DeskBox.csproj -c Debug --no-restore @props -v:minimal
if ($LASTEXITCODE -ne 0) { throw "编译失败" }

$exe = Get-ChildItem .\src\DeskBox\bin -Recurse -Filter DeskBox.exe | Sort-Object LastWriteTime -Descending | Select-Object -First 1
if (-not $exe) { throw "没找到 DeskBox.exe" }
Write-Host "==> 启动 $($exe.FullName)" -ForegroundColor Green
Start-Process $exe.FullName
114 changes: 114 additions & 0 deletions src/DeskBox/App.ForkDevUpdate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using DeskBox.Services;
using H.NotifyIcon.Core;

namespace DeskBox;

/// <summary>
/// GOXF/DeskBox fork: background loop of the local-test-build update channel.
/// Only runs for a local dev build (<see cref="ForkDevBuildInfo.Current"/>):
/// shortly after startup and then every 30 minutes it asks GitHub for the tip
/// of GOXF/DeskBox's dev branch and, once per new commit, shows the same
/// style of update toast (tray balloon as fallback) the regular updater
/// uses. Clicking it opens About, where "update and restart" lives.
/// </summary>
public partial class App
{
private string? _forkDevUpdateNotifiedSha;

private void ScheduleForkDevUpdateCheck()
{
ForkDevBuild? build = ForkDevBuildInfo.Current;
if (build is null)
{
return;
}

Log($"[DevUpdate] Local dev build {build.ShortSha} ({build.Branch}) at {build.RepositoryRoot}");
_ = Task.Run(() => ForkDevUpdateLoopAsync(IsStartupMode ? TimeSpan.FromSeconds(60) : TimeSpan.FromSeconds(15)));
}

private async Task ForkDevUpdateLoopAsync(TimeSpan initialDelay)
{
DateTimeOffset nextCheckAt = DateTimeOffset.Now + initialDelay;
while (!IsShuttingDown)
{
// Wall-clock deadline, re-evaluated after every wake (timers
// pause during sleep), same as the regular update loop.
TimeSpan remaining = nextCheckAt - DateTimeOffset.Now;
if (remaining > TimeSpan.Zero)
{
await Task.Delay(remaining < TimeSpan.FromMinutes(5) ? remaining : TimeSpan.FromMinutes(5));
continue;
}

try
{
ForkDevUpdateInfo? info = await ForkDevUpdateService.CheckAsync();
if (info is { HasUpdate: true } && !IsShuttingDown)
{
Log($"[DevUpdate] dev has {info.RemoteShortSha} (local {info.LocalShortSha})");
UiDispatcherQueue?.TryEnqueue(() => ShowForkDevUpdateNotification(info));
}
}
catch (Exception ex)
{
Log($"[DevUpdate] Background check crashed: {ex.GetType().Name}");
}

nextCheckAt = DateTimeOffset.Now + ForkDevUpdateService.CheckInterval;
}
}

private void ShowForkDevUpdateNotification(ForkDevUpdateInfo info)
{
if (IsShuttingDown ||
string.Equals(_forkDevUpdateNotifiedSha, info.RemoteSha, StringComparison.Ordinal) ||
!SettingsService.Settings.Core.ShowUpdateToastNotification)
{
return;
}

(string title, string message) = ForkDevUpdateService.FormatNotification(LocalizationService.CurrentCultureName, info);
// {type=update} without an action opens Settings → About, where the
// "update and restart" button is.
var openAboutArguments = new Dictionary<string, string>
{
["type"] = "update"
};
if (_nativeNotificationService?.TryShow(
title,
message,
openAboutArguments,
options: new NativeAppNotificationOptions(
Tag: "dev-update-available",
Group: "update")) == true)
{
_forkDevUpdateNotifiedSha = info.RemoteSha;
return;
}

if (_trayIcon is null)
{
return;
}

try
{
_trayIcon.ShowNotification(
title,
message,
NotificationIcon.Info,
customIconHandle: null,
largeIcon: true,
sound: false,
respectQuietTime: true,
realtime: false,
timeout: TimeSpan.FromSeconds(8));
_forkDevUpdateNotifiedSha = info.RemoteSha;
}
catch (Exception ex)
{
Log($"[DevUpdate] Tray notification failed: {ex.Message}");
}
}
}
1 change: 1 addition & 0 deletions src/DeskBox/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,7 @@
() => ShowReleaseNotesAfterUpdateOnce());

RunOptionalStartupStep("background-update-check", ScheduleBackgroundUpdateCheck);
RunOptionalStartupStep("fork-dev-update-check", ScheduleForkDevUpdateCheck); // GOXF fork: local dev builds only
RunOptionalStartupStep(
"update-installer-prune",
// Interface-typed property: pruning only exists on the
Expand Down Expand Up @@ -2784,7 +2785,7 @@
return null;
}

return window.CurrentContent is Controls.WidgetContents.TodoWidgetContentAdapter adapter &&

Check warning on line 2788 in src/DeskBox/App.xaml.cs

View workflow job for this annotation

GitHub Actions / Build and test

Dereference of a possibly null reference.

Check warning on line 2788 in src/DeskBox/App.xaml.cs

View workflow job for this annotation

GitHub Actions / Build and test

Dereference of a possibly null reference.
adapter.ViewModel.IsInitialized
? adapter.ViewModel
: null;
Expand Down
Loading
Loading