Skip to content

Commit de2c165

Browse files
yaira20x5bfahishitetsu
authored
Feature: Added support for SeerPro's "Track selected file" setting (#15339)
Co-authored-by: 0x5bfa <[email protected]> Co-authored-by: hishitetsu <[email protected]>
1 parent 318bbb3 commit de2c165

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

src/Files.App/Services/PreviewPopupProviders/SeerProProvider.cs

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Files.App.Services;
4+
using Microsoft.Win32;
5+
using System.IO;
56
using System.Runtime.InteropServices;
67
using Vanara.PInvoke;
78

@@ -34,6 +35,14 @@ public async Task TogglePreviewPopupAsync(string path)
3435

3536
public async Task SwitchPreviewAsync(string path)
3637
{
38+
// Close preview window is track selection setting is disabled
39+
if (!IsTrackSelectionSettingEnabled && !string.IsNullOrEmpty(CurrentPath))
40+
{
41+
await TogglePreviewPopupAsync(CurrentPath);
42+
return;
43+
}
44+
45+
// Update the preview window if the path changed
3746
if (CurrentPath is not null && path != CurrentPath)
3847
await TogglePreviewPopupAsync(path);
3948
}
@@ -43,5 +52,64 @@ public async Task<bool> DetectAvailability()
4352
var handle = User32.FindWindow("SeerWindowClass", null).DangerousGetHandle();
4453
return handle != IntPtr.Zero && handle.ToInt64() != -1;
4554
}
55+
56+
private bool? _IsTrackSelectionSettingEnabledCache;
57+
private bool IsTrackSelectionSettingEnabled
58+
{
59+
get
60+
{
61+
if (_IsTrackSelectionSettingEnabledCache is null)
62+
_IsTrackSelectionSettingEnabledCache = DetectTrackSelectionSetting().Result;
63+
64+
return _IsTrackSelectionSettingEnabledCache.Value;
65+
}
66+
}
67+
68+
private Task<bool> DetectTrackSelectionSetting()
69+
{
70+
bool trackSelectedFile = true;
71+
72+
var keyName = @"HKEY_CURRENT_USER\Software\Corey\Seer";
73+
var value = Registry.GetValue(keyName, "tracking_file", null);
74+
75+
if (value?.ToString() == "false")
76+
return Task.FromResult(false);
77+
78+
// List of possible paths for the Seer Pro settings file
79+
string[] paths =
80+
{
81+
Environment.ExpandEnvironmentVariables("%USERPROFILE%\\Documents\\Seer\\uwp.ini"),
82+
Environment.ExpandEnvironmentVariables("%USERPROFILE%\\appdata\\Local\\Packages\\CNABA5E861-AC2A-4523-B3C1.Seer-AWindowsQuickLookTo_p7t0z30wh4868\\LocalCache\\Local\\Corey\\Seer\\uwp.ini"),
83+
Environment.ExpandEnvironmentVariables("%USERPROFILE%\\appdata\\Local\\Corey\\Seer\\uwp.ini"),
84+
Environment.ExpandEnvironmentVariables("%USERPROFILE%\\Documents\\Seer\\config.ini")
85+
};
86+
87+
// Find the first existing path
88+
foreach (var path in paths)
89+
{
90+
if (File.Exists(path))
91+
{
92+
// Read the settings file and look for the tracking_file setting
93+
string[] lines = File.ReadAllLines(path);
94+
95+
foreach (var line in lines)
96+
{
97+
if (line.StartsWith("tracking_file", StringComparison.OrdinalIgnoreCase))
98+
{
99+
string[] keyValue = line.Split('=');
100+
if (keyValue.Length == 2 && bool.TryParse(keyValue[1].Trim(), out bool isTrackingFile))
101+
{
102+
trackSelectedFile = isTrackingFile;
103+
break;
104+
}
105+
}
106+
}
107+
108+
break;
109+
}
110+
}
111+
112+
return Task.FromResult(trackSelectedFile);
113+
}
46114
}
47115
}

0 commit comments

Comments
 (0)