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
36 changes: 19 additions & 17 deletions src/Sidekick.Wpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,30 @@
{
logger.LogInformation("[MainWindow] Opening view: " + url);

var settingsService = scope.ServiceProvider.GetRequiredService<ISettingsService>();
CloseOnBlur = await settingsService.GetBool(SettingKeys.OverlayCloseWithMouse);
OriginalFocusedWindow = User32.GetForegroundWindow();

await Dispatch(async () =>
{
var settingsService = scope.ServiceProvider.GetRequiredService<ISettingsService>();
CloseOnBlur = await settingsService.GetBool(SettingKeys.OverlayCloseWithMouse);
OriginalFocusedWindow = User32.GetForegroundWindow();

Show();

if (!IsReady) NextPath = url;
else Navigate(url);
if (!IsReady)
{
NextPath = url;
}
else
{
Navigate(url);
}

Activate();
await NormalizeView();
Activate();

// Attempt to set focus back to the original window
if (ViewType == SidekickViewType.Overlay && !CloseOnBlur && OriginalFocusedWindow != IntPtr.Zero)
{
//User32.SetForegroundWindow(OriginalFocusedWindow);
User32.SetForegroundWindow(OriginalFocusedWindow);
}
});
}
Expand All @@ -106,7 +112,6 @@

_ = Dispatch(async () =>
{
IsReady = true;
NavigationManager = navigationManager;
View = view;

Expand All @@ -120,9 +125,11 @@

WebView.Visibility = Visibility.Visible;
SetWebViewDebugging();
if (NextPath != null) NavigationManager.NavigateTo(NextPath);

await NormalizeView();
Navigate(NextPath);

IsReady = true;
});
}

Expand Down Expand Up @@ -167,13 +174,8 @@
switch (ViewType)
{
case SidekickViewType.Overlay:
#if DEBUG
Topmost = false;
ShowInTaskbar = true;
#else
Topmost = true;
ShowInTaskbar = false;
#endif
ResizeMode = ResizeMode.CanResize;
break;

Expand Down Expand Up @@ -272,7 +274,7 @@

private void Navigate(string? url)
{
if (NavigationManager == null || !IsReady || string.IsNullOrEmpty(url)) return;
if (NavigationManager == null || string.IsNullOrEmpty(url)) return;

NavigationManager.NavigateTo(url);
}
Expand Down Expand Up @@ -317,7 +319,7 @@
{
base.OnDeactivated(e);

if (ViewType == SidekickViewType.Overlay && CloseOnBlur)
if (IsReady && ViewType == SidekickViewType.Overlay && CloseOnBlur)
{
CloseView();
}
Expand All @@ -341,7 +343,7 @@
return;
#endif

WebView.WebView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;

Check warning on line 346 in src/Sidekick.Wpf/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / tests

Unreachable code detected

Check warning on line 346 in src/Sidekick.Wpf/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / tests

Unreachable code detected
WebView.WebView.CoreWebView2.Settings.AreBrowserAcceleratorKeysEnabled = false;
WebView.WebView.CoreWebView2.Settings.AreDevToolsEnabled = false;
}
Expand Down
Loading