Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Added support for SeerPro's "Track selected file" setting #15339

Merged
merged 10 commits into from
May 12, 2024

Conversation

yaira2
Copy link
Member

@yaira2 yaira2 commented May 8, 2024

Resolved / Related Issues

To prevent extra work, all changes to the Files codebase must link to an approved issue marked as Ready to build. Please insert the issue number following the hashtag with the issue number that this Pull Request resolves.

Steps used to test these changes

Stability is a top priority for Files and all changes are required to go through testing before being merged into the repo. Please include a list of steps that you used to test this PR.

  1. Install SeerPro
  2. Confirm that the follow selection setting in SeerPro is reflected in Files
    • This setting is only detected once, Files requires a restart after updating the setting in SeerPro

@yaira2 yaira2 marked this pull request as draft May 8, 2024 20:27
@yaira2 yaira2 force-pushed the ya/FollowSeerProSettings branch from 626e1c6 to b62192e Compare May 8, 2024 20:47
@yaira2
Copy link
Member Author

yaira2 commented May 8, 2024

Fyi @ccseer

@yaira2 yaira2 force-pushed the ya/FollowSeerProSettings branch from 0c1deac to de9894b Compare May 8, 2024 21:18
@yaira2 yaira2 marked this pull request as ready for review May 8, 2024 22:35
@ccseer
Copy link

ccseer commented May 9, 2024 via email

@yaira2
Copy link
Member Author

yaira2 commented May 9, 2024

I tested the store version and it works correct, @ccseer can you confirm this works for the win32 version?

@yaira2 yaira2 requested a review from 0x5bfa May 9, 2024 16:02
Copy link
Member

@0x5bfa 0x5bfa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code wise, looks good but some parts.

Update SeerProProvider.cs

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

Co-Authored-By: 0x5bfa <[email protected]>
@yaira2 yaira2 force-pushed the ya/FollowSeerProSettings branch from 5fdfb3d to 9ec9987 Compare May 9, 2024 20:04
@yaira2 yaira2 requested a review from 0x5bfa May 9, 2024 20:04
@ccseer
Copy link

ccseer commented May 10, 2024

I tested the store version and it works correct, @ccseer can you confirm this works for the win32 version?

do i need to build from the source to test?
I just read the code, the default path for win32 is from REG, but it's not in your code.
Am I missing something?

Copy link
Member

@0x5bfa 0x5bfa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I concern, what do you think?
Putting aside it, LGTM, code wise.

@yaira2
Copy link
Member Author

yaira2 commented May 10, 2024

I just read the code, the default path for win32 is from REG, but it's not in your code.

I didn't implement anything for the registry, I'll modify this PR to account for that possibility.

@yaira2 yaira2 requested a review from ccseer May 12, 2024 02:52
Copy link

@ccseer ccseer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

hi, in the REG, you can just read tracking_file from Computer\HKEY_CURRENT_USER\SOFTWARE\Corey\Seer
General group is only for ini files.

Copy link

@ccseer ccseer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I just got some code from Copilot, hope it helps.

using System;
using Microsoft.Win32;

class Program
{
    static void Main()
    {
        // Open the subkey
        using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Corey\Seer"))
        {
            if (key != null)
            {
                // Attempt to read the value
                object value = key.GetValue("tracking_file");

                if (value != null)
                {
                    // Convert the value to a boolean
                    bool trackingFile = Convert.ToBoolean(value);

                    Console.WriteLine($"tracking_file value: {trackingFile}");
                }
                else
                {
                    Console.WriteLine("The 'tracking_file' value does not exist.");
                }
            }
            else
            {
                Console.WriteLine("The specified registry key does not exist.");
            }
        }
    }
}

@ccseer
Copy link

ccseer commented May 12, 2024

  1. Double Backslashes in Key Name: In the keyName variable, you've used double backslashes (\) at the beginning and within the path. When specifying registry paths in C#, you should use a single backslash () as the separator, and there's no need for leading backslashes. The correct format for the key name would be @"HKEY_CURRENT_USER\Software\Corey\Seer".
  2. Registry.GetValue Usage: The Registry.GetValue method is correctly used to read a value from the registry. However, the third parameter you've passed is null, which is the default value returned if the specified valueName does not exist. If you're trying to read a boolean value named General, ensure that General is the correct name of the value you're interested in. If you're trying to read a value named tracking_file (as mentioned in your previous question), you should replace "General" with "tracking_file".
  3. Return Type: The snippet ends with return Task.FromResult(true);, which suggests you want this code to be part of an asynchronous method returning a Task. However, the code snippet as provided does not include the method signature, so it's unclear how this fits into the larger context of your application.
using System;
using System.Threading.Tasks;
using Microsoft.Win32;

public class RegistryReader
{
    public Task<bool> ReadTrackingFileValueAsync()
    {
        var keyName = @"HKEY_CURRENT_USER\Software\Corey\Seer";
        var value = Registry.GetValue(keyName, "tracking_file", null);

        if (value is not null)
        {
            // Assuming the value is stored as an integer (0 for false, non-zero for true)
            bool trackSelectedFile = Convert.ToBoolean(value);
            return Task.FromResult(trackSelectedFile);
        }
        else
        {
            // Return false or handle the case where the value does not exist
            return Task.FromResult(false);
        }
    }
}

@hishitetsu
Copy link
Member

When I tried to test it, it crashed with the following exception:

2024-05-12 22:17:34.4955|Error|System.ArgumentException: Registry key name must start with a valid base key name. (Parameter 'keyName')
   at Microsoft.Win32.Registry.GetBaseKeyFromKeyName(String keyName, String& subKeyName)
   at Microsoft.Win32.Registry.GetValue(String keyName, String valueName, Object defaultValue)
   at Files.App.Services.PreviewPopupProviders.SeerProProvider.DetectTrackSelectionSetting()
   at Files.App.Services.PreviewPopupProviders.SeerProProvider.get_IsTrackSelectionSettingEnabled()
   at Files.App.Services.PreviewPopupProviders.SeerProProvider.SwitchPreviewAsync(String path)
   at Files.App.Actions.LaunchPreviewPopupAction.SwitchPopupPreviewAsync()
   at Files.App.Actions.LaunchPreviewPopupAction.Context_PropertyChanged(Object sender, PropertyChangedEventArgs e)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.<>c__DisplayClass2_0.<Post>b__0()

@yaira2
Copy link
Member Author

yaira2 commented May 12, 2024

@hishitetsu can you try with the latest commit?

@yaira2
Copy link
Member Author

yaira2 commented May 12, 2024

Everything looks good from my end

Copy link
Member

@0x5bfa 0x5bfa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, code wise.

@hishitetsu
Copy link
Member

It still tracks the file regardless of the settings in my environment.

@ccseer
Copy link

ccseer commented May 12, 2024 via email

@yaira2
Copy link
Member Author

yaira2 commented May 12, 2024

It still tracks the file regardless of the settings in my environment.

Did you restart Files in between changing the setting?

@yaira2
Copy link
Member Author

yaira2 commented May 12, 2024

I tested with the Win32 version and confirm it's working as expected. The one thing to note is that a restart of Files is required after changing the setting in Seer.

@yaira2 yaira2 merged commit de2c165 into main May 12, 2024
6 checks passed
@yaira2 yaira2 added ready to merge Pull requests that are approved and ready to merge and removed needs - code review labels May 12, 2024
@yaira2 yaira2 deleted the ya/FollowSeerProSettings branch May 26, 2024 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Pull requests that are approved and ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Seer preview should close when selecting a different file via the mouse
4 participants