Skip to content

A Swiss Army knife for developers.

Added Smart Detection on Windows

Etienne Baudoux42e90f18a731
diff --git a/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.cs b/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.cs
index 133f61821..210fd0d32 100644
--- a/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.cs
+++ b/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.cs
@@ -38,16 +38,24 @@ public partial class GridView<TKey, TElement> : JSStyledComponentBase
if (firstRender)
{
- Guard.IsNotNull(_scrollViewer);
- await (await JSModule).InvokeVoidAsync("initializeStickyHeaders", _scrollViewer.Id);
-
- if (ItemMinWidth > 0)
+ using (await Semaphore.WaitAsync(CancellationToken.None))
{
- await (await JSModule).InvokeVoidAsync("initializeDynamicItemSize", _scrollViewer.Id, ItemMinWidth);
+ Guard.IsNotNull(_scrollViewer);
+ await (await JSModule).InvokeVoidWithErrorHandlingAsync("initializeStickyHeaders", _scrollViewer.Id);
+
+ if (ItemMinWidth > 0)
+ {
+ await (await JSModule).InvokeVoidWithErrorHandlingAsync("initializeDynamicItemSize", _scrollViewer.Id, ItemMinWidth);
+ }
}
}
}
+ public override async ValueTask DisposeAsync()
+ {
+ await base.DisposeAsync();
+ }
+
internal Task OnItemClickAsync(TElement item)
{
return OnItemClick.InvokeAsync(item);
diff --git a/src/app/dev/DevToys.Blazor/Components/JSStyledComponentBase.cs b/src/app/dev/DevToys.Blazor/Components/JSStyledComponentBase.cs
index d34c66bb0..9c575424b 100644
--- a/src/app/dev/DevToys.Blazor/Components/JSStyledComponentBase.cs
+++ b/src/app/dev/DevToys.Blazor/Components/JSStyledComponentBase.cs
@@ -1,7 +1,10 @@
-namespace DevToys.Blazor.Components;
+using DevToys.Api;
+
+namespace DevToys.Blazor.Components;
public abstract class JSStyledComponentBase : StyledComponentBase, IAsyncDisposable
{
+ protected readonly DisposableSemaphore Semaphore = new();
private Task<IJSObjectReference>? _jsModule;
private DotNetObjectReference<JSStyledComponentBase>? _reference;
@@ -43,15 +46,29 @@ public abstract class JSStyledComponentBase : StyledComponentBase, IAsyncDisposa
}
}
+ protected override Task OnAfterRenderAsync(bool firstRender)
+ {
+ return base.OnAfterRenderAsync(firstRender);
+ }
+
/// <summary />
public virtual async ValueTask DisposeAsync()
{
_reference?.Dispose();
_reference = null;
- if (_jsModule is not null)
+ using (await Semaphore.WaitAsync(CancellationToken.None))
{
- await (await _jsModule).DisposeAsync();
+ try
+ {
+ if (_jsModule is not null)
+ {
+ await (await _jsModule).DisposeAsync();
+ }
+ }
+ catch (JSDisconnectedException)
+ {
+ }
}
GC.SuppressFinalize(this);
diff --git a/src/app/dev/DevToys.Blazor/Components/Layout/FocusTrapper/FocusTrapper.razor.cs b/src/app/dev/DevToys.Blazor/Components/Layout/FocusTrapper/FocusTrapper.razor.cs
index f07aa3d7e..1dbcb24a3 100644
--- a/src/app/dev/DevToys.Blazor/Components/Layout/FocusTrapper/FocusTrapper.razor.cs
+++ b/src/app/dev/DevToys.Blazor/Components/Layout/FocusTrapper/FocusTrapper.razor.cs
@@ -22,7 +22,7 @@ public partial class FocusTrapper : JSStyledComponentBase
public override async ValueTask DisposeAsync()
{
- await (await JSModule).InvokeVoidAsync("dispose", Element);
+ await (await JSModule).InvokeVoidWithErrorHandlingAsync("dispose", Element);
await base.DisposeAsync();
}
@@ -32,7 +32,10 @@ public partial class FocusTrapper : JSStyledComponentBase
if (firstRender)
{
- await (await JSModule).InvokeVoidAsync("initializeFocusTracking", Element);
+ using (await Semaphore.WaitAsync(CancellationToken.None))
+ {
+ await (await JSModule).InvokeVoidWithErrorHandlingAsync("initializeFocusTracking", Element);
+ }
}
}
diff --git a/src/app/dev/DevToys.Blazor/Components/Layout/SplitGrid/SplitGrid.razor.cs b/src/app/dev/DevToys.Blazor/Components/Layout/SplitGrid/SplitGrid.razor.cs
index a0d132b69..c50a2e695 100644
--- a/src/app/dev/DevToys.Blazor/Components/Layout/SplitGrid/SplitGrid.razor.cs
+++ b/src/app/dev/DevToys.Blazor/Components/Layout/SplitGrid/SplitGrid.razor.cs
@@ -62,7 +62,7 @@ public partial class SplitGrid : JSStyledComponentBase
public override async ValueTask DisposeAsync()
{
- await (await JSModule).InvokeVoidAsync("dispose", Element);
+ await (await JSModule).InvokeVoidWithErrorHandlingAsync("dispose", Element);
await base.DisposeAsync();
}
@@ -72,12 +72,15 @@ public partial class SplitGrid : JSStyledComponentBase
if (firstRender)
{
- await (await JSModule).InvokeVoidAsync(
+ using (await Semaphore.WaitAsync(CancellationToken.None))
+ {
+ await (await JSModule).InvokeVoidWithErrorHandlingAsync(
"initializeSplitGrid",
Element,
_gutterElement,
GutterOrientation == Orientation.Vertical,
MinimumCellSize);
+ }
}
}
diff --git a/src/app/dev/DevToys.Blazor/Components/Menu/NavBar/NavBar.razor.cs b/src/app/dev/DevToys.Blazor/Components/Menu/NavBar/NavBar.razor.cs
index 4f273e62e..789fa8845 100644
--- a/src/app/dev/DevToys.Blazor/Components/Menu/NavBar/NavBar.razor.cs
+++ b/src/app/dev/DevToys.Blazor/Components/Menu/NavBar/NavBar.razor.cs
@@ -104,13 +104,26 @@ public partial class NavBar<TElement, TSearchElement>
_sidebarState.IsHiddenChanged += SidebarState_IsHiddenChanged;
}
+ internal ValueTask<bool> TryFocusSearchBoxAsync()
+ {
+ if (!_sidebarState.IsCollapsed && !_sidebarState.IsHidden)
+ {
+ return _autoSuggestBox.FocusAsync();
+ }
+
+ return new ValueTask<bool>(false);
+ }
+
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (firstRender)
{
- await (await JSModule).InvokeVoidAsync("registerResizeHandler", Id, NavId, Reference);
+ using (await Semaphore.WaitAsync(CancellationToken.None))
+ {
+ await (await JSModule).InvokeVoidWithErrorHandlingAsync("registerResizeHandler", Id, NavId, Reference);
+ }
}
}
diff --git a/src/app/dev/DevToys.Blazor/Components/Menu/NavBar/NavBar.razor.scss b/src/app/dev/DevToys.Blazor/Components/Menu/NavBar/NavBar.razor.scss
index e64c3868d..ad9aac1bf 100644
--- a/src/app/dev/DevToys.Blazor/Components/Menu/NavBar/NavBar.razor.scss
+++ b/src/app/dev/DevToys.Blazor/Components/Menu/NavBar/NavBar.razor.scss
@@ -28,7 +28,7 @@ $sidebar-top-bar-height: 48px;
}
.nav-bar-button-icon {
- height: 36px;
+ height: 36px !important;
width: 40px;
font-size: 16px;
line-height: 16px;
diff --git a/src/app/dev/DevToys.Blazor/Components/Menu/NavBar/NavBarItem.razor.scss b/src/app/dev/DevToys.Blazor/Components/Menu/NavBar/NavBarItem.razor.scss
index 216668cd7..53ec907da 100644
--- a/src/app/dev/DevToys.Blazor/Components/Menu/NavBar/NavBarItem.razor.scss
+++ b/src/app/dev/DevToys.Blazor/Components/Menu/NavBar/NavBarItem.razor.scss
@@ -21,7 +21,7 @@ nav {
}
.sidebar-expand-group-button {
- height: 34px;
+ height: 34px !important;
transition-duration: 0.2s;
transition-property: transform;
diff --git a/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor.cs b/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor.cs
index 8c5e01715..714a2c93b 100644
--- a/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor.cs
+++ b/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor.cs
@@ -95,7 +95,7 @@ public partial class TextBox : MefComponentBase
{
try
{
- await (await JSModule).InvokeVoidAsync("dispose", Element);
+ await (await JSModule).InvokeVoidWithErrorHandlingAsync("dispose", Element);
}
catch
{
@@ -112,7 +112,10 @@ public partial class TextBox : MefComponentBase
if (firstRender)
{
- await (await JSModule).InvokeVoidAsync("initializeKeyboardTracking", Element);
+ using (await Semaphore.WaitAsync(CancellationToken.None))
+ {
+ await (await JSModule).InvokeVoidWithErrorHandlingAsync("initializeKeyboardTracking", Element);
+ }
}
}
@@ -124,18 +127,24 @@ public partial class TextBox : MefComponentBase
private async Task OnDecreaseClickAsync()
{
- Guard.IsNotNull(_input);
- Guard.IsNotNull(_input.Element);
- await SetTextAsync((await (await JSModule).InvokeAsync<int>("decreaseValue", _input.Element)).ToString());
- await FocusAsync();
+ using (await Semaphore.WaitAsync(CancellationToken.None))
+ {
+ Guard.IsNotNull(_input);
+ Guard.IsNotNull(_input.Element);
+ await SetTextAsync((await (await JSModule).InvokeAsync<int>("decreaseValue", _input.Element)).ToString());
+ await FocusAsync();
+ }
}
private async Task OnIncreaseClickAsync()
{
- Guard.IsNotNull(_input);
- Guard.IsNotNull(_input.Element);
- await SetTextAsync((await (await JSModule).InvokeAsync<int>("increaseValue", _input.Element)).ToString());
- await FocusAsync();
+ using (await Semaphore.WaitAsync(CancellationToken.None))
+ {
+ Guard.IsNotNull(_input);
+ Guard.IsNotNull(_input.Element);
+ await SetTextAsync((await (await JSModule).InvokeAsync<int>("increaseValue", _input.Element)).ToString());
+ await FocusAsync();
+ }
}
private Task OnContextMenuOpening()
@@ -162,34 +171,37 @@ public partial class TextBox : MefComponentBase
private async Task UpdateContextMenuAsync()
{
- Guard.IsNotNull(_input);
- Guard.IsNotNull(_input.Element);
- int selectionLength = await (await JSModule).InvokeAsync<int>("getSelectionLength", _input.Element);
+ using (await Semaphore.WaitAsync(CancellationToken.None))
+ {
+ Guard.IsNotNull(_input);
+ Guard.IsNotNull(_input.Element);
+ int selectionLength = await (await JSModule).InvokeAsync<int>("getSelectionLength", _input.Element);
- _contextMenuItems.Clear();
+ _contextMenuItems.Clear();
- if (selectionLength > 0)
- {
- if (!IsReadOnly)
+ if (selectionLength > 0)
{
- CutContextMenuItem.OnClick = EventCallback.Factory.Create(this, OnCutAsync);
- _contextMenuItems.Add(CutContextMenuItem);
+ if (!IsReadOnly)
+ {
+ CutContextMenuItem.OnClick = EventCallback.Factory.Create(this, OnCutAsync);
+ _contextMenuItems.Add(CutContextMenuItem);
+ }
+
+ CopyContextMenuItem.OnClick = EventCallback.Factory.Create(this, OnCopyAsync);
+ _contextMenuItems.Add(CopyContextMenuItem);
}
- CopyContextMenuItem.OnClick = EventCallback.Factory.Create(this, OnCopyAsync);
- _contextMenuItems.Add(CopyContextMenuItem);
- }
-
- if (!IsReadOnly)
- {
- PasteContextMenuItem.OnClick = EventCallback.Factory.Create(this, OnPasteAsync);
- _contextMenuItems.Add(PasteContextMenuItem);
- }
+ if (!IsReadOnly)
+ {
+ PasteContextMenuItem.OnClick = EventCallback.Factory.Create(this, OnPasteAsync);
+ _contextMenuItems.Add(PasteContextMenuItem);
+ }
- if (Text?.Length > 0)
- {
- SelectAllContextMenuItem.OnClick = EventCallback.Factory.Create(this, OnSelectAllAsync);
- _contextMenuItems.Add(SelectAllContextMenuItem);
+ if (Text?.Length > 0)
+ {
+ SelectAllContextMenuItem.OnClick = EventCallback.Factory.Create(this, OnSelectAllAsync);
+ _contextMenuItems.Add(SelectAllContextMenuItem);
+ }
}
}
@@ -235,15 +247,21 @@ public partial class TextBox : MefComponentBase
private async Task OnSelectAllAsync()
{
- Guard.IsNotNull(_input);
- await (await JSModule).InvokeVoidAsync("selectAll", _input.Element);
+ using (await Semaphore.WaitAsync(CancellationToken.None))
+ {
+ Guard.IsNotNull(_input);
+ await (await JSModule).InvokeVoidWithErrorHandlingAsync("selectAll", _input.Element);
+ }
}
private async Task<TextSpan> GetSelectionAsync()
{
- Guard.IsNotNull(_input);
- int[] selection = await (await JSModule).InvokeAsync<int[]>("getSelectionSpan", _input.Element);
- return new TextSpan(selection[0], selection[1] - selection[0]);
+ using (await Semaphore.WaitAsync(CancellationToken.None))
+ {
+ Guard.IsNotNull(_input);
+ int[] selection = await (await JSModule).InvokeAsync<int[]>("getSelectionSpan", _input.Element);
+ return new TextSpan(selection[0], selection[1] - selection[0]);
+ }
}
private Task SetTextAsync(string text)
diff --git a/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor.scss b/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor.scss
index 832cf36a0..a3835586f 100644
--- a/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor.scss
+++ b/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor.scss
@@ -147,6 +147,7 @@
button {
margin-inline-start: 6px;
height: 22px;
+ min-block-size: 22px;
width: 22px;
padding: 0;
diff --git a/src/app/dev/DevToys.Blazor/Core/Extensions/IJSRuntimeExtensions.cs b/src/app/dev/DevToys.Blazor/Core/Extensions/IJSRuntimeExtensions.cs
index 878705fcc..39116a989 100644
--- a/src/app/dev/DevToys.Blazor/Core/Extensions/IJSRuntimeExtensions.cs
+++ b/src/app/dev/DevToys.Blazor/Core/Extensions/IJSRuntimeExtensions.cs
@@ -2,6 +2,8 @@
internal static class IJSRuntimeExtensions
{
+ // TODO: Log JS errors.
+
/// <summary>
/// Invokes the specified JavaScript function asynchronously and catches <see cref="JSException"/>,
/// <see cref="JSDisconnectedException"/> and <see cref="TaskCanceledException"/>.
@@ -19,13 +21,52 @@ internal static class IJSRuntimeExtensions
await jsRuntime.InvokeVoidAsync(identifier, args);
return true;
}
+ catch (JSException ex)
+ {
#if DEBUG
-#else
- catch (JSException)
+ Debug.WriteLine(GetExceptionString(ex));
+#endif
+ return false;
+ }
+ // catch pre-rending errors since there is no browser at this point.
+ catch (InvalidOperationException ex) when (ex.Message.Contains("prerender", StringComparison.InvariantCultureIgnoreCase))
+ {
+ return false;
+ }
+ catch (JSDisconnectedException)
{
return false;
}
+ catch (TaskCanceledException)
+ {
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Invokes the specified JavaScript function asynchronously and catches <see cref="JSException"/>,
+ /// <see cref="JSDisconnectedException"/> and <see cref="TaskCanceledException"/>.
+ /// </summary>
+ /// <param name="jsObjectReference">The <see cref="IJSObjectReference"/>.</param>
+ /// <param name="identifier">An identifier for the function to invoke. For example, the value <c>"someScope.someFunction"</c> will
+ /// invoke the function <c>window.someScope.someFunction</c>.</param>
+ /// <param name="args">JSON-serializable arguments.</param>
+ /// <returns>A <see cref="ValueTask"/> that represents the asynchronous invocation operation and resolves to true in case
+ /// no exception has occurred otherwise false.</returns>
+ public static async ValueTask<bool> InvokeVoidWithErrorHandlingAsync(this IJSObjectReference jsObjectReference, string identifier, params object?[]? args)
+ {
+ try
+ {
+ await jsObjectReference.InvokeVoidAsync(identifier, args);
+ return true;
+ }
+ catch (JSException ex)
+ {
+#if DEBUG
+ Debug.WriteLine(GetExceptionString(ex));
#endif
+ return false;
+ }
// catch pre-rending errors since there is no browser at this point.
catch (InvalidOperationException ex) when (ex.Message.Contains("prerender", StringComparison.InvariantCultureIgnoreCase))
{
@@ -40,4 +81,31 @@ internal static class IJSRuntimeExtensions
return false;
}
}
+
+ private static string GetExceptionString(JSException ex)
+ {
+ if (ex.InnerException is null)
+ {
+ return
+@$"===========================
+JAVASCRIPT Exception caught:
+MESSAGE: {ex.Message}
+STACK TRACE:
+{ex.StackTrace}
+===========================";
+ }
+
+ return
+@$"===========================
+JAVASCRIPT Exception caught:
+MESSAGE: {ex.Message}
+STACK TRACE:
+{ex.StackTrace}
+
+== INNER EXCEPTION ==
+MESSAGE: {ex.InnerException!.Message}
+STACK TRACE:
+{ex.InnerException!.StackTrace}
+===========================";
+ }
}
diff --git a/src/app/dev/DevToys.Blazor/Core/Services/ContextMenuService.cs b/src/app/dev/DevToys.Blazor/Core/Services/ContextMenuService.cs
index fa65ba6bc..153b00821 100644
--- a/src/app/dev/DevToys.Blazor/Core/Services/ContextMenuService.cs
+++ b/src/app/dev/DevToys.Blazor/Core/Services/ContextMenuService.cs
@@ -10,7 +10,7 @@ public sealed class ContextMenuService
Guard.IsNotNull(windowService);
_windowService = windowService;
- _windowService.WindowLostFocus += WindowService_MajorWindowChange;
+ _windowService.WindowDeactivated += WindowService_MajorWindowChange;
_windowService.WindowClosing += WindowService_MajorWindowChange;
_windowService.WindowLocationChanged += WindowService_MajorWindowChange;
_windowService.WindowSizeChanged += WindowService_MajorWindowChange;
diff --git a/src/app/dev/DevToys.Blazor/Core/Services/IWindowService.cs b/src/app/dev/DevToys.Blazor/Core/Services/IWindowService.cs
index f11af2823..d1bc8610b 100644
--- a/src/app/dev/DevToys.Blazor/Core/Services/IWindowService.cs
+++ b/src/app/dev/DevToys.Blazor/Core/Services/IWindowService.cs
@@ -2,11 +2,15 @@
public interface IWindowService
{
- event EventHandler<EventArgs>? WindowLostFocus;
+ event EventHandler<EventArgs>? WindowActivated;
+
+ event EventHandler<EventArgs>? WindowDeactivated;
event EventHandler<EventArgs>? WindowLocationChanged;
event EventHandler<EventArgs>? WindowSizeChanged;
event EventHandler<EventArgs>? WindowClosing;
+
+ bool IsOverlayMode { get; set; }
}
diff --git a/src/app/dev/DevToys.Blazor/Pages/Index.razor b/src/app/dev/DevToys.Blazor/Pages/Index.razor
index e6bc158a8..39bfb7731 100644
--- a/src/app/dev/DevToys.Blazor/Pages/Index.razor
+++ b/src/app/dev/DevToys.Blazor/Pages/Index.razor
@@ -16,7 +16,8 @@
<!-- Navigation View -->
<!-- TODO: Localize -->
-<NavBar TElement="INotifyPropertyChanged"
+<NavBar @ref=_navBar
+ TElement="INotifyPropertyChanged"
TSearchElement="GuiToolViewItem"
MenuItemsSource="@ViewModel.HeaderAndBodyToolViewItems"
FooterMenuItemsSource="@ViewModel.FooterToolViewItems"
@@ -77,7 +78,19 @@
title = groupViewItem.DisplayTitle;
}
- <TextBlock NoWrap="true" Text="@title" />
+ <div style="display: flex;">
+ <TextBlock NoWrap="true"
+ Text="@title"
+ Style="flex-grow: 1 !important; flex-basis: auto !important; align-self:center;" />
+ @if (item is GuiToolViewItem guiToolViewItem2 && guiToolViewItem2.IsRecommended)
+ {
+ <img src="_content/DevToys.Blazor/img/idea.svg"
+ height="16"
+ width="16"
+ style="flex-basis: auto; align-self:center;" />
+ }
+ <img />
+ </div>
}
</NavBarItemTitleTemplate>
diff --git a/src/app/dev/DevToys.Blazor/Pages/Index.razor.cs b/src/app/dev/DevToys.Blazor/Pages/Index.razor.cs
index 9f0199f09..013dfdd69 100644
--- a/src/app/dev/DevToys.Blazor/Pages/Index.razor.cs
+++ b/src/app/dev/DevToys.Blazor/Pages/Index.razor.cs
@@ -1,4 +1,5 @@
-using DevToys.Blazor.Components;
+using DevToys.Api;
+using DevToys.Blazor.Components;
using DevToys.Blazor.Core.Services;
using DevToys.Business.ViewModels;
using DevToys.Core;
@@ -12,6 +13,8 @@ public partial class Index : MefComponentBase
private const int TitleBarMarginLeftWhenNavBarHidden = 87;
private const int TitleBarMarginLeftWhenNavBarNotHidden = 47;
+ private NavBar<INotifyPropertyChanged, GuiToolViewItem> _navBar = default!;
+
[Import]
internal MainWindowViewModel ViewModel { get; set; } = default!;
@@ -21,12 +24,14 @@ public partial class Index : MefComponentBase
[Import]
internal TitleBarMarginProvider TitleBarMarginProvider { get; set; } = default!;
+ [Import]
+ internal IThemeListener ThemeListener { get; set; } = default!;
+
[Inject]
internal ContextMenuService ContextMenuService { get; set; } = default!;
- // TODO: Temp.
- [Parameter]
- public int ComboBoxSelectedItem { get; set; } = 1;
+ [Inject]
+ internal IWindowService WindowService { get; set; } = default!;
/// <summary>
/// Indicates whether we're transitioning to another selected menu item.
@@ -39,6 +44,7 @@ public partial class Index : MefComponentBase
ViewModel.SelectedMenuItemChanged += ViewModel_SelectedMenuItemChanged;
ViewModel.SelectedMenuItem = ViewModel.HeaderAndBodyToolViewItems[0];
ContextMenuService.IsContextMenuOpenedChanged += ContextMenuService_IsContextMenuOpenedChanged;
+ WindowService.WindowActivated += WindowService_WindowActivated;
}
private void ViewModel_SelectedMenuItemChanged(object? sender, EventArgs e)
@@ -54,6 +60,12 @@ public partial class Index : MefComponentBase
StateHasChanged();
}
+ private void WindowService_WindowActivated(object? sender, EventArgs e)
+ {
+ // Start Smart Detection
+ ViewModel.RunSmartDetectionAsync(WindowService.IsOverlayMode).Forget();
+ }
+
private void OnBackButtonClicked()
{
ViewModel.GoBack();
@@ -96,11 +108,11 @@ public partial class Index : MefComponentBase
{
if (firstRender)
{
- // TODO: Focus on the Search Box.
+ // Focus on the Search Box.
+ _navBar.TryFocusSearchBoxAsync();
- // TODO:
// Start Smart Detection
- // ViewModel.RunSmartDetectionAsync(IsInCompactOverlay).Forget();
+ ViewModel.RunSmartDetectionAsync(WindowService.IsOverlayMode).Forget();
}
if (IsTransitioning)
diff --git a/src/app/dev/DevToys.Blazor/wwwroot/img/idea-disabled.svg b/src/app/dev/DevToys.Blazor/wwwroot/img/idea-disabled.svg
new file mode 100644
index 000000000..2d63a957e
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/wwwroot/img/idea-disabled.svg
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ viewBox="0 0 48 48"
+ version="1.1"
+ id="svg36"
+ sodipodi:docname="Idea-disabled.svg"
+ inkscape:version="1.2 (dc2aedaf03, 2022-05-15)"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:svg="http://www.w3.org/2000/svg">
+ <defs
+ id="defs40" />
+ <sodipodi:namedview
+ id="namedview38"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:showpageshadow="2"
+ inkscape:pageopacity="0.0"
+ inkscape:pagecheckerboard="0"
+ inkscape:deskcolor="#d1d1d1"
+ showgrid="false"
+ inkscape:zoom="17.270833"
+ inkscape:cx="24.028951"
+ inkscape:cy="24.028951"
+ inkscape:window-width="1920"
+ inkscape:window-height="1009"
+ inkscape:window-x="-8"
+ inkscape:window-y="-8"
+ inkscape:window-maximized="1"
+ inkscape:current-layer="svg36" />
+ <radialGradient
+ id="4Var25g6pDrxGe_QIeTVza"
+ cx="16.106"
+ cy="-171.073"
+ r="23.43"
+ gradientTransform="matrix(1 0 0 -1 0 118)"
+ gradientUnits="userSpaceOnUse">
+ <stop
+ offset="0"
+ stop-color="#6e757b"
+ id="stop22" />
+ <stop
+ offset="1"
+ stop-color="#4a4e52"
+ id="stop24" />
+ </radialGradient>
+ <path
+ fill="url(#4Var25g6pDrxGe_QIeTVza)"
+ d="M30,34H18c0,0.855,0,3.95,0,3.95c0,3.314,2.686,6,6,6s6-2.686,6-6C30,37.95,30,34.855,30,34z"
+ id="path27" />
+ <linearGradient
+ id="4Var25g6pDrxGe_QIeTVzb"
+ x1="16.365"
+ x2="28.493"
+ y1="2.837"
+ y2="26.454"
+ gradientUnits="userSpaceOnUse">
+ <stop
+ offset="0"
+ stop-color="#ffda1c"
+ id="stop29" />
+ <stop
+ offset="1"
+ stop-color="#feb705"
+ id="stop31" />
+ </linearGradient>
+ <path
+ fill="url(#4Var25g6pDrxGe_QIeTVzb)"
+ d="M36,16c0-6.627-5.373-12-12-12S12,9.373,12,16c0,7,6,12,6,15.8V34h12v-2.2C30,28,36,23,36,16z"
+ id="path34"
+ style="fill:#b3b3b3" />
+</svg>
diff --git a/src/app/dev/DevToys.Blazor/wwwroot/img/idea.svg b/src/app/dev/DevToys.Blazor/wwwroot/img/idea.svg
new file mode 100644
index 000000000..4ab8b7011
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/wwwroot/img/idea.svg
@@ -0,0 +1,12 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48">
+ <radialGradient id="4Var25g6pDrxGe_QIeTVza" cx="16.106" cy="-171.073" r="23.43" gradientTransform="matrix(1 0 0 -1 0 118)" gradientUnits="userSpaceOnUse">
+ <stop offset="0" stop-color="#6e757b"></stop>
+ <stop offset="1" stop-color="#4a4e52"></stop>
+ </radialGradient>
+ <path fill="url(#4Var25g6pDrxGe_QIeTVza)" d="M30,34H18c0,0.855,0,3.95,0,3.95c0,3.314,2.686,6,6,6s6-2.686,6-6C30,37.95,30,34.855,30,34z"></path>
+ <linearGradient id="4Var25g6pDrxGe_QIeTVzb" x1="16.365" x2="28.493" y1="2.837" y2="26.454" gradientUnits="userSpaceOnUse">
+ <stop offset="0" stop-color="#ffda1c"></stop>
+ <stop offset="1" stop-color="#feb705"></stop>
+ </linearGradient>
+ <path fill="url(#4Var25g6pDrxGe_QIeTVzb)" d="M36,16c0-6.627-5.373-12-12-12S12,9.373,12,16c0,7,6,12,6,15.8V34h12v-2.2C30,28,36,23,36,16z"></path>
+</svg>
\ No newline at end of file
diff --git a/src/app/dev/platforms/desktop/DevToys.MacOS/Core/WindowService.cs b/src/app/dev/platforms/desktop/DevToys.MacOS/Core/WindowService.cs
index b71efd9f3..28cade060 100644
--- a/src/app/dev/platforms/desktop/DevToys.MacOS/Core/WindowService.cs
+++ b/src/app/dev/platforms/desktop/DevToys.MacOS/Core/WindowService.cs
@@ -5,22 +5,29 @@ namespace DevToys.MacOS.Core;
internal sealed class WindowService : IWindowService
{
- public event EventHandler<EventArgs>? WindowLostFocus;
+ public event EventHandler<EventArgs>? WindowActivated;
+ public event EventHandler<EventArgs>? WindowDeactivated;
public event EventHandler<EventArgs>? WindowLocationChanged;
public event EventHandler<EventArgs>? WindowSizeChanged;
public event EventHandler<EventArgs>? WindowClosing;
public WindowService()
{
- NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSWindowDidResignMainNotification"), OnWindowLostFocus);
+ NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSWindowDidBecomeMainNotification"), OnWindowActivated);
+ NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSWindowDidResignMainNotification"), OnWindowDeactivated);
NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSWindowWillMoveNotification"), OnWindowLocationChanged);
NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSWindowWillStartLiveResizeNotification"), OnWindowSizeChanged);
NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSWindowWillCloseNotification"), OnWindowClosing);
}
- public void OnWindowLostFocus(NSNotification notification)
+ public void OnWindowActivated(NSNotification notification)
{
- WindowLostFocus?.Invoke(this, EventArgs.Empty);
+ WindowActivated?.Invoke(this, EventArgs.Empty);
+ }
+
+ public void OnWindowDeactivated(NSNotification notification)
+ {
+ WindowDeactivated?.Invoke(this, EventArgs.Empty);
}
public void OnWindowLocationChanged(NSNotification notification)
diff --git a/src/app/dev/platforms/desktop/DevToys.Windows/Core/WindowService.cs b/src/app/dev/platforms/desktop/DevToys.Windows/Core/WindowService.cs
index 39a4cd9c6..acdb3ee03 100644
--- a/src/app/dev/platforms/desktop/DevToys.Windows/Core/WindowService.cs
+++ b/src/app/dev/platforms/desktop/DevToys.Windows/Core/WindowService.cs
@@ -7,26 +7,35 @@ internal sealed class WindowService : IWindowService
{
private Window? _window;
- public event EventHandler<EventArgs>? WindowLostFocus;
+ public event EventHandler<EventArgs>? WindowActivated;
+ public event EventHandler<EventArgs>? WindowDeactivated;
public event EventHandler<EventArgs>? WindowLocationChanged;
public event EventHandler<EventArgs>? WindowSizeChanged;
public event EventHandler<EventArgs>? WindowClosing;
+ public bool IsOverlayMode { get; set; }
+
internal void SetWindow(Window window)
{
Guard.IsNull(_window);
Guard.IsNotNull(window);
_window = window;
- _window.LostFocus += Window_LostFocus;
+ _window.Activated += Window_Activated;
+ _window.Deactivated += Window_Deactivated;
_window.LocationChanged += Window_LocationChanged;
_window.SizeChanged += Window_SizeChanged;
_window.Closing += Window_Closing;
}
- private void Window_LostFocus(object sender, RoutedEventArgs e)
+ private void Window_Activated(object? sender, EventArgs e)
+ {
+ WindowActivated?.Invoke(this, EventArgs.Empty);
+ }
+
+ private void Window_Deactivated(object? sender, EventArgs e)
{
- WindowLostFocus?.Invoke(this, EventArgs.Empty);
+ WindowDeactivated?.Invoke(this, EventArgs.Empty);
}
private void Window_LocationChanged(object? sender, EventArgs e)
diff --git a/src/app/dev/platforms/desktop/DevToys.Windows/MainWindow.xaml.cs b/src/app/dev/platforms/desktop/DevToys.Windows/MainWindow.xaml.cs
index 0037cdfd5..73e74d193 100644
--- a/src/app/dev/platforms/desktop/DevToys.Windows/MainWindow.xaml.cs
+++ b/src/app/dev/platforms/desktop/DevToys.Windows/MainWindow.xaml.cs
@@ -1,5 +1,4 @@
-using System;
-using DevToys.Api;
+using DevToys.Api;
using DevToys.Blazor.Core.Languages;
using DevToys.Blazor.Core.Services;
using DevToys.Business.ViewModels;
@@ -9,6 +8,7 @@ using DevToys.Core.Mef;
using DevToys.Windows.Controls;
using DevToys.Windows.Core;
using Microsoft.AspNetCore.Components.WebView;
+using Microsoft.AspNetCore.Components.WebView.Wpf;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PredefinedSettings = DevToys.Core.Settings.PredefinedSettings;
@@ -93,7 +93,18 @@ public partial class MainWindow : MicaWindowWithOverlay
private void BlazorWebView_BlazorWebViewInitialized(object? sender, BlazorWebViewInitializedEventArgs e)
{
+ if (!Debugger.IsAttached)
+ {
+ blazorWebView.WebView.CoreWebView2.Settings.AreBrowserAcceleratorKeysEnabled = false;
+ }
+ blazorWebView.WebView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
+ blazorWebView.WebView.CoreWebView2.Settings.IsGeneralAutofillEnabled = false;
+ blazorWebView.WebView.CoreWebView2.Settings.IsPinchZoomEnabled = false;
+ blazorWebView.WebView.CoreWebView2.Settings.IsZoomControlEnabled = false;
+ blazorWebView.WebView.CoreWebView2.Settings.IsSwipeNavigationEnabled = false;
blazorWebView.WebView.CoreWebView2.Settings.IsStatusBarEnabled = false;
+ blazorWebView.Focus();
+ blazorWebView.WebView.Focus();
LogUiLoadTime((DateTime.Now - _uiLoadingTime).TotalMilliseconds);
}