Skip to content

Commit

Permalink
Feature: Added support for SeerPro's "Track selected file" setting
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 committed May 8, 2024
1 parent 49a1664 commit b62192e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private async Task SwitchPopupPreviewAsync()
if (IsExecutable)
{
var provider = await previewPopupService.GetProviderAsync();
if (provider is null)
if (provider is null || !provider.IsTrackSelectionSettingEnabled)
return;

var itemPath = context.SelectedItem?.ItemPath;
Expand Down
7 changes: 7 additions & 0 deletions src/Files.App/Data/Contracts/IPreviewPopupProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,12 @@ public interface IPreviewPopupProvider
/// </summary>
/// <returns></returns>
Task<bool> DetectAvailability();

/// <summary>
/// Indicates if the provider is configured to track the selected file
/// This is used to update the preview popup when the selected file changes
/// </summary>
/// <returns></returns>
bool IsTrackSelectionSettingEnabled { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,7 @@ async Task<int> QuickLookServerAvailable()
return false;
}
}

public bool IsTrackSelectionSettingEnabled => true;
}
}
44 changes: 43 additions & 1 deletion src/Files.App/Services/PreviewPopupProviders/SeerProProvider.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Services;
using System.IO;
using System.Runtime.InteropServices;
using Vanara.PInvoke;

Expand Down Expand Up @@ -43,5 +43,47 @@ public async Task<bool> DetectAvailability()
var handle = User32.FindWindow("SeerWindowClass", null).DangerousGetHandle();
return handle != IntPtr.Zero && handle.ToInt64() != -1;
}

public bool IsTrackSelectionSettingEnabled => DetectTrackSelectionSetting().Result;

private Task<bool> DetectTrackSelectionSetting()
{
bool trackSelectedFile = true;

// List of possible paths for the Seer Pro settings file
string[] paths =
{
Environment.ExpandEnvironmentVariables("%USERPROFILE%\\Documents\\Seer\\uwp.ini"),
Environment.ExpandEnvironmentVariables("%USERPROFILE%\\appdata\\Local\\Corey\\Seer\\uwp.ini"),
Environment.ExpandEnvironmentVariables("%USERPROFILE%\\Documents\\Seer\\config.ini")
};

// Find the first existing path
foreach (var path in paths)
{
if (File.Exists(path))
{
// Read the settings file and look for the tracking_file setting
string[] lines = File.ReadAllLines(path);

foreach (var line in lines)
{
if (line.StartsWith("tracking_file", StringComparison.OrdinalIgnoreCase))
{
string[] keyValue = line.Split('=');
if (keyValue.Length == 2 && bool.TryParse(keyValue[1].Trim(), out bool isTrackingFile))
{
trackSelectedFile = isTrackingFile;
break;
}
}
}

break;
}
}

return Task.FromResult(trackSelectedFile);
}
}
}

0 comments on commit b62192e

Please sign in to comment.