mirror of
https://github.com/bitwarden/mobile
synced 2026-01-05 10:03:26 +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:
committed by
GitHub
parent
23a164b245
commit
705b8ac12b
40
src/iOS.Core/Services/ClipboardService.cs
Normal file
40
src/iOS.Core/Services/ClipboardService.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Abstractions;
|
||||
using Foundation;
|
||||
using MobileCoreServices;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.iOS.Core.Services
|
||||
{
|
||||
public class ClipboardService : IClipboardService
|
||||
{
|
||||
private readonly IStorageService _storageService;
|
||||
|
||||
public ClipboardService(IStorageService storageService)
|
||||
{
|
||||
_storageService = storageService;
|
||||
}
|
||||
|
||||
public async Task CopyTextAsync(string text, int expiresInMs = -1)
|
||||
{
|
||||
int clearSeconds = -1;
|
||||
if (expiresInMs < 0)
|
||||
{
|
||||
clearSeconds = await _storageService.GetAsync<int?>(Bit.Core.Constants.ClearClipboardKey) ?? -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
clearSeconds = expiresInMs * 1000;
|
||||
}
|
||||
|
||||
var dictArr = new NSDictionary<NSString, NSObject>[1];
|
||||
dictArr[0] = new NSDictionary<NSString, NSObject>(new NSString(UTType.UTF8PlainText), new NSString(text));
|
||||
Device.BeginInvokeOnMainThread(() => UIPasteboard.General.SetItems(dictArr, new UIPasteboardOptions
|
||||
{
|
||||
LocalOnly = true,
|
||||
ExpirationDate = clearSeconds > 0 ? NSDate.FromTimeIntervalSinceNow(clearSeconds) : null
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@ namespace Bit.iOS.Core.Utilities
|
||||
var cryptoPrimitiveService = new CryptoPrimitiveService();
|
||||
var mobileStorageService = new MobileStorageService(preferencesStorage, liteDbStorage);
|
||||
var deviceActionService = new DeviceActionService(mobileStorageService, messagingService);
|
||||
var clipboardService = new ClipboardService(mobileStorageService);
|
||||
var platformUtilsService = new MobilePlatformUtilsService(deviceActionService, messagingService,
|
||||
broadcasterService);
|
||||
var biometricService = new BiometricService(mobileStorageService);
|
||||
@@ -67,6 +68,7 @@ namespace Bit.iOS.Core.Utilities
|
||||
ServiceContainer.Register<IStorageService>("storageService", mobileStorageService);
|
||||
ServiceContainer.Register<IStorageService>("secureStorageService", secureStorageService);
|
||||
ServiceContainer.Register<IDeviceActionService>("deviceActionService", deviceActionService);
|
||||
ServiceContainer.Register<IClipboardService>("clipboardService", clipboardService);
|
||||
ServiceContainer.Register<IPlatformUtilsService>("platformUtilsService", platformUtilsService);
|
||||
ServiceContainer.Register<IBiometricService>("biometricService", biometricService);
|
||||
ServiceContainer.Register<ICryptoFunctionService>("cryptoFunctionService", cryptoFunctionService);
|
||||
|
||||
@@ -191,6 +191,7 @@
|
||||
<Compile Include="Views\Toast.cs" />
|
||||
<Compile Include="Renderers\SelectableLabelRenderer.cs" />
|
||||
<Compile Include="Effects\ScrollEnabledEffect.cs" />
|
||||
<Compile Include="Services\ClipboardService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\App\App.csproj">
|
||||
|
||||
Reference in New Issue
Block a user