Skip to content
Merged
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
39 changes: 30 additions & 9 deletions QuickLook/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,19 @@ protected override void OnStartup(StartupEventArgs e)
RunListener(e);

// First instance: run and preview this file
if (e.Args.Any() && (Directory.Exists(e.Args.First()) || File.Exists(e.Args.First())))
PipeServerManager.SendMessage(PipeMessages.Toggle, e.Args.First());
if (e.Args.Any())
{
try
{
var path = Path.GetFullPath(e.Args.First());
if (Directory.Exists(path) || File.Exists(path))
PipeServerManager.SendMessage(PipeMessages.Toggle, path);
}
catch
{
// Invalid path, ignore
}
Comment on lines +137 to +140
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The catch block is too broad and catches all exceptions. According to the PR description, specific exceptions should be caught: ArgumentException, SecurityException, NotSupportedException, and PathTooLongException. The current implementation could silently swallow unexpected exceptions that should be handled or logged differently. Consider using a filtered catch clause to only handle path-related exceptions.

Copilot uses AI. Check for mistakes.
}

// Exception handling events which are not caught in the Task thread
TaskScheduler.UnobservedTaskException += (_, e) =>
Expand Down Expand Up @@ -290,16 +301,26 @@ private bool EnsureFirstInstance(string[] args)
return true;

// Second instance: preview this file
if (args.Any() && (Directory.Exists(args.First()) || File.Exists(args.First())))
if (args.Any())
{
PipeServerManager.SendMessage(PipeMessages.Toggle, args.First(), [.. args.Skip(1)]);
try
{
var path = Path.GetFullPath(args.First());
if (Directory.Exists(path) || File.Exists(path))
{
PipeServerManager.SendMessage(PipeMessages.Toggle, path, [.. args.Skip(1)]);
return false;
}
}
catch
{
// Invalid path, continue to show duplicate message
}
Comment on lines +315 to +318
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The catch block is too broad and catches all exceptions. According to the PR description, specific exceptions should be caught: ArgumentException, SecurityException, NotSupportedException, and PathTooLongException. The current implementation could silently swallow unexpected exceptions that should be handled or logged differently. Consider using a filtered catch clause to only handle path-related exceptions.

Copilot uses AI. Check for mistakes.
}

// Second instance: duplicate
else
{
MessageBox.Show(TranslationHelper.Get("APP_SECOND_TEXT"), TranslationHelper.Get("APP_SECOND"),
MessageBoxButton.OK, MessageBoxImage.Information);
}
MessageBox.Show(TranslationHelper.Get("APP_SECOND_TEXT"), TranslationHelper.Get("APP_SECOND"),
MessageBoxButton.OK, MessageBoxImage.Information);
Comment on lines 321 to +323
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The control flow is incorrect. The duplicate message MessageBox will now always be shown, even when a valid file path is successfully processed. Previously, the else clause ensured the message was only shown when no arguments were provided or the path was invalid. This breaks the second instance behavior - when a user opens a file from a second instance, they will see both the file preview AND the duplicate instance message. The MessageBox call on lines 322-323 should only execute when args are empty or when the path is invalid/doesn't exist.

Copilot uses AI. Check for mistakes.

return false;
}
Expand Down
Loading