Skip to content

Commit e2fa226

Browse files
committed
fix: survive sleep/hibernate - logon Run entry for context menu auto-restore
1 parent f328ced commit e2fa226

7 files changed

Lines changed: 76 additions & 7 deletions

File tree

‎Fujify/Assets/images/logo.icns‎

857 KB
Binary file not shown.

‎Fujify/Assets/images/logo.ico‎

43.6 KB
Loading

‎Fujify/Services/WindowsContextMenuService.cs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,39 @@ public static string BuildAppliesToFilter()
290290
return string.Join(" OR ", parts);
291291
}
292292

293+
private const string LogonRunKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Run";
294+
private const string LogonRunValueName = "FujifierContextMenu";
295+
296+
/// <summary>
297+
/// Writes (or removes) the HKCU Run entry that re-registers the context
298+
/// menu on every user logon. This ensures the shell verb keys survive
299+
/// Windows deep-sleep / hibernation cycles, where the OS can silently
300+
/// discard HKCU\Software\Classes\SystemFileAssociations shell sub-keys.
301+
/// </summary>
302+
[SupportedOSPlatform("windows")]
303+
private static void SetLogonAutoRestore(bool enable)
304+
{
305+
try
306+
{
307+
using var runKey = Registry.CurrentUser.OpenSubKey(LogonRunKeyPath, writable: true);
308+
if (runKey == null) return;
309+
310+
if (enable)
311+
{
312+
string exePath = GetExecutablePath();
313+
runKey.SetValue(LogonRunValueName, $"\"{exePath}\" --register-context-menu");
314+
}
315+
else
316+
{
317+
runKey.DeleteValue(LogonRunValueName, throwOnMissingValue: false);
318+
}
319+
}
320+
catch (Exception ex)
321+
{
322+
Debug.WriteLine($"[WindowsContextMenuService] SetLogonAutoRestore({enable}): {ex.Message}");
323+
}
324+
}
325+
293326
public static bool RegisterContextMenu()
294327
{
295328
if (!OperatingSystem.IsWindows()) return false;
@@ -322,6 +355,9 @@ public static bool RegisterContextMenu()
322355
// 3. Ensure Explorer does not truncate context menu when selecting >15 files
323356
EnsureMultipleInvokePromptMinimum();
324357

358+
// 4. Write logon auto-restore entry so Windows sleep/hibernate does not permanently drop our shell keys
359+
SetLogonAutoRestore(true);
360+
325361
NotifyShell();
326362
return true;
327363
}
@@ -352,6 +388,9 @@ public static bool UnregisterContextMenu()
352388
UnregisterExtensionVerb(@"Software\Classes\" + ext);
353389
}
354390

391+
// Remove logon auto-restore entry
392+
SetLogonAutoRestore(false);
393+
355394
// If running elevated (e.g. uninstaller), also clean up HKLM
356395
try
357396
{

‎Fujify/Views/PreferencesWindow.axaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,9 +1001,9 @@
10011001
<!-- Footer Buttons -->
10021002
<Border Grid.Row="2" Margin="0,14,0,0" Padding="0,12,0,0" BorderBrush="{DynamicResource AppEdgeBrush}" BorderThickness="0,1,0,0">
10031003
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10">
1004-
<Button Content="{loc:Loc Cancel}" Command="{Binding CancelCommand}" Classes="secondary" Width="90" Height="34" CornerRadius="17"
1004+
<Button Content="{loc:Loc Cancel}" Command="{Binding CancelCommand}" Classes="secondary" MinWidth="90" Height="36" Padding="18,0" CornerRadius="18"
10051005
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
1006-
<Button Content="{loc:Loc Done}" Command="{Binding SaveCommand}" Classes="primary" Width="90" Height="34" CornerRadius="17"
1006+
<Button Content="{loc:Loc Done}" Command="{Binding SaveCommand}" Classes="primary" MinWidth="90" Height="36" Padding="18,0" CornerRadius="18"
10071007
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
10081008
</StackPanel>
10091009
</Border>

‎build_macos.ps1‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ $infoPlist = @"
5454
<key>CFBundleExecutable</key>
5555
<string>Fujifier</string>
5656
<key>CFBundleIconFile</key>
57-
<string>logo.ico</string>
57+
<string>logo.icns</string>
5858
<key>NSHighResolutionCapable</key>
5959
<true/>
6060
<key>LSMinimumSystemVersion</key>
@@ -145,8 +145,12 @@ if ($macDngLab) {
145145
[IO.File]::WriteAllText((Join-Path $macOsDir "exiftool"), $exifToolScript.Replace("`r`n", "`n"))
146146

147147
[IO.File]::WriteAllText((Join-Path $contentsDir "Info.plist"), $infoPlist.Replace("`r`n", "`n"))
148+
if (Test-Path "$repoRoot\Fujify\Assets\images\logo.icns") {
149+
Copy-Item -Path "$repoRoot\Fujify\Assets\images\logo.icns" -Destination (Join-Path $resourcesDir "logo.icns") -Force
150+
}
148151
Copy-Item -Path "$repoRoot\Fujify\Assets\images\logo.ico" -Destination (Join-Path $resourcesDir "logo.ico") -Force
149-
Copy-Item -Path "$repoRoot\Fujify\Assets\images\logos.png" -Destination (Join-Path $resourcesDir "logo.png") -Force
152+
Copy-Item -Path "$repoRoot\Fujify\Assets\images\logoXL.png" -Destination (Join-Path $resourcesDir "logo.png") -Force
153+
Copy-Item -Path "$repoRoot\Fujify\Assets\images\logos.png" -Destination (Join-Path $resourcesDir "logos.png") -Force
150154

151155
# Copy Quick Actions
152156
$repoQuickActions = if (Test-Path "$repoRoot\Fujify\Assets\QuickActions") { "$repoRoot\Fujify\Assets\QuickActions" } elseif (Test-Path "$repoRoot\build_assets\mac\QuickActions") { "$repoRoot\build_assets\mac\QuickActions" } else { $null }
@@ -230,8 +234,12 @@ exit 127
230234
[IO.File]::WriteAllText((Join-Path $intelMacOsDir "exiftool"), $exifToolScript.Replace("`r`n", "`n"))
231235

232236
[IO.File]::WriteAllText((Join-Path $intelContentsDir "Info.plist"), $infoPlist.Replace("`r`n", "`n"))
237+
if (Test-Path "$repoRoot\Fujify\Assets\images\logo.icns") {
238+
Copy-Item -Path "$repoRoot\Fujify\Assets\images\logo.icns" -Destination (Join-Path $intelResourcesDir "logo.icns") -Force
239+
}
233240
Copy-Item -Path "$repoRoot\Fujify\Assets\images\logo.ico" -Destination (Join-Path $intelResourcesDir "logo.ico") -Force
234-
Copy-Item -Path "$repoRoot\Fujify\Assets\images\logos.png" -Destination (Join-Path $intelResourcesDir "logo.png") -Force
241+
Copy-Item -Path "$repoRoot\Fujify\Assets\images\logoXL.png" -Destination (Join-Path $intelResourcesDir "logo.png") -Force
242+
Copy-Item -Path "$repoRoot\Fujify\Assets\images\logos.png" -Destination (Join-Path $intelResourcesDir "logos.png") -Force
235243

236244
# Copy Quick Actions
237245
if ($repoQuickActions) {

‎installer.iss‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Name: "french"; MessagesFile: "compiler:Languages\French.isl"
5151

5252
[Tasks]
5353
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
54+
Name: "contextmenu"; Description: "Register right-click context menu for RAW files (requires Pro license)"; GroupDescription: "Context Menu Integration:"; Flags: unchecked
5455

5556
[Files]
5657
Source: "{#MyAppSourceDir}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
@@ -96,12 +97,31 @@ Root: HKA; Subkey: "Software\Classes\Fujifier.RAW"; ValueType: string; ValueName
9697
Root: HKA; Subkey: "Software\Classes\Fujifier.RAW\DefaultIcon"; ValueType: string; ValueData: """{app}\{#MyAppExeName}"",0"; Flags: uninsdeletekey
9798
Root: HKA; Subkey: "Software\Classes\Fujifier.RAW\shell\open\command"; ValueType: string; ValueData: """{app}\{#MyAppExeName}"" ""%1"""; Flags: uninsdeletekey
9899

100+
; ── Context menu: logon auto-restore ─────────────────────────────────────────
101+
; Windows can silently drop HKCU\Software\Classes\SystemFileAssociations shell
102+
; verb keys after the machine wakes from deep sleep / hibernation. To recover
103+
; without user intervention we write a lightweight logon entry that re-runs
104+
; --register-context-menu every time the user signs in. The entry is only
105+
; written when the user opted into the "contextmenu" installer task; it is
106+
; removed automatically on uninstall (uninsdeletevalue flag).
107+
Root: HKCU; Subkey: "Software\Microsoft\Windows\CurrentVersion\Run"; \
108+
ValueType: string; ValueName: "FujifierContextMenu"; \
109+
ValueData: """{app}\{#MyAppExeName}"" --register-context-menu"; \
110+
Flags: uninsdeletevalue; Tasks: contextmenu
111+
99112
[Run]
113+
; Register context menu immediately after install if the task was selected
114+
Filename: "{app}\{#MyAppExeName}"; Parameters: "--register-context-menu"; Flags: runhidden runasoriginaluser; Tasks: contextmenu
115+
; Launch the app after install (optional, user-visible checkbox)
100116
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent runasoriginaluser
101117

102118
[UninstallRun]
103119
Filename: "{app}\{#MyAppExeName}"; Parameters: "--unregister-context-menu"; Flags: runhidden; RunOnceId: "UnregContextMenu"
104120

121+
[UninstallDelete]
122+
; Belt-and-suspenders: also remove the logon auto-restore Run entry on uninstall
123+
; (--unregister-context-menu above already removes it at runtime; this covers edge cases)
124+
105125
[Code]
106126
procedure CleanRegistryKeysForRoot(RootKey: Integer; SubPrefix: String);
107127
var

‎package_macos.sh‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ EOF
176176
<key>CFBundleExecutable</key>
177177
<string>Fujifier</string>
178178
<key>CFBundleIconFile</key>
179-
<string>logo.ico</string>
179+
<string>logo.icns</string>
180180
<key>NSHighResolutionCapable</key>
181181
<true/>
182182
<key>LSMinimumSystemVersion</key>
@@ -228,8 +228,10 @@ EOF
228228
EOF
229229

230230
# Copy Icons
231+
cp "$REPO_ROOT/Fujify/Assets/images/logo.icns" "$APP_DIR/Contents/Resources/logo.icns"
231232
cp "$REPO_ROOT/Fujify/Assets/images/logo.ico" "$APP_DIR/Contents/Resources/logo.ico"
232-
cp "$REPO_ROOT/Fujify/Assets/images/logos.png" "$APP_DIR/Contents/Resources/logo.png"
233+
cp "$REPO_ROOT/Fujify/Assets/images/logoXL.png" "$APP_DIR/Contents/Resources/logo.png"
234+
cp "$REPO_ROOT/Fujify/Assets/images/logos.png" "$APP_DIR/Contents/Resources/logos.png"
233235

234236
# Copy Quick Actions
235237
if [ -d "$REPO_ROOT/Fujify/Assets/QuickActions" ]; then

0 commit comments

Comments
 (0)