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
80 changes: 58 additions & 22 deletions docs/architecture/mapped-organize.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,51 @@ Ordinary organization never targets mapped widgets: they are filtered out in
`DesktopOrganizationRuleResolver.Resolve`, `CreateExecutionPlan` and
`GetDestinationOptions`.

## Native desktop icons (user accepted hiding)

Choice: hide the desktop `SysListView32` (child of the desktop
`SHELLDLL_DefView`) with `ShowWindow(SW_HIDE)`
(`Services/DesktopIconVisibilityService.cs`), **not** Explorer's persisted
"Show desktop icons" setting.

* Not persisted by Explorer → no failure mode can leave the user permanently
without icons (Explorer restart / sign-out always shows them again).
* Hidden while ≥1 mapped widget exists; shown when the last one is dissolved,
on DeskBox shutdown (`ShutdownStep "mapped-organize"`), and best-effort in
`AppDomain.ProcessExit`.
* Crash safety: `desktopIconsHiddenByDeskBox` is written *before* hiding. On
the next start `MappedOrganizeService.Initialize` either re-applies (mapped
widgets exist) or restores (none left). It runs even if widget restore fails.
* Explorer restarts recreate a visible list view; a 4 s dispatcher timer
re-hides it while mapped widgets exist.
## Global 「整理方式」 (organize mode)

* Settings → 桌面整理 → 「整理方式」: 「移动到格子」 (default, upstream) /
「只映射,不移动文件」. Stored in `<data root>/fork-organize.json`
(`{"organizeMode":"move|mapOnly"}`, `Services/ForkOrganizeModeSettings.cs`),
written by the settings process, read by the main process at use time and
watched by `MappedOrganizeService` (FileSystemWatcher).
* The preview no longer has a checkbox: its footer shows the current mode
(link opens the setting) and 「开始整理」 follows it.
* Automatic organization of new files: in 「只映射」 mode the upstream
`DesktopAutoOrganizationWatcher` never moves; it hands the settled file to
`MappedOrganizeService.TryTakeOverAutoOrganization` (mapped routing).
* Switching back to 「移动到格子」 dissolves every mapped widget and restores
every hidden desktop item. Startup: installs that already have mapped widgets
but no mode file adopt 「只映射」.

## Desktop visibility: per item (replaces hiding the whole list view)

* Only mapped entries are hidden, by setting `FILE_ATTRIBUTE_HIDDEN`.
Unmapped and 「放回桌面」 entries stay visible as normal desktop icons.
* Ledger `data/mapped-organize.hidden` lists every path DeskBox hid; it is
written *before* an attribute is set. Files that were already hidden are
never recorded and never touched. Pure rules: `MappedOrganizeHiddenLedger`.
* Restore (`Reconcile` with nothing desired / member removed): entry leaves its
widget, 「放回桌面」, 「退出映射整理」, switching to move mode, DeskBox exit
(shutdown step + ProcessExit), next start after a crash (members re-hidden,
stale records restored), and the uninstaller
(`installer/DeskBox.ForkMappedOrganize.iss`, after the process is stopped).
* `MappedOrganizeHiddenRegistry` lets the widget folder loader
(`FileService`: snapshot filter, `ClassifyExistingEntry`, `ShouldDisplayEntry`)
keep listing DeskBox-hidden members; it is seeded lazily from the ledger.
* The legacy `desktopIconsHiddenByDeskBox` marker (whole list view hidden by
older builds) is repaired once at startup.
* Settings warns when Explorer shows hidden items (HKCU …\Explorer\Advanced
`Hidden`=1): mapped entries then still appear as faded icons.

## 「放回桌面」

The item menu row 「移回桌面」 reads 「放回桌面」 in mapped widgets and calls
`MappedOrganizeService.KeepOnDesktop` (single and multi-select): membership
removed, attribute restored, path recorded in `data/mapped-organize.kept` so
automatic sorting and 「一键整理」 skip it (follows renames, dropped on delete).
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.

## Multi-monitor / sleep

Expand All @@ -74,17 +102,25 @@ topology profiles and wake recovery apply unchanged.
* `DesktopOrganizationRuleResolver.cs`, `DesktopOrganizationCoordinator.cs`:
exclude mapped widgets.
* `DesktopOrganizationTaskView.xaml` (+ `.Actions.cs` one call),
`FileSurfaceContent.SelectionAndMenus.cs` (one call).
`FileSurfaceContent.SelectionAndMenus.cs` (blank menu call, item-menu
localizer, 「放回桌面」 interception).
* `FileService.cs`: DeskBox-hidden members stay displayable (3 conditions).
* `DesktopAutoOrganizationWatcher.cs`: 只映射 hand-off (one block).
* `DesktopOrganizationSettingsSection.xaml`: one host panel for the mode card.
* `installer/DeskBox.Uninstall.iss`: include + one call.
* `Strings/*.json`: 6 keys inserted after `DesktopOrganization.Preview.Title`
(zh-CN / zh-TW translated, other locales English fallback).

## Known gaps

* Manual mode: new desktop files stay unassigned (and therefore invisible
while icons are hidden) until 「一键整理」.
* Manual mode: new desktop files stay unassigned (visible on the desktop)
until 「一键整理」.
* Public Desktop entries need admin rights to change attributes; when that
fails they stay visible on the desktop as well as in the widget.
* Hidden entries are also hidden in File Explorer's Desktop folder view.
* Preview "use existing widget" destination choices are ignored in mapped mode
(grouping is per category).
* No dedicated entry in the Settings window yet; the auto/manual switch is in
the mapped widget's blank-area menu.
* The auto/manual switch for mapped widgets stays in the mapped widget's
blank-area menu.
* Not runtime-verified on a real desktop in this change (CI builds and runs
unit tests only).
58 changes: 58 additions & 0 deletions installer/DeskBox.ForkMappedOrganize.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// GOXF/DeskBox fork: 「映射整理」 hides mapped desktop entries by setting the
// hidden attribute and records every entry it hid in
// data\mapped-organize.hidden (one absolute path per line). The app restores
// them when mapping ends or DeskBox exits; the uninstaller stops DeskBox
// forcibly, so restore the recorded entries here as well. Entries that were
// hidden before DeskBox touched them are never recorded and stay hidden.
// Included from DeskBox.Uninstall.iss (inside its [Code] section).

const
DeskBoxMappedOrganizeHiddenLedgerPath = '{localappdata}\DeskBox\data\mapped-organize.hidden';
DeskBoxFileAttributeHidden = $2;
DeskBoxInvalidFileAttributes = $FFFFFFFF;

function DeskBoxGetFileAttributes(lpFileName: String): Cardinal;
external '[email protected] stdcall';
function DeskBoxSetFileAttributes(lpFileName: String; dwFileAttributes: Cardinal): Boolean;
external '[email protected] stdcall';

procedure RestoreMappedOrganizeHiddenDesktopItems;
var
LedgerPath: string;
Lines: TArrayOfString;
Index: Integer;
ItemPath: string;
Attributes: Cardinal;
Restored: Integer;
begin
LedgerPath := ExpandConstant(DeskBoxMappedOrganizeHiddenLedgerPath);
if not FileExists(LedgerPath) then
Exit;

if not LoadStringsFromFile(LedgerPath, Lines) then
begin
Log('DeskBox uninstall could not read the mapped-organize hidden ledger.');
Exit;
end;

Restored := 0;
for Index := 0 to GetArrayLength(Lines) - 1 do
begin
ItemPath := Trim(Lines[Index]);
if ItemPath = '' then
Continue;

Attributes := DeskBoxGetFileAttributes(ItemPath);
if (Attributes <> DeskBoxInvalidFileAttributes) and
((Attributes and DeskBoxFileAttributeHidden) <> 0) then
begin
if DeskBoxSetFileAttributes(ItemPath, Attributes and (not DeskBoxFileAttributeHidden)) then
Restored := Restored + 1
else
Log('DeskBox uninstall could not restore a hidden desktop item: ' + ItemPath);
end;
end;

SaveStringToFile(LedgerPath, '', False);
Log(Format('DeskBox uninstall restored %d desktop items hidden by mapped organize.', [Restored]));
end;
5 changes: 5 additions & 0 deletions installer/DeskBox.Uninstall.iss
Original file line number Diff line number Diff line change
Expand Up @@ -949,10 +949,15 @@ begin
end;
end;

#include "DeskBox.ForkMappedOrganize.iss"

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usUninstall then
begin
StopDeskBoxProcess;
RestoreMappedOrganizeHiddenDesktopItems;
end;

if CurUninstallStep = usPostUninstall then
begin
Expand Down
68 changes: 54 additions & 14 deletions src/DeskBox/Controls/DesktopOrganizationTaskView.MappedOrganize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,62 @@
namespace DeskBox.Controls;

/// <summary>
/// Fork feature 「映射整理」: the preview's 「只映射,不移动文件」 option. When
/// checked, confirming the preview creates mapped-organize widgets that only
/// record membership; no file leaves the Desktop folders.
/// Fork feature 「映射整理」: the preview follows the global 「整理方式」 setting
/// (设置 → 桌面整理). The footer shows the current mode read-only with a link
/// to the setting; in 「只映射」 mode confirming the preview creates
/// mapped-organize widgets that only record membership and no file leaves the
/// Desktop folders.
/// </summary>
public sealed partial class DesktopOrganizationTaskView
{
private bool _mapOnlyInitialized;
private bool _organizeModeInitialized;

private void MapOnlyCheckBox_Loaded(object sender, RoutedEventArgs e)
private void OrganizeModeLink_Loaded(object sender, RoutedEventArgs e)
{
if (_mapOnlyInitialized)
RefreshOrganizeModeLink();
if (_organizeModeInitialized)
{
return;
}

_mapOnlyInitialized = true;
MapOnlyCheckBox.Content = T("MappedOrganize.Preview.MapOnly");
ToolTipService.SetToolTip(MapOnlyCheckBox, T("MappedOrganize.Preview.MapOnlyDescription"));
OrganizationCompleted += (_, _) => MapOnlyCheckBox.Visibility = Visibility.Collapsed;
_organizeModeInitialized = true;
OrganizationCompleted += (_, _) => OrganizeModeLink.Visibility = Visibility.Collapsed;
ForkOrganizeModeSettings.Changed += _ => DispatcherQueue?.TryEnqueue(RefreshOrganizeModeLink);
}

private void OrganizeModeLink_Click(object sender, RoutedEventArgs e)
{
try
{
App.Current.ShowSettings("DesktopOrganizationSettings");
}
catch (Exception ex)
{
App.Log($"[MappedOrganize] Opening the organize-mode setting failed: {ex.Message}");
}
}

private void RefreshOrganizeModeLink()
{
DesktopOrganizeMode mode = ForkOrganizeModeSettings.Load();
OrganizeModeLink.Content = ForkOrganizeModeText.Format(
ForkOrganizeModeText.Key.PreviewModeFormat,
ForkOrganizeModeText.ModeName(mode)) +
ForkOrganizeModeText.Get(ForkOrganizeModeText.Key.PreviewChange);
ToolTipService.SetToolTip(OrganizeModeLink, ForkOrganizeModeText.Get(mode == DesktopOrganizeMode.MapOnly
? ForkOrganizeModeText.Key.PreviewTooltipMapOnly
: ForkOrganizeModeText.Key.PreviewTooltipMove));
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(
OrganizeModeLink,
ForkOrganizeModeText.Get(ForkOrganizeModeText.Key.SettingTitle));
}

/// <summary>Returns true when the mapped path handled the confirm click.</summary>
private async Task<bool> TryRunMappedOrganizeAsync(DesktopOrganizationPlan previewPlan)
{
if (MapOnlyCheckBox.IsChecked != true)
DesktopOrganizeMode mode = ForkOrganizeModeSettings.Load();
RefreshOrganizeModeLink();
if (!ForkOrganizeModePolicy.ConfirmMapsInsteadOfMoving(mode))
{
return false;
}
Expand All @@ -44,6 +75,15 @@ private async Task<bool> TryRunMappedOrganizeAsync(DesktopOrganizationPlan previ
return true;
}

// Entries the user deselected in the preview stay on the desktop
// (「放回桌面」) instead of being swept up by automatic sorting.
List<string> keepOnDesktop = previewPlan.Targets
.SelectMany(target =>
_targetSelections.TryGetValue(target.SourceBucketId, out DesktopOrganizationTargetSelection? selection) &&
!selection.IsSelected
? target.Items.Select(item => item.SourcePath)
: target.Items.Where(item => _excludedSourcePaths.Contains(item.SourcePath)).Select(item => item.SourcePath))
.ToList();
List<MappedOrganizeGroup> groups = previewPlan.Targets
.Where(target => !_targetSelections.TryGetValue(target.SourceBucketId, out DesktopOrganizationTargetSelection? selection) ||
selection.IsSelected)
Expand All @@ -70,10 +110,10 @@ private async Task<bool> TryRunMappedOrganizeAsync(DesktopOrganizationPlan previ
_isExecuting = true;
ExecuteButton.IsEnabled = false;
CancelButton.IsEnabled = false;
MapOnlyCheckBox.IsEnabled = false;
OrganizeModeLink.IsEnabled = false;
try
{
int count = await service.ApplyGroupsAsync(groups);
int count = await service.ApplyGroupsAsync(groups, keepOnDesktop);
_hasCompletedExecution = true;
ResultInfo.Severity = InfoBarSeverity.Success;
ResultInfo.Title = T("DesktopOrganization.Result.SuccessTitle");
Expand All @@ -100,7 +140,7 @@ private async Task<bool> TryRunMappedOrganizeAsync(DesktopOrganizationPlan previ
{
_isExecuting = false;
CancelButton.IsEnabled = true;
MapOnlyCheckBox.IsEnabled = true;
OrganizeModeLink.IsEnabled = true;
DoneButton.IsEnabled = true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/DeskBox/Controls/DesktopOrganizationTaskView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@
<Grid ColumnDefinitions="*,Auto,Auto,Auto,Auto" ColumnSpacing="8">
<TextBlock x:Name="FooterSummaryText" VerticalAlignment="Center" TextWrapping="Wrap"
Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
<CheckBox x:Name="MapOnlyCheckBox" Grid.Column="1" MinWidth="0" VerticalAlignment="Center"
Loaded="MapOnlyCheckBox_Loaded" />
<HyperlinkButton x:Name="OrganizeModeLink" Grid.Column="1" MinWidth="0" VerticalAlignment="Center"
Loaded="OrganizeModeLink_Loaded" Click="OrganizeModeLink_Click" />
<Button x:Name="UndoButton" Grid.Column="1" Click="UndoButton_Click" Visibility="Collapsed" />
<Button x:Name="AbandonUndoButton" Grid.Column="2" Click="AbandonUndoButton_Click" Visibility="Collapsed" />
<Button x:Name="CancelButton" Grid.Column="3" Click="CancelButton_Click" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
using DeskBox.Models;
using DeskBox.Services;
using Microsoft.UI.Xaml.Controls;

namespace DeskBox.Controls.WidgetContents;

/// <summary>Fork feature 「映射整理」: blank-area menu entries of a mapped-organize widget.</summary>
/// <summary>
/// Fork feature 「映射整理」: blank-area menu entries of a mapped-organize widget,
/// and 「放回桌面」 for its items (the upstream 「移回桌面」 row, which in a mapped
/// widget would have nothing to move, unmaps instead).
/// </summary>
public sealed partial class FileSurfaceContent
{
private string LocalizeFileItemMenu(string key) =>
ViewModel.IsMappedOrganizeWidget && string.Equals(key, "Widget.MoveBackToDesktop", StringComparison.Ordinal)
? ForkOrganizeModeText.Get(ForkOrganizeModeText.Key.MenuKeepOnDesktop)
: T(key);

/// <summary>Returns true when the items belonged to a mapped widget and were put back on the desktop.</summary>
private bool TryKeepMappedItemsOnDesktop(IReadOnlyList<WidgetItem> items)
{
if (!ViewModel.IsMappedOrganizeWidget || MappedOrganizeService.Current is not { } service)
{
return false;
}

int kept = service.KeepOnDesktop(items
.Select(item => item.Path)
.Where(path => !string.IsNullOrWhiteSpace(path)));
ShowFeedback(new WidgetFeedbackRequest(
kept > 0
? ForkOrganizeModeText.Format(ForkOrganizeModeText.Key.KeptOnDesktopFormat, kept)
: T("Widget.NoItemsMoved"),
kept > 0 ? WidgetFeedbackSeverity.Success : WidgetFeedbackSeverity.Info,
"mapped-keep-desktop"));
return true;
}

private void AddMappedOrganizeMenuItems(MenuFlyout flyout)
{
if (!ViewModel.IsMappedOrganizeWidget || MappedOrganizeService.Current is not { } service)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ private FileItemMenuActions CreateFileItemMenuActions()
{
return new FileItemMenuActions(
CreateMenuItem,
T,
LocalizeFileItemMenu,
ActivateItemAsync,
cut => RunAsync(
() => CopySelectionToClipboardAsync(cut)),
Expand Down Expand Up @@ -2057,6 +2057,11 @@ private async Task MoveSelectedItemsBackToDesktopAsync()
return;
}

if (TryKeepMappedItemsOnDesktop(items))
{
return;
}

if (TryBlockTransferMutation(items))
{
return;
Expand Down
17 changes: 17 additions & 0 deletions src/DeskBox/Helpers/ForkOrganizeModeText.Culture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace DeskBox.Services;

/// <summary>GOXF fork: the UI culture for <see cref="ForkOrganizeModeText"/>, read from the running app (main or settings process).</summary>
public static partial class ForkOrganizeModeText
{
private static string? CurrentCulture()
{
try
{
return App.Current?.LocalizationService?.CurrentCultureName;
}
catch (Exception)
{
return null;
}
}
}
7 changes: 7 additions & 0 deletions src/DeskBox/Services/DesktopAutoOrganizationWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,13 @@ private async Task ProcessAfterSettleAsync(
return;
}

// GOXF fork: 整理方式 = 只映射 → never move; mapped routing takes it.
if (MappedOrganizeService.TryTakeOverAutoOrganization(workItem.Path))
{
MarkIgnored(workItem);
return;
}

DesktopOrganizationFileSnapshot item =
_scanner.CreateAutoOrganizationSnapshot(workItem.Path);
if (!item.IsEligible)
Expand Down
Loading
Loading