2019-03-28 03:12:44 +03:00
|
|
|
|
using System;
|
2019-06-12 06:04:41 +03:00
|
|
|
|
using System.Collections.Generic;
|
2019-07-01 23:56:42 +03:00
|
|
|
|
using System.Threading.Tasks;
|
2019-06-27 23:22:58 +03:00
|
|
|
|
using AuthenticationServices;
|
2019-06-11 22:20:28 +03:00
|
|
|
|
using Bit.App.Abstractions;
|
2019-07-02 20:15:00 +03:00
|
|
|
|
using Bit.App.Pages;
|
2019-06-12 06:04:41 +03:00
|
|
|
|
using Bit.App.Resources;
|
2019-06-11 22:20:28 +03:00
|
|
|
|
using Bit.App.Services;
|
2019-06-24 19:23:00 +03:00
|
|
|
|
using Bit.App.Utilities;
|
2019-07-01 23:56:42 +03:00
|
|
|
|
using Bit.Core;
|
2019-06-11 22:20:28 +03:00
|
|
|
|
using Bit.Core.Abstractions;
|
|
|
|
|
using Bit.Core.Services;
|
|
|
|
|
using Bit.Core.Utilities;
|
2019-06-12 06:04:41 +03:00
|
|
|
|
using Bit.iOS.Core.Utilities;
|
2019-06-11 22:20:28 +03:00
|
|
|
|
using Bit.iOS.Services;
|
2019-06-12 05:20:59 +03:00
|
|
|
|
using CoreNFC;
|
2019-03-28 03:12:44 +03:00
|
|
|
|
using Foundation;
|
|
|
|
|
using UIKit;
|
2019-06-26 16:35:18 +03:00
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using Xamarin.Forms.Platform.iOS;
|
2019-03-28 03:12:44 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.iOS
|
|
|
|
|
{
|
|
|
|
|
[Register("AppDelegate")]
|
2019-06-28 15:21:44 +03:00
|
|
|
|
public partial class AppDelegate : FormsApplicationDelegate
|
2019-03-28 03:12:44 +03:00
|
|
|
|
{
|
2019-06-12 05:20:59 +03:00
|
|
|
|
private NFCNdefReaderSession _nfcSession = null;
|
|
|
|
|
private iOSPushNotificationHandler _pushHandler = null;
|
2020-05-29 19:26:36 +03:00
|
|
|
|
private Core.NFCReaderDelegate _nfcDelegate = null;
|
2019-07-01 23:56:42 +03:00
|
|
|
|
private NSTimer _clipboardTimer = null;
|
2019-07-02 06:44:47 +03:00
|
|
|
|
private nint _clipboardBackgroundTaskId;
|
2020-05-29 19:26:36 +03:00
|
|
|
|
private NSTimer _vaultTimeoutTimer = null;
|
2019-07-02 06:44:47 +03:00
|
|
|
|
private nint _lockBackgroundTaskId;
|
2019-07-13 03:56:54 +03:00
|
|
|
|
private NSTimer _eventTimer = null;
|
|
|
|
|
private nint _eventBackgroundTaskId;
|
2019-06-11 22:20:28 +03:00
|
|
|
|
|
2019-06-12 06:04:41 +03:00
|
|
|
|
private IDeviceActionService _deviceActionService;
|
|
|
|
|
private IMessagingService _messagingService;
|
|
|
|
|
private IBroadcasterService _broadcasterService;
|
|
|
|
|
private IStorageService _storageService;
|
2020-05-29 19:26:36 +03:00
|
|
|
|
private IVaultTimeoutService _vaultTimeoutService;
|
2019-07-13 03:56:54 +03:00
|
|
|
|
private IEventService _eventService;
|
2019-06-12 06:04:41 +03:00
|
|
|
|
|
2019-03-28 03:12:44 +03:00
|
|
|
|
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
|
|
|
|
|
{
|
2019-06-27 03:28:23 +03:00
|
|
|
|
Forms.Init();
|
2019-06-11 22:20:28 +03:00
|
|
|
|
InitApp();
|
2019-07-05 20:35:22 +03:00
|
|
|
|
|
2019-06-12 06:04:41 +03:00
|
|
|
|
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
|
|
|
|
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
|
|
|
|
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
|
|
|
|
|
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
|
2020-05-29 19:26:36 +03:00
|
|
|
|
_vaultTimeoutService = ServiceContainer.Resolve<IVaultTimeoutService>("vaultTimeoutService");
|
2019-07-13 03:56:54 +03:00
|
|
|
|
_eventService = ServiceContainer.Resolve<IEventService>("eventService");
|
2019-04-23 00:08:37 +03:00
|
|
|
|
|
2019-05-17 19:03:35 +03:00
|
|
|
|
LoadApplication(new App.App(null));
|
2019-10-01 04:39:50 +03:00
|
|
|
|
iOSCoreHelpers.AppearanceAdjustments(_deviceActionService);
|
2019-05-23 03:28:31 +03:00
|
|
|
|
ZXing.Net.Mobile.Forms.iOS.Platform.Init();
|
2019-06-12 06:04:41 +03:00
|
|
|
|
|
2019-06-27 23:22:58 +03:00
|
|
|
|
_broadcasterService.Subscribe(nameof(AppDelegate), async (message) =>
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
2020-05-29 19:26:36 +03:00
|
|
|
|
if (message.Command == "scheduleVaultTimeoutTimer")
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
2020-05-29 19:26:36 +03:00
|
|
|
|
VaultTimeoutTimer((int)message.Data);
|
2019-06-12 06:04:41 +03:00
|
|
|
|
}
|
2020-05-29 19:26:36 +03:00
|
|
|
|
else if (message.Command == "cancelVaultTimeoutTimer")
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
2020-05-29 19:26:36 +03:00
|
|
|
|
CancelVaultTimeoutTimer();
|
2019-06-12 06:04:41 +03:00
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
else if (message.Command == "startEventTimer")
|
2019-07-13 03:56:54 +03:00
|
|
|
|
{
|
|
|
|
|
StartEventTimer();
|
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
else if (message.Command == "stopEventTimer")
|
2019-07-13 03:56:54 +03:00
|
|
|
|
{
|
|
|
|
|
var task = StopEventTimerAsync();
|
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
else if (message.Command == "updatedTheme")
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
2019-06-24 19:23:00 +03:00
|
|
|
|
// ThemeManager.SetThemeStyle(message.Data as string);
|
2019-06-12 06:04:41 +03:00
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
else if (message.Command == "copiedToClipboard")
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
2019-07-02 06:44:47 +03:00
|
|
|
|
|
|
|
|
|
Device.BeginInvokeOnMainThread(() =>
|
|
|
|
|
{
|
|
|
|
|
var task = ClearClipboardTimerAsync(message.Data as Tuple<string, int?, bool>);
|
|
|
|
|
});
|
2019-06-12 06:04:41 +03:00
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
else if (message.Command == "listenYubiKeyOTP")
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
2020-05-29 19:26:36 +03:00
|
|
|
|
iOSCoreHelpers.ListenYubiKey((bool)message.Data, _deviceActionService, _nfcSession, _nfcDelegate);
|
2019-06-12 06:04:41 +03:00
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
else if (message.Command == "unlocked")
|
2019-07-22 14:09:51 +03:00
|
|
|
|
{
|
|
|
|
|
var needsAutofillReplacement = await _storageService.GetAsync<bool?>(
|
|
|
|
|
Core.Constants.AutofillNeedsIdentityReplacementKey);
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (needsAutofillReplacement.GetValueOrDefault())
|
2019-07-22 14:09:51 +03:00
|
|
|
|
{
|
|
|
|
|
await ASHelpers.ReplaceAllIdentities();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
else if (message.Command == "showAppExtension")
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
2019-07-02 20:15:00 +03:00
|
|
|
|
Device.BeginInvokeOnMainThread(() => ShowAppExtension((ExtensionPageViewModel)message.Data));
|
2019-06-12 06:04:41 +03:00
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
else if (message.Command == "showStatusBar")
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
2019-06-26 17:05:31 +03:00
|
|
|
|
Device.BeginInvokeOnMainThread(() =>
|
|
|
|
|
UIApplication.SharedApplication.SetStatusBarHidden(!(bool)message.Data, false));
|
2019-06-12 06:04:41 +03:00
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
else if (message.Command == "syncCompleted")
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (message.Data is Dictionary<string, object> data && data.ContainsKey("successfully"))
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
|
|
|
|
var success = data["successfully"] as bool?;
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (success.GetValueOrDefault() && _deviceActionService.SystemMajorVersion() >= 12)
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
2019-06-27 23:22:58 +03:00
|
|
|
|
await ASHelpers.ReplaceAllIdentities();
|
2019-06-12 06:04:41 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-01 21:46:53 +03:00
|
|
|
|
else if (message.Command == "addedCipher" || message.Command == "editedCipher" ||
|
|
|
|
|
message.Command == "restoredCipher")
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (_deviceActionService.SystemMajorVersion() >= 12)
|
2019-06-27 23:22:58 +03:00
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (await ASHelpers.IdentitiesCanIncremental())
|
2019-06-27 23:22:58 +03:00
|
|
|
|
{
|
|
|
|
|
var cipherId = message.Data as string;
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (message.Command == "addedCipher" && !string.IsNullOrWhiteSpace(cipherId))
|
2019-06-27 23:22:58 +03:00
|
|
|
|
{
|
|
|
|
|
var identity = await ASHelpers.GetCipherIdentityAsync(cipherId);
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (identity == null)
|
2019-06-27 23:22:58 +03:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await ASCredentialIdentityStore.SharedStore?.SaveCredentialIdentitiesAsync(
|
|
|
|
|
new ASPasswordCredentialIdentity[] { identity });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
await ASHelpers.ReplaceAllIdentities();
|
|
|
|
|
}
|
2019-06-12 06:04:41 +03:00
|
|
|
|
}
|
2020-05-20 20:35:20 +03:00
|
|
|
|
else if (message.Command == "deletedCipher" || message.Command == "softDeletedCipher")
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (_deviceActionService.SystemMajorVersion() >= 12)
|
2019-06-27 23:22:58 +03:00
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (await ASHelpers.IdentitiesCanIncremental())
|
2019-06-27 23:22:58 +03:00
|
|
|
|
{
|
|
|
|
|
var identity = ASHelpers.ToCredentialIdentity(
|
|
|
|
|
message.Data as Bit.Core.Models.View.CipherView);
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (identity == null)
|
2019-06-27 23:22:58 +03:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await ASCredentialIdentityStore.SharedStore?.RemoveCredentialIdentitiesAsync(
|
|
|
|
|
new ASPasswordCredentialIdentity[] { identity });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await ASHelpers.ReplaceAllIdentities();
|
|
|
|
|
}
|
2019-06-12 06:04:41 +03:00
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
else if (message.Command == "loggedOut")
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (_deviceActionService.SystemMajorVersion() >= 12)
|
2019-06-27 23:22:58 +03:00
|
|
|
|
{
|
|
|
|
|
await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync();
|
|
|
|
|
}
|
2019-06-12 06:04:41 +03:00
|
|
|
|
}
|
2020-05-20 20:35:20 +03:00
|
|
|
|
else if ((message.Command == "softDeletedCipher" || message.Command == "restoredCipher")
|
|
|
|
|
&& _deviceActionService.SystemMajorVersion() >= 12)
|
|
|
|
|
{
|
|
|
|
|
await ASHelpers.ReplaceAllIdentities();
|
|
|
|
|
}
|
2020-06-01 21:46:53 +03:00
|
|
|
|
else if (message.Command == "vaultTimeoutActionChanged")
|
|
|
|
|
{
|
|
|
|
|
var timeoutAction = await _storageService.GetAsync<string>(Constants.VaultTimeoutActionKey);
|
|
|
|
|
if (timeoutAction == "logOut")
|
|
|
|
|
{
|
|
|
|
|
await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ASHelpers.ReplaceAllIdentities();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-12 06:04:41 +03:00
|
|
|
|
});
|
|
|
|
|
|
2019-03-28 03:12:44 +03:00
|
|
|
|
return base.FinishedLaunching(app, options);
|
|
|
|
|
}
|
2019-06-11 22:20:28 +03:00
|
|
|
|
|
2019-06-12 06:04:41 +03:00
|
|
|
|
public override void DidEnterBackground(UIApplication uiApplication)
|
|
|
|
|
{
|
|
|
|
|
var view = new UIView(UIApplication.SharedApplication.KeyWindow.Frame)
|
|
|
|
|
{
|
|
|
|
|
Tag = 4321
|
|
|
|
|
};
|
|
|
|
|
var backgroundView = new UIView(UIApplication.SharedApplication.KeyWindow.Frame)
|
|
|
|
|
{
|
2020-05-29 19:26:36 +03:00
|
|
|
|
BackgroundColor = ThemeManager.GetResourceColor("SplashBackgroundColor").ToUIColor()
|
2019-06-12 06:04:41 +03:00
|
|
|
|
};
|
2019-09-30 23:52:20 +03:00
|
|
|
|
var logo = new UIImage(!ThemeManager.UsingLightTheme ? "logo_white.png" : "logo.png");
|
2019-06-26 16:35:18 +03:00
|
|
|
|
var imageView = new UIImageView(logo)
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
|
|
|
|
Center = new CoreGraphics.CGPoint(view.Center.X, view.Center.Y - 30)
|
|
|
|
|
};
|
|
|
|
|
view.AddSubview(backgroundView);
|
|
|
|
|
view.AddSubview(imageView);
|
|
|
|
|
UIApplication.SharedApplication.KeyWindow.AddSubview(view);
|
|
|
|
|
UIApplication.SharedApplication.KeyWindow.BringSubviewToFront(view);
|
|
|
|
|
UIApplication.SharedApplication.KeyWindow.EndEditing(true);
|
|
|
|
|
UIApplication.SharedApplication.SetStatusBarHidden(true, false);
|
2019-07-13 03:56:54 +03:00
|
|
|
|
_storageService.SaveAsync(Constants.LastActiveKey, DateTime.UtcNow);
|
2019-07-14 03:25:31 +03:00
|
|
|
|
_messagingService.Send("slept");
|
2019-06-12 06:04:41 +03:00
|
|
|
|
base.DidEnterBackground(uiApplication);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnActivated(UIApplication uiApplication)
|
|
|
|
|
{
|
|
|
|
|
base.OnActivated(uiApplication);
|
|
|
|
|
UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
|
|
|
|
|
var view = UIApplication.SharedApplication.KeyWindow.ViewWithTag(4321);
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (view != null)
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
|
|
|
|
view.RemoveFromSuperview();
|
|
|
|
|
UIApplication.SharedApplication.SetStatusBarHidden(false, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void WillEnterForeground(UIApplication uiApplication)
|
|
|
|
|
{
|
2019-06-25 00:02:05 +03:00
|
|
|
|
_messagingService.Send("resumed");
|
2019-06-12 06:04:41 +03:00
|
|
|
|
base.WillEnterForeground(uiApplication);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication,
|
|
|
|
|
NSObject annotation)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-11 22:20:28 +03:00
|
|
|
|
public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
|
|
|
|
|
{
|
|
|
|
|
_pushHandler?.OnErrorReceived(error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
|
|
|
|
|
{
|
|
|
|
|
_pushHandler?.OnRegisteredSuccess(deviceToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void DidRegisterUserNotificationSettings(UIApplication application,
|
|
|
|
|
UIUserNotificationSettings notificationSettings)
|
|
|
|
|
{
|
|
|
|
|
application.RegisterForRemoteNotifications();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo,
|
|
|
|
|
Action<UIBackgroundFetchResult> completionHandler)
|
|
|
|
|
{
|
|
|
|
|
_pushHandler?.OnMessageReceived(userInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
|
|
|
|
|
{
|
|
|
|
|
_pushHandler?.OnMessageReceived(userInfo);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-28 15:21:44 +03:00
|
|
|
|
public void InitApp()
|
2019-06-11 22:20:28 +03:00
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (ServiceContainer.RegisteredServices.Count > 0)
|
2019-06-11 22:20:28 +03:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-28 15:21:44 +03:00
|
|
|
|
// Migration services
|
2019-06-11 22:20:28 +03:00
|
|
|
|
ServiceContainer.Register<ILogService>("logService", new ConsoleLogService());
|
|
|
|
|
|
2019-07-03 17:08:59 +03:00
|
|
|
|
// Note: This might cause a race condition. Investigate more.
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
FFImageLoading.Forms.Platform.CachedImageRenderer.Init();
|
|
|
|
|
FFImageLoading.ImageService.Instance.Initialize(new FFImageLoading.Config.Configuration
|
|
|
|
|
{
|
|
|
|
|
FadeAnimationEnabled = false,
|
|
|
|
|
FadeAnimationForCachedImages = false
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2019-06-28 15:21:44 +03:00
|
|
|
|
iOSCoreHelpers.RegisterLocalServices();
|
|
|
|
|
RegisterPush();
|
2019-09-04 18:52:32 +03:00
|
|
|
|
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
|
|
|
|
ServiceContainer.Init(deviceActionService.DeviceUserAgent);
|
2020-04-02 16:02:38 +03:00
|
|
|
|
iOSCoreHelpers.RegisterAppCenter();
|
2019-06-28 15:21:44 +03:00
|
|
|
|
_pushHandler = new iOSPushNotificationHandler(
|
|
|
|
|
ServiceContainer.Resolve<IPushNotificationListenerService>("pushNotificationListenerService"));
|
2020-05-29 19:26:36 +03:00
|
|
|
|
_nfcDelegate = new Core.NFCReaderDelegate((success, message) =>
|
2019-06-28 15:21:44 +03:00
|
|
|
|
_messagingService.Send("gotYubiKeyOTP", message));
|
2019-06-11 22:20:28 +03:00
|
|
|
|
|
2020-02-10 22:07:06 +03:00
|
|
|
|
iOSCoreHelpers.Bootstrap(async () => await ApplyManagedSettingsAsync());
|
2019-06-28 15:21:44 +03:00
|
|
|
|
}
|
2019-06-11 22:20:28 +03:00
|
|
|
|
|
2019-06-28 15:21:44 +03:00
|
|
|
|
private void RegisterPush()
|
|
|
|
|
{
|
2019-06-11 22:20:28 +03:00
|
|
|
|
var notificationListenerService = new PushNotificationListenerService();
|
|
|
|
|
ServiceContainer.Register<IPushNotificationListenerService>(
|
|
|
|
|
"pushNotificationListenerService", notificationListenerService);
|
|
|
|
|
var iosPushNotificationService = new iOSPushNotificationService();
|
|
|
|
|
ServiceContainer.Register<IPushNotificationService>(
|
|
|
|
|
"pushNotificationService", iosPushNotificationService);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 19:26:36 +03:00
|
|
|
|
private void VaultTimeoutTimer(int vaultTimeoutMinutes)
|
2019-07-02 04:10:24 +03:00
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (_lockBackgroundTaskId > 0)
|
2019-07-02 06:44:47 +03:00
|
|
|
|
{
|
|
|
|
|
UIApplication.SharedApplication.EndBackgroundTask(_lockBackgroundTaskId);
|
|
|
|
|
_lockBackgroundTaskId = 0;
|
|
|
|
|
}
|
|
|
|
|
_lockBackgroundTaskId = UIApplication.SharedApplication.BeginBackgroundTask(() =>
|
|
|
|
|
{
|
|
|
|
|
UIApplication.SharedApplication.EndBackgroundTask(_lockBackgroundTaskId);
|
|
|
|
|
_lockBackgroundTaskId = 0;
|
|
|
|
|
});
|
2020-05-29 19:26:36 +03:00
|
|
|
|
var vaultTimeoutMs = vaultTimeoutMinutes * 60000;
|
|
|
|
|
_vaultTimeoutTimer?.Invalidate();
|
|
|
|
|
_vaultTimeoutTimer?.Dispose();
|
|
|
|
|
_vaultTimeoutTimer = null;
|
|
|
|
|
var vaultTimeoutMsSpan = TimeSpan.FromMilliseconds(vaultTimeoutMs + 10);
|
2019-07-02 04:10:24 +03:00
|
|
|
|
Device.BeginInvokeOnMainThread(() =>
|
|
|
|
|
{
|
2020-05-29 19:26:36 +03:00
|
|
|
|
_vaultTimeoutTimer = NSTimer.CreateScheduledTimer(vaultTimeoutMsSpan, timer =>
|
2019-07-02 04:10:24 +03:00
|
|
|
|
{
|
|
|
|
|
Device.BeginInvokeOnMainThread(() =>
|
|
|
|
|
{
|
2020-05-29 19:26:36 +03:00
|
|
|
|
_vaultTimeoutService.CheckVaultTimeoutAsync();
|
|
|
|
|
_vaultTimeoutTimer?.Invalidate();
|
|
|
|
|
_vaultTimeoutTimer?.Dispose();
|
|
|
|
|
_vaultTimeoutTimer = null;
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (_lockBackgroundTaskId > 0)
|
2019-07-02 06:44:47 +03:00
|
|
|
|
{
|
|
|
|
|
UIApplication.SharedApplication.EndBackgroundTask(_lockBackgroundTaskId);
|
|
|
|
|
_lockBackgroundTaskId = 0;
|
|
|
|
|
}
|
2019-07-02 04:10:24 +03:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 19:26:36 +03:00
|
|
|
|
private void CancelVaultTimeoutTimer()
|
2019-07-02 04:10:24 +03:00
|
|
|
|
{
|
2020-05-29 19:26:36 +03:00
|
|
|
|
_vaultTimeoutTimer?.Invalidate();
|
|
|
|
|
_vaultTimeoutTimer?.Dispose();
|
|
|
|
|
_vaultTimeoutTimer = null;
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (_lockBackgroundTaskId > 0)
|
2019-07-02 06:44:47 +03:00
|
|
|
|
{
|
|
|
|
|
UIApplication.SharedApplication.EndBackgroundTask(_lockBackgroundTaskId);
|
|
|
|
|
_lockBackgroundTaskId = 0;
|
|
|
|
|
}
|
2019-07-02 04:10:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-01 23:56:42 +03:00
|
|
|
|
private async Task ClearClipboardTimerAsync(Tuple<string, int?, bool> data)
|
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (data.Item3)
|
2019-07-01 23:56:42 +03:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var clearMs = data.Item2;
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (clearMs == null)
|
2019-07-01 23:56:42 +03:00
|
|
|
|
{
|
|
|
|
|
var clearSeconds = await _storageService.GetAsync<int?>(Constants.ClearClipboardKey);
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (clearSeconds != null)
|
2019-07-01 23:56:42 +03:00
|
|
|
|
{
|
|
|
|
|
clearMs = clearSeconds.Value * 1000;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (clearMs == null)
|
2019-07-01 23:56:42 +03:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (_clipboardBackgroundTaskId > 0)
|
2019-07-02 06:44:47 +03:00
|
|
|
|
{
|
|
|
|
|
UIApplication.SharedApplication.EndBackgroundTask(_clipboardBackgroundTaskId);
|
|
|
|
|
_clipboardBackgroundTaskId = 0;
|
|
|
|
|
}
|
|
|
|
|
_clipboardBackgroundTaskId = UIApplication.SharedApplication.BeginBackgroundTask(() =>
|
|
|
|
|
{
|
|
|
|
|
UIApplication.SharedApplication.EndBackgroundTask(_clipboardBackgroundTaskId);
|
|
|
|
|
_clipboardBackgroundTaskId = 0;
|
|
|
|
|
});
|
2019-07-01 23:56:42 +03:00
|
|
|
|
_clipboardTimer?.Invalidate();
|
|
|
|
|
_clipboardTimer?.Dispose();
|
|
|
|
|
_clipboardTimer = null;
|
2019-07-02 06:44:47 +03:00
|
|
|
|
var lastClipboardChangeCount = UIPasteboard.General.ChangeCount;
|
2019-07-01 23:56:42 +03:00
|
|
|
|
var clearMsSpan = TimeSpan.FromMilliseconds(clearMs.Value);
|
2019-07-02 06:44:47 +03:00
|
|
|
|
_clipboardTimer = NSTimer.CreateScheduledTimer(clearMsSpan, timer =>
|
2019-07-01 23:56:42 +03:00
|
|
|
|
{
|
2019-07-02 06:44:47 +03:00
|
|
|
|
Device.BeginInvokeOnMainThread(() =>
|
2019-07-01 23:56:42 +03:00
|
|
|
|
{
|
2019-07-02 06:44:47 +03:00
|
|
|
|
var changeNow = UIPasteboard.General.ChangeCount;
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (changeNow == 0 || lastClipboardChangeCount == changeNow)
|
2019-07-01 23:56:42 +03:00
|
|
|
|
{
|
2019-07-02 06:44:47 +03:00
|
|
|
|
UIPasteboard.General.String = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
_clipboardTimer?.Invalidate();
|
|
|
|
|
_clipboardTimer?.Dispose();
|
|
|
|
|
_clipboardTimer = null;
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (_clipboardBackgroundTaskId > 0)
|
2019-07-02 06:44:47 +03:00
|
|
|
|
{
|
|
|
|
|
UIApplication.SharedApplication.EndBackgroundTask(_clipboardBackgroundTaskId);
|
|
|
|
|
_clipboardBackgroundTaskId = 0;
|
|
|
|
|
}
|
2019-07-01 23:56:42 +03:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-02 20:15:00 +03:00
|
|
|
|
private void ShowAppExtension(ExtensionPageViewModel extensionPageViewModel)
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
|
|
|
|
var itemProvider = new NSItemProvider(new NSDictionary(), Core.Constants.UTTypeAppExtensionSetup);
|
2019-06-28 18:47:04 +03:00
|
|
|
|
var extensionItem = new NSExtensionItem
|
|
|
|
|
{
|
|
|
|
|
Attachments = new NSItemProvider[] { itemProvider }
|
|
|
|
|
};
|
2019-07-02 20:15:00 +03:00
|
|
|
|
var activityViewController = new UIActivityViewController(new NSExtensionItem[] { extensionItem }, null)
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
2019-07-02 20:15:00 +03:00
|
|
|
|
CompletionHandler = (activityType, completed) =>
|
|
|
|
|
{
|
2019-07-06 00:10:37 +03:00
|
|
|
|
extensionPageViewModel.EnabledExtension(completed && activityType == iOSCoreHelpers.AppExtensionId);
|
2019-07-02 20:15:00 +03:00
|
|
|
|
}
|
2019-06-12 06:04:41 +03:00
|
|
|
|
};
|
|
|
|
|
var modal = UIApplication.SharedApplication.KeyWindow.RootViewController.ModalViewController;
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (activityViewController.PopoverPresentationController != null)
|
2019-06-12 06:04:41 +03:00
|
|
|
|
{
|
|
|
|
|
activityViewController.PopoverPresentationController.SourceView = modal.View;
|
|
|
|
|
var frame = UIScreen.MainScreen.Bounds;
|
|
|
|
|
frame.Height /= 2;
|
|
|
|
|
activityViewController.PopoverPresentationController.SourceRect = frame;
|
|
|
|
|
}
|
|
|
|
|
modal.PresentViewController(activityViewController, true, null);
|
2019-06-12 05:20:59 +03:00
|
|
|
|
}
|
2019-07-13 03:56:54 +03:00
|
|
|
|
|
|
|
|
|
private void StartEventTimer()
|
|
|
|
|
{
|
|
|
|
|
_eventTimer?.Invalidate();
|
|
|
|
|
_eventTimer?.Dispose();
|
|
|
|
|
_eventTimer = null;
|
|
|
|
|
Device.BeginInvokeOnMainThread(() =>
|
|
|
|
|
{
|
|
|
|
|
_eventTimer = NSTimer.CreateScheduledTimer(60, true, timer =>
|
|
|
|
|
{
|
|
|
|
|
var task = Task.Run(() => _eventService.UploadEventsAsync());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task StopEventTimerAsync()
|
|
|
|
|
{
|
|
|
|
|
_eventTimer?.Invalidate();
|
|
|
|
|
_eventTimer?.Dispose();
|
|
|
|
|
_eventTimer = null;
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (_eventBackgroundTaskId > 0)
|
2019-07-13 03:56:54 +03:00
|
|
|
|
{
|
|
|
|
|
UIApplication.SharedApplication.EndBackgroundTask(_eventBackgroundTaskId);
|
|
|
|
|
_eventBackgroundTaskId = 0;
|
|
|
|
|
}
|
|
|
|
|
_eventBackgroundTaskId = UIApplication.SharedApplication.BeginBackgroundTask(() =>
|
|
|
|
|
{
|
|
|
|
|
UIApplication.SharedApplication.EndBackgroundTask(_eventBackgroundTaskId);
|
|
|
|
|
_eventBackgroundTaskId = 0;
|
|
|
|
|
});
|
|
|
|
|
await _eventService.UploadEventsAsync();
|
|
|
|
|
UIApplication.SharedApplication.EndBackgroundTask(_eventBackgroundTaskId);
|
|
|
|
|
_eventBackgroundTaskId = 0;
|
|
|
|
|
}
|
2020-02-10 22:07:06 +03:00
|
|
|
|
|
|
|
|
|
private async Task ApplyManagedSettingsAsync()
|
|
|
|
|
{
|
|
|
|
|
var userDefaults = NSUserDefaults.StandardUserDefaults;
|
|
|
|
|
var managedSettings = userDefaults.DictionaryForKey("com.apple.configuration.managed");
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (managedSettings != null && managedSettings.Count > 0)
|
2020-02-10 22:07:06 +03:00
|
|
|
|
{
|
|
|
|
|
var dict = new Dictionary<string, string>();
|
2020-03-28 16:16:28 +03:00
|
|
|
|
foreach (var setting in managedSettings)
|
2020-02-10 22:07:06 +03:00
|
|
|
|
{
|
|
|
|
|
dict.Add(setting.Key.ToString(), setting.Value?.ToString());
|
|
|
|
|
}
|
|
|
|
|
await AppHelpers.SetPreconfiguredSettingsAsync(dict);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-28 03:12:44 +03:00
|
|
|
|
}
|
|
|
|
|
}
|