-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Blazor] Support conditionally enabling developer tools
* Disables developer tools by default. * Adds a new method to enable developer tools * Adds platform specific service registration methods on the service container * Updates the Blazor template to enable developer tools only in Debug
- Loading branch information
Showing
21 changed files
with
208 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
src/BlazorWebView/src/Maui/BlazorWebViewRegistrationExtensions.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.Components.WebView.Maui | ||
{ | ||
internal class MauiBlazorMarkerService | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/BlazorWebView/src/SharedSource/BlazorWebViewDeveloperTools.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
|
||
#if WEBVIEW2_WINFORMS | ||
namespace Microsoft.AspNetCore.Components.WebView.WindowsForms | ||
#elif WEBVIEW2_WPF | ||
namespace Microsoft.AspNetCore.Components.WebView.Wpf | ||
#elif WEBVIEW2_MAUI | ||
namespace Microsoft.AspNetCore.Components.WebView.Maui | ||
#else | ||
#error Must define WEBVIEW2_WINFORMS, WEBVIEW2_WPF, WEBVIEW2_MAUI | ||
#endif | ||
{ | ||
internal class BlazorWebViewDeveloperTools | ||
{ | ||
public bool Enabled { get; set; } = false; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/BlazorWebView/src/SharedSource/BlazorWebViewServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
#if WEBVIEW2_WINFORMS | ||
using Microsoft.AspNetCore.Components.WebView.WindowsForms; | ||
#elif WEBVIEW2_WPF | ||
using Microsoft.AspNetCore.Components.WebView.Wpf; | ||
#elif WEBVIEW2_MAUI | ||
using Microsoft.AspNetCore.Components.WebView.Maui; | ||
using Microsoft.Maui.Hosting; | ||
#else | ||
#error Must define WEBVIEW2_WINFORMS, WEBVIEW2_WPF, WEBVIEW2_MAUI | ||
#endif | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
/// <summary> | ||
/// Extension methods to <see cref="IServiceCollection"/>. | ||
/// </summary> | ||
public static class BlazorWebViewServiceCollectionExtensions | ||
{ | ||
/// <summary> | ||
/// Configures <see cref="IServiceCollection"/> to add support for <see cref="BlazorWebView"/>. | ||
/// </summary> | ||
/// <param name="services">The <see cref="IServiceCollection"/>.</param> | ||
/// <returns>The <see cref="IServiceCollection"/>.</returns> | ||
#if WEBVIEW2_WINFORMS | ||
public static IServiceCollection AddWindowsFormsBlazorWebView(this IServiceCollection services) | ||
#elif WEBVIEW2_WPF | ||
public static IServiceCollection AddWpfBlazorWebView(this IServiceCollection services) | ||
#elif WEBVIEW2_MAUI | ||
public static IServiceCollection AddMauiBlazorWebView(this IServiceCollection services) | ||
#else | ||
#error Must define WEBVIEW2_WINFORMS, WEBVIEW2_WPF, WEBVIEW2_MAUI | ||
#endif | ||
{ | ||
services.AddBlazorWebView(); | ||
services.TryAddSingleton(new BlazorWebViewDeveloperTools { Enabled = false }); | ||
#if WEBVIEW2_MAUI | ||
services.TryAddSingleton<MauiBlazorMarkerService>(); | ||
services.ConfigureMauiHandlers(static handlers => handlers.AddHandler<IBlazorWebView, BlazorWebViewHandler>()); | ||
#elif WEBVIEW2_WINFORMS | ||
services.TryAddSingleton<WindowsFormsBlazorMarkerService>(); | ||
#elif WEBVIEW2_WPF | ||
services.TryAddSingleton<WpfBlazorMarkerService>(); | ||
#endif | ||
return services; | ||
} | ||
|
||
/// <summary> | ||
/// Enables Developer tools on the underlying WebView controls. | ||
/// </summary> | ||
/// <param name="services">The <see cref="IServiceCollection"/>.</param> | ||
/// <returns>The <see cref="IServiceCollection"/>.</returns> | ||
public static IServiceCollection AddBlazorWebViewDeveloperTools(this IServiceCollection services) | ||
{ | ||
return services.AddSingleton<BlazorWebViewDeveloperTools>(new BlazorWebViewDeveloperTools { Enabled = true }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/BlazorWebView/src/WindowsForms/WindowsFormsBlazorMarkerService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.Components.WebView.WindowsForms | ||
{ | ||
internal class WindowsFormsBlazorMarkerService | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.Components.WebView.Wpf | ||
{ | ||
internal class WpfBlazorMarkerService | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.