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>
25 changes: 25 additions & 0 deletions docs/architecture/mapped-organize.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ Dragging it into a mapped widget or confirming a preview that maps it clears
the mark. Entries deselected in a confirmed mapped preview are kept the same
way. 「退出映射整理」 clears the list.

### 拖到桌面 = 放回桌面

Dragging items out of a mapped widget and releasing them on the system desktop
(any monitor) runs the same `KeepOnDesktop`. Explorer sees that drop as a
same-folder move (a no-op), so DeskBox decides it at drag completion
(`FileSurfaceContent.MappedDragToDesktop.cs`, hooked once in
`CompleteDragItemsSession`): the window under the cursor must be the shell
desktop (`SHELLDLL_DefView`/`SysListView32` under `Progman`/`WorkerW`, shell
process, not a DeskBox window — `MappedDragToDesktopPolicy.ClassifyTarget`),
the point must be blank desktop (upstream `DesktopBlankHitTest`; a drop on a
folder / Recycle Bin icon stays a real move), no mouse button / Esc held, and
DeskBox must not have handled the drop itself. The put-back entries are then
moved to the release point through the desktop's `IFolderView`
(`SelectAndPositionItems`, `DesktopIconPlacementNativeMethods`), first icon
centred on the cursor, the rest in a column; skipped when 自动排列图标 is on.
Drops on other folders / widgets and move-mode widgets keep upstream behaviour.

## Multi-monitor / sleep

Mapped widgets are normal widgets, so the existing monitor binding,
Expand All @@ -104,6 +121,8 @@ topology profiles and wake recovery apply unchanged.
* `DesktopOrganizationTaskView.xaml` (+ `.Actions.cs` one call),
`FileSurfaceContent.SelectionAndMenus.cs` (blank menu call, item-menu
localizer, 「放回桌面」 interception).
* `FileSurfaceContent.xaml.cs`: one `TryPutBackMappedDragOnDesktop` call in
`CompleteDragItemsSession` (拖到桌面 = 放回桌面).
* `FileService.cs`: DeskBox-hidden members stay displayable (3 conditions).
* `DesktopAutoOrganizationWatcher.cs`: 只映射 hand-off (one block).
* `DesktopOrganizationSettingsSection.xaml`: one host panel for the mode card.
Expand All @@ -122,5 +141,11 @@ topology profiles and wake recovery apply unchanged.
(grouping is per category).
* The auto/manual switch for mapped widgets stays in the mapped widget's
blank-area menu.
* Moving / copying a mapped item out to another folder keeps the Hidden
attribute DeskBox set (NTFS carries it along); membership and the hidden
ledger are cleaned up by the desktop watcher, but the file stays hidden at
the destination.
* 拖到桌面 = 放回桌面: a drop onto an existing desktop icon is not treated as
put-back; icon placement needs 自动排列图标 off (网格对齐 still snaps it).
* Not runtime-verified on a real desktop in this change (CI builds and runs
unit tests only).
72 changes: 72 additions & 0 deletions scripts/fork-dev-update.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# GOXF fork:拉取最新测试代码,本地编译并运行 DeskBox(Debug)
# 用法:在仓库根目录右键「使用 PowerShell 运行」,或:
# powershell -ExecutionPolicy Bypass -File .\scripts\fork-dev-update.ps1 [-Branch dev]
# DeskBox 本地测试版的「更新并重启」也会调用本脚本(带 -GraceSeconds,先等 DeskBox 自己退出)。
# 出错时窗口不会自动关闭,按回车后关闭。
param(
[string]$Branch = "dev",
[int]$GraceSeconds = 0
)
$ErrorActionPreference = "Stop"

try {
Set-Location (Split-Path $PSScriptRoot -Parent)

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

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)"

$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
}
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using DeskBox.Models;
using DeskBox.Platform;
using DeskBox.Services;

namespace DeskBox.Controls.WidgetContents;

/// <summary>
/// GOXF fork, 「映射整理」: dragging items out of a mapped widget and dropping
/// them on the system desktop is 「放回桌面」. The items already live in the
/// desktop folder, so for Explorer that drop is a same-folder move (nothing
/// happens) and they would stay hidden and mapped; DeskBox recognises the
/// drop from the release point instead. Drops on a desktop icon, on other
/// folders, on other widgets, and every drag out of a move-mode widget keep
/// the upstream behaviour.
/// </summary>
public sealed partial class FileSurfaceContent
{
private const int VirtualKeyLeftButton = 0x01;
private const int VirtualKeyRightButton = 0x02;
private const int VirtualKeyEscape = 0x1B;

/// <summary>Returns true when the completed drag was turned into 「放回桌面」.</summary>
private bool TryPutBackMappedDragOnDesktop(string[] draggedPaths, bool handledInternally)
{
if (handledInternally ||
draggedPaths.Length == 0 ||
!ViewModel.IsMappedOrganizeWidget ||
MappedOrganizeService.Current is not { } service ||
!Win32Helper.GetCursorPos(out Win32Helper.POINT cursor))
{
return false;
}

MappedDesktopDropPoint drop = MappedDragToDesktopTarget.Probe(cursor);
if (!MappedDragToDesktopPolicy.ShouldPutBack(
isMappedWidget: true,
handledInternally,
drop.Kind,
drop.OnIcon,
mouseButtonDown: Win32Helper.IsKeyDown(VirtualKeyLeftButton) || Win32Helper.IsKeyDown(VirtualKeyRightButton),
escapePressed: Win32Helper.IsKeyDown(VirtualKeyEscape)))
{
return false;
}

IReadOnlyList<string> paths = MappedDragToDesktopPolicy.ComputePutBackPaths(
draggedPaths,
path => File.Exists(path) || Directory.Exists(path),
MappedOrganizeService.IsDesktopEntryPath);
if (paths.Count == 0)
{
return false;
}

int kept = service.KeepOnDesktop(paths);
App.Log(
$"[MappedOrganize] Drag to desktop: put back {kept}/{draggedPaths.Length} " +
$"widget={WidgetId} target={drop.Kind} at={cursor.X},{cursor.Y}.");
if (kept <= 0)
{
return false;
}

MappedDragToDesktopPlacement.PlaceInBackground(paths, drop);
ShowFeedback(new WidgetFeedbackRequest(
ForkOrganizeModeText.Format(ForkOrganizeModeText.Key.KeptOnDesktopFormat, kept),
WidgetFeedbackSeverity.Success,
"mapped-keep-desktop"));
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,12 @@ private void CompleteDragItemsSession(
return;
}

// GOXF fork: a mapped widget's drag released on the desktop is 「放回桌面」.
if (TryPutBackMappedDragOnDesktop(movedPaths, handledAsStackMembership))
{
return;
}

bool allowReleaseRecovery = ShouldRecoverUnhandledSourceDrop(
dropResult, handledAsStackMembership);
if (allowReleaseRecovery && fromStackPopover &&
Expand Down
Loading
Loading