FabriBertani / Plugin.Maui.ScreenSecurity

Safeguard your .NET MAUI app effortlessly by preventing content exposure, screenshots, and recordings with ease.
MIT License
160 stars 12 forks source link

.Net MAUI Blazor #5

Closed steindin closed 1 year ago

steindin commented 1 year ago

Hi! I have tried implementing this plugin in my .net MAUI Blazor App, but it doesnt seem to work! Is this plugin enabled for Blazor, or not?

FabriBertani commented 1 year ago

Hi @steindin

I don't know what or how you're trying, but this plugin does work with Blazor.

Considering that Blazor is embedded within the Maui app via BlazorWebView and the lifecycle relies on Maui, you can use this plugin as described in the docs or sample within the Maui app context (page code behind or ViewModel).

Remember to register the plugin on the MauiProgram.cs:

builder.Services.AddSingleton<IScreenSecurity>(ScreenSecurity.Default);

Or use the default instance directly:

ScreenSecurity.Default.EnableScreenSecurityProtection();

Also, you can execute the methods on Blazor:

@page "/"

@using Plugin.Maui.ScreenSecurity;
@inject IScreenSecurity ScreenSecurity

<h1>Hello, world!</h1>

Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />

<button class="btn btn-primary" @onclick="EnableScreenSecurity">Enable Screen Security</button>

<button class="btn btn-secondary" @onclick="DisableScreenSecurity">Disable Screen Security</button>

@code
{
    void EnableScreenSecurity()
    {
#if ANDROID
        ScreenSecurity.EnableScreenSecurityProtection();
#elif IOS
        ScreenSecurity.EnableBlurScreenProtection(Plugin.Maui.ScreenSecurity.Platforms.iOS.ThemeStyle.Light);
#endif
    }

    void DisableScreenSecurity()
    {
#if ANDROID
        ScreenSecurity.DisableScreenSecurityProtection();
#elif IOS
        ScreenSecurity.DisableBlurScreenProtection();
#endif
    }
}

Hope this clarifies your question.

FabriBertani commented 1 year ago

Closed due to not being an issue/bug.