1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-07 11:03:54 +00:00

Fix Clipboard clear after time on iOS (#1679)

* Fixed Clipboard clear after x seconds depending on what the user set. Also refactored a bit to make the Clipboard a custom service to provide a better way to handle this situation #1464

* Clear some usings #1464
This commit is contained in:
Federico Maccaroni
2021-12-10 17:41:36 -03:00
committed by GitHub
parent 23a164b245
commit 705b8ac12b
17 changed files with 157 additions and 131 deletions

View File

@@ -71,14 +71,6 @@ namespace Bit.iOS
iOSCoreHelpers.AppearanceAdjustments();
});
}
else if (message.Command == "copiedToClipboard")
{
Device.BeginInvokeOnMainThread(() =>
{
var task = ClearClipboardTimerAsync(message.Data as Tuple<string, int?, bool>);
});
}
else if (message.Command == "listenYubiKeyOTP")
{
iOSCoreHelpers.ListenYubiKey((bool)message.Data, _deviceActionService, _nfcSession, _nfcDelegate);
@@ -329,61 +321,6 @@ namespace Bit.iOS
"pushNotificationService", iosPushNotificationService);
}
private async Task ClearClipboardTimerAsync(Tuple<string, int?, bool> data)
{
if (data.Item3)
{
return;
}
var clearMs = data.Item2;
if (clearMs == null)
{
var clearSeconds = await _storageService.GetAsync<int?>(Constants.ClearClipboardKey);
if (clearSeconds != null)
{
clearMs = clearSeconds.Value * 1000;
}
}
if (clearMs == null)
{
return;
}
if (_clipboardBackgroundTaskId > 0)
{
UIApplication.SharedApplication.EndBackgroundTask(_clipboardBackgroundTaskId);
_clipboardBackgroundTaskId = 0;
}
_clipboardBackgroundTaskId = UIApplication.SharedApplication.BeginBackgroundTask(() =>
{
UIApplication.SharedApplication.EndBackgroundTask(_clipboardBackgroundTaskId);
_clipboardBackgroundTaskId = 0;
});
_clipboardTimer?.Invalidate();
_clipboardTimer?.Dispose();
_clipboardTimer = null;
var lastClipboardChangeCount = UIPasteboard.General.ChangeCount;
var clearMsSpan = TimeSpan.FromMilliseconds(clearMs.Value);
_clipboardTimer = NSTimer.CreateScheduledTimer(clearMsSpan, timer =>
{
Device.BeginInvokeOnMainThread(() =>
{
var changeNow = UIPasteboard.General.ChangeCount;
if (changeNow == 0 || lastClipboardChangeCount == changeNow)
{
UIPasteboard.General.String = string.Empty;
}
_clipboardTimer?.Invalidate();
_clipboardTimer?.Dispose();
_clipboardTimer = null;
if (_clipboardBackgroundTaskId > 0)
{
UIApplication.SharedApplication.EndBackgroundTask(_clipboardBackgroundTaskId);
_clipboardBackgroundTaskId = 0;
}
});
});
}
private void ShowAppExtension(ExtensionPageViewModel extensionPageViewModel)
{
var itemProvider = new NSItemProvider(new NSDictionary(), Core.Constants.UTTypeAppExtensionSetup);