mirror of
https://github.com/bitwarden/android.git
synced 2024-12-27 11:28:28 +03:00
PM-3350 MAUI Migration Fix iOS Autofill extension
This commit is contained in:
parent
87eebda55f
commit
90649d1c8b
8 changed files with 77 additions and 88 deletions
|
@ -10,9 +10,7 @@ namespace Bit.App
|
||||||
#if ANDROID
|
#if ANDROID
|
||||||
effects.Add<Effects.FabShadowEffect, Effects.FabShadowPlatformEffect>();
|
effects.Add<Effects.FabShadowEffect, Effects.FabShadowPlatformEffect>();
|
||||||
#else
|
#else
|
||||||
effects.Add<Effects.NoEmojiKeyboardEffect, Bit.iOS.Core.Effects.NoEmojiKeyboardEffect>();
|
iOS.Core.Utilities.iOSCoreHelpers.ConfigureMAUIEffects(effects);
|
||||||
effects.Add<Effects.ScrollEnabledEffect, Effects.ScrollEnabledPlatformEffect>();
|
|
||||||
effects.Add<Effects.ScrollViewContentInsetAdjustmentBehaviorEffect, Bit.App.Effects.ScrollViewContentInsetAdjustmentBehaviorPlatformEffect>();
|
|
||||||
#endif
|
#endif
|
||||||
},
|
},
|
||||||
handlers =>
|
handlers =>
|
||||||
|
@ -32,15 +30,7 @@ namespace Bit.App
|
||||||
|
|
||||||
handlers.AddHandler(typeof(TabbedPage), typeof(Bit.App.Handlers.CustomTabbedPageHandler));
|
handlers.AddHandler(typeof(TabbedPage), typeof(Bit.App.Handlers.CustomTabbedPageHandler));
|
||||||
#else
|
#else
|
||||||
iOS.Core.Handlers.ButtonHandlerMappings.Setup();
|
iOS.Core.Utilities.iOSCoreHelpers.ConfigureMAUIHandlers(handlers);
|
||||||
iOS.Core.Handlers.DatePickerHandlerMappings.Setup();
|
|
||||||
iOS.Core.Handlers.EditorHandlerMappings.Setup();
|
|
||||||
iOS.Core.Handlers.EntryHandlerMappings.Setup();
|
|
||||||
//iOS.Core.Handlers.LabelHandlerMappings.Setup();
|
|
||||||
iOS.Core.Handlers.PickerHandlerMappings.Setup();
|
|
||||||
iOS.Core.Handlers.SearchBarHandlerMappings.Setup();
|
|
||||||
iOS.Core.Handlers.StepperHandlerMappings.Setup();
|
|
||||||
iOS.Core.Handlers.TimePickerHandlerMappings.Setup();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
).Build();
|
).Build();
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
BackgroundColor="#22000000"
|
BackgroundColor="#22000000"
|
||||||
Padding="0"
|
Padding="0"
|
||||||
IsVisible="False">
|
IsVisible="False">
|
||||||
<StackLayout
|
<VerticalStackLayout
|
||||||
x:Name="_accountListContainer"
|
x:Name="_accountListContainer"
|
||||||
VerticalOptions="Fill"
|
VerticalOptions="Fill"
|
||||||
HorizontalOptions="FillAndExpand"
|
HorizontalOptions="FillAndExpand"
|
||||||
|
@ -58,5 +58,5 @@
|
||||||
<TapGestureRecognizer Tapped="FreeSpaceOverlay_Tapped" />
|
<TapGestureRecognizer Tapped="FreeSpaceOverlay_Tapped" />
|
||||||
</BoxView.GestureRecognizers>
|
</BoxView.GestureRecognizers>
|
||||||
</BoxView>
|
</BoxView>
|
||||||
</StackLayout>
|
</VerticalStackLayout>
|
||||||
</ContentView>
|
</ContentView>
|
||||||
|
|
|
@ -11,10 +11,14 @@ namespace Bit.Core;
|
||||||
public static class MauiProgram
|
public static class MauiProgram
|
||||||
{
|
{
|
||||||
public static MauiAppBuilder ConfigureMauiAppBuilder(Action<IEffectsBuilder> customEffectsBuilder, Action<IMauiHandlersCollection> customHandlers)
|
public static MauiAppBuilder ConfigureMauiAppBuilder(Action<IEffectsBuilder> customEffectsBuilder, Action<IMauiHandlersCollection> customHandlers)
|
||||||
|
{
|
||||||
|
return ConfigureBaseMauiAppBuilder(customEffectsBuilder, customHandlers)
|
||||||
|
.UseMauiApp<Bit.App.App>();
|
||||||
|
}
|
||||||
|
public static MauiAppBuilder ConfigureBaseMauiAppBuilder(Action<IEffectsBuilder> customEffectsBuilder, Action<IMauiHandlersCollection> customHandlers)
|
||||||
{
|
{
|
||||||
var builder = MauiApp.CreateBuilder();
|
var builder = MauiApp.CreateBuilder();
|
||||||
builder
|
builder
|
||||||
.UseMauiApp<Bit.App.App>()
|
|
||||||
.UseMauiCommunityToolkit()
|
.UseMauiCommunityToolkit()
|
||||||
.UseMauiCompatibility()
|
.UseMauiCompatibility()
|
||||||
.UseBarcodeReader()
|
.UseBarcodeReader()
|
||||||
|
|
|
@ -1,23 +1,8 @@
|
||||||
using System;
|
using Foundation;
|
||||||
using Foundation;
|
|
||||||
using Microsoft.Maui;
|
|
||||||
using Microsoft.Maui.Embedding;
|
|
||||||
using Microsoft.Maui.Hosting;
|
|
||||||
using UIKit;
|
using UIKit;
|
||||||
|
|
||||||
namespace Bit.iOS.Autofill
|
namespace Bit.iOS.Autofill
|
||||||
{
|
{
|
||||||
public class MauiContextSingleton
|
|
||||||
{
|
|
||||||
private static Lazy<MauiContextSingleton> _instance = new Lazy<MauiContextSingleton>(() => new MauiContextSingleton());
|
|
||||||
|
|
||||||
private MauiContextSingleton() { }
|
|
||||||
|
|
||||||
public static MauiContextSingleton Instance = _instance.Value;
|
|
||||||
|
|
||||||
public MauiContext MauiContext { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Register("AppDelegate")]
|
[Register("AppDelegate")]
|
||||||
public partial class AppDelegate : UIApplicationDelegate
|
public partial class AppDelegate : UIApplicationDelegate
|
||||||
{
|
{
|
||||||
|
@ -41,17 +26,5 @@ namespace Bit.iOS.Autofill
|
||||||
public override void WillTerminate(UIApplication application)
|
public override void WillTerminate(UIApplication application)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
|
|
||||||
{
|
|
||||||
var builder = MauiApp.CreateBuilder();
|
|
||||||
builder.UseMauiEmbedding<Microsoft.Maui.Controls.Application>();
|
|
||||||
// Register the Window
|
|
||||||
builder.Services.Add(new Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(UIWindow), Window));
|
|
||||||
var mauiApp = builder.Build();
|
|
||||||
MauiContextSingleton.Instance.MauiContext = new MauiContext(mauiApp.Services);
|
|
||||||
|
|
||||||
return base.FinishedLaunching(application, launchOptions);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ using CoreFoundation;
|
||||||
using CoreNFC;
|
using CoreNFC;
|
||||||
using Foundation;
|
using Foundation;
|
||||||
using Microsoft.Maui.Controls;
|
using Microsoft.Maui.Controls;
|
||||||
using Microsoft.Maui.Controls.Compatibility;
|
|
||||||
using Microsoft.Maui.Platform;
|
using Microsoft.Maui.Platform;
|
||||||
using UIKit;
|
using UIKit;
|
||||||
|
|
||||||
|
@ -64,8 +63,6 @@ namespace Bit.iOS.Autofill
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine("[Bitwarden] PrepareCredentialList");
|
|
||||||
|
|
||||||
InitAppIfNeeded();
|
InitAppIfNeeded();
|
||||||
_context.ServiceIdentifiers = serviceIdentifiers;
|
_context.ServiceIdentifiers = serviceIdentifiers;
|
||||||
if (serviceIdentifiers.Length > 0)
|
if (serviceIdentifiers.Length > 0)
|
||||||
|
@ -354,7 +351,7 @@ namespace Bit.iOS.Autofill
|
||||||
{
|
{
|
||||||
if (await IsLocked() || await _stateService.Value.GetPasswordRepromptAutofillAsync())
|
if (await IsLocked() || await _stateService.Value.GetPasswordRepromptAutofillAsync())
|
||||||
{
|
{
|
||||||
DispatchQueue.MainQueue.DispatchAsync(() => PerformSegue("lockPasswordSegue", this));
|
DispatchQueue.MainQueue.DispatchAsync(() => PerformSegue("lockPasswordSegue", this));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -397,28 +394,8 @@ namespace Bit.iOS.Autofill
|
||||||
|
|
||||||
private void InitApp()
|
private void InitApp()
|
||||||
{
|
{
|
||||||
if (ServiceContainer.RegisteredServices.Count > 0)
|
iOSCoreHelpers.InitApp(this, Bit.Core.Constants.iOSAutoFillClearCiphersCacheKey,
|
||||||
{
|
_nfcSession, out _nfcDelegate, out _accountsManager);
|
||||||
ServiceContainer.Reset();
|
|
||||||
}
|
|
||||||
iOSCoreHelpers.RegisterLocalServices();
|
|
||||||
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
|
||||||
var messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
|
||||||
ServiceContainer.Init(deviceActionService.DeviceUserAgent,
|
|
||||||
Bit.Core.Constants.iOSAutoFillClearCiphersCacheKey, Bit.Core.Constants.iOSAllClearCipherCacheKeys);
|
|
||||||
iOSCoreHelpers.InitLogger();
|
|
||||||
iOSCoreHelpers.RegisterFinallyBeforeBootstrap();
|
|
||||||
iOSCoreHelpers.Bootstrap();
|
|
||||||
var appOptions = new AppOptions { IosExtension = true };
|
|
||||||
var app = new App.App(appOptions);
|
|
||||||
ThemeManager.SetTheme(app.Resources);
|
|
||||||
iOSCoreHelpers.AppearanceAdjustments();
|
|
||||||
_nfcDelegate = new Core.NFCReaderDelegate((success, message) =>
|
|
||||||
messagingService.Send("gotYubiKeyOTP", message));
|
|
||||||
iOSCoreHelpers.SubscribeBroadcastReceiver(this, _nfcSession, _nfcDelegate);
|
|
||||||
|
|
||||||
_accountsManager = ServiceContainer.Resolve<IAccountsManager>("accountsManager");
|
|
||||||
_accountsManager.Init(() => appOptions, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitAppIfNeeded()
|
private void InitAppIfNeeded()
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
using System;
|
using Bit.App.Controls;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Bit.App.Controls;
|
|
||||||
using Bit.Core.Abstractions;
|
using Bit.Core.Abstractions;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
|
using Microsoft.Maui.Platform;
|
||||||
using UIKit;
|
using UIKit;
|
||||||
|
|
||||||
namespace Bit.iOS.Core.Utilities
|
namespace Bit.iOS.Core.Utilities
|
||||||
|
@ -72,17 +71,18 @@ namespace Bit.iOS.Core.Utilities
|
||||||
//renderer.SetElementSize(new Size(containerView.Frame.Size.Width, containerView.Frame.Size.Height));
|
//renderer.SetElementSize(new Size(containerView.Frame.Size.Width, containerView.Frame.Size.Height));
|
||||||
|
|
||||||
//var view = renderer.NativeView;
|
//var view = renderer.NativeView;
|
||||||
//view.TranslatesAutoresizingMaskIntoConstraints = false;
|
var view = overlay.ToPlatform(MauiContextSingleton.Instance.MauiContext);
|
||||||
|
view.TranslatesAutoresizingMaskIntoConstraints = false;
|
||||||
|
|
||||||
//containerView.AddSubview(view);
|
containerView.AddSubview(view);
|
||||||
//containerView.AddConstraints(new NSLayoutConstraint[]
|
containerView.AddConstraints(new NSLayoutConstraint[]
|
||||||
//{
|
{
|
||||||
// NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, view, NSLayoutAttribute.Trailing, 1f, 0f),
|
NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, view, NSLayoutAttribute.Trailing, 1f, 0f),
|
||||||
// NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, view, NSLayoutAttribute.Leading, 1f, 0f),
|
NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, view, NSLayoutAttribute.Leading, 1f, 0f),
|
||||||
// NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, view, NSLayoutAttribute.Top, 1f, 0f),
|
NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, view, NSLayoutAttribute.Top, 1f, 0f),
|
||||||
// NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, view, NSLayoutAttribute.Bottom, 1f, 0f)
|
NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, view, NSLayoutAttribute.Bottom, 1f, 0f)
|
||||||
//});
|
});
|
||||||
//containerView.Hidden = true;
|
containerView.Hidden = true;
|
||||||
|
|
||||||
return overlay;
|
return overlay;
|
||||||
}
|
}
|
||||||
|
|
15
src/iOS.Core/Utilities/MauiContextSingleton.cs
Normal file
15
src/iOS.Core/Utilities/MauiContextSingleton.cs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
namespace Bit.iOS.Core.Utilities
|
||||||
|
{
|
||||||
|
public class MauiContextSingleton
|
||||||
|
{
|
||||||
|
private static readonly Lazy<MauiContextSingleton> _instance = new Lazy<MauiContextSingleton>(() => new MauiContextSingleton());
|
||||||
|
|
||||||
|
public static MauiContextSingleton Instance => _instance.Value;
|
||||||
|
|
||||||
|
private MauiContextSingleton() { }
|
||||||
|
|
||||||
|
public MauiContext? MauiContext { get; private set; }
|
||||||
|
|
||||||
|
public void Init(MauiContext mauiContext) => MauiContext = mauiContext;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,21 +1,18 @@
|
||||||
using System;
|
using Bit.App.Abstractions;
|
||||||
using System.IO;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Bit.App.Abstractions;
|
|
||||||
using Bit.App.Controls;
|
using Bit.App.Controls;
|
||||||
using Bit.App.Models;
|
using Bit.App.Models;
|
||||||
using Bit.App.Pages;
|
using Bit.App.Pages;
|
||||||
using Bit.Core.Resources.Localization;
|
|
||||||
using Bit.App.Services;
|
using Bit.App.Services;
|
||||||
using Bit.App.Utilities;
|
using Bit.App.Utilities;
|
||||||
using Bit.App.Utilities.AccountManagement;
|
using Bit.App.Utilities.AccountManagement;
|
||||||
using Bit.Core.Abstractions;
|
using Bit.Core.Abstractions;
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Resources.Localization;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
using Bit.iOS.Core.Services;
|
using Bit.iOS.Core.Services;
|
||||||
using CoreNFC;
|
using CoreNFC;
|
||||||
using Foundation;
|
using Foundation;
|
||||||
|
using Microsoft.Maui.Embedding;
|
||||||
using UIKit;
|
using UIKit;
|
||||||
|
|
||||||
namespace Bit.iOS.Core.Utilities
|
namespace Bit.iOS.Core.Utilities
|
||||||
|
@ -28,6 +25,37 @@ namespace Bit.iOS.Core.Utilities
|
||||||
public static string AppGroupId = "group.com.8bit.bitwarden";
|
public static string AppGroupId = "group.com.8bit.bitwarden";
|
||||||
public static string AccessGroup = "LTZ2PFU5D6.com.8bit.bitwarden";
|
public static string AccessGroup = "LTZ2PFU5D6.com.8bit.bitwarden";
|
||||||
|
|
||||||
|
public static void SetupMaui()
|
||||||
|
{
|
||||||
|
var builder = Bit.Core.MauiProgram.ConfigureBaseMauiAppBuilder(ConfigureMAUIEffects, ConfigureMAUIHandlers)
|
||||||
|
.UseMauiEmbedding<Application>();
|
||||||
|
// Register the Window
|
||||||
|
builder.Services.Add(new ServiceDescriptor(typeof(UIWindow), UIApplication.SharedApplication.KeyWindow));
|
||||||
|
var mauiApp = builder.Build();
|
||||||
|
|
||||||
|
MauiContextSingleton.Instance.Init(new MauiContext(mauiApp.Services));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ConfigureMAUIEffects(IEffectsBuilder effects)
|
||||||
|
{
|
||||||
|
effects.Add<App.Effects.NoEmojiKeyboardEffect, Bit.iOS.Core.Effects.NoEmojiKeyboardEffect>();
|
||||||
|
effects.Add<App.Effects.ScrollEnabledEffect, App.Effects.ScrollEnabledPlatformEffect>();
|
||||||
|
effects.Add<App.Effects.ScrollViewContentInsetAdjustmentBehaviorEffect, Bit.App.Effects.ScrollViewContentInsetAdjustmentBehaviorPlatformEffect>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ConfigureMAUIHandlers(IMauiHandlersCollection handlers)
|
||||||
|
{
|
||||||
|
Handlers.ButtonHandlerMappings.Setup();
|
||||||
|
Handlers.DatePickerHandlerMappings.Setup();
|
||||||
|
Handlers.EditorHandlerMappings.Setup();
|
||||||
|
Handlers.EntryHandlerMappings.Setup();
|
||||||
|
//Handlers.LabelHandlerMappings.Setup();
|
||||||
|
Handlers.PickerHandlerMappings.Setup();
|
||||||
|
Handlers.SearchBarHandlerMappings.Setup();
|
||||||
|
Handlers.StepperHandlerMappings.Setup();
|
||||||
|
Handlers.TimePickerHandlerMappings.Setup();
|
||||||
|
}
|
||||||
|
|
||||||
public static void InitApp<T>(T rootController,
|
public static void InitApp<T>(T rootController,
|
||||||
string clearCipherCacheKey,
|
string clearCipherCacheKey,
|
||||||
NFCNdefReaderSession nfcSession,
|
NFCNdefReaderSession nfcSession,
|
||||||
|
@ -35,6 +63,8 @@ namespace Bit.iOS.Core.Utilities
|
||||||
out IAccountsManager accountsManager)
|
out IAccountsManager accountsManager)
|
||||||
where T : UIViewController, IAccountsManagerHost
|
where T : UIViewController, IAccountsManagerHost
|
||||||
{
|
{
|
||||||
|
SetupMaui();
|
||||||
|
|
||||||
if (ServiceContainer.RegisteredServices.Count > 0)
|
if (ServiceContainer.RegisteredServices.Count > 0)
|
||||||
{
|
{
|
||||||
ServiceContainer.Reset();
|
ServiceContainer.Reset();
|
||||||
|
|
Loading…
Reference in a new issue