settings shim with ios group id

This commit is contained in:
Kyle Spearrin 2019-07-05 17:10:37 -04:00
parent 19c62d3320
commit 341b66f44f
4 changed files with 72 additions and 32 deletions

View file

@ -4,64 +4,119 @@ namespace Bit.App.Migration
{ {
public class SettingsShim public class SettingsShim
{ {
private readonly string _sharedName;
public SettingsShim(string sharedName = null)
{
_sharedName = sharedName;
}
public bool Contains(string key) public bool Contains(string key)
{ {
return Xamarin.Essentials.Preferences.ContainsKey(key); return _sharedName != null ? Xamarin.Essentials.Preferences.ContainsKey(key, _sharedName) :
Xamarin.Essentials.Preferences.ContainsKey(key);
} }
public string GetValueOrDefault(string key, string defaultValue) public string GetValueOrDefault(string key, string defaultValue)
{ {
return Xamarin.Essentials.Preferences.Get(key, defaultValue); return _sharedName != null ? Xamarin.Essentials.Preferences.Get(key, defaultValue, _sharedName) :
Xamarin.Essentials.Preferences.Get(key, defaultValue);
} }
public DateTime GetValueOrDefault(string key, DateTime defaultValue) public DateTime GetValueOrDefault(string key, DateTime defaultValue)
{ {
return Xamarin.Essentials.Preferences.Get(key, defaultValue); return _sharedName != null ? Xamarin.Essentials.Preferences.Get(key, defaultValue, _sharedName) :
Xamarin.Essentials.Preferences.Get(key, defaultValue);
} }
public bool GetValueOrDefault(string key, bool defaultValue) public bool GetValueOrDefault(string key, bool defaultValue)
{ {
return Xamarin.Essentials.Preferences.Get(key, defaultValue); return _sharedName != null ? Xamarin.Essentials.Preferences.Get(key, defaultValue, _sharedName) :
Xamarin.Essentials.Preferences.Get(key, defaultValue);
} }
public int GetValueOrDefault(string key, int defaultValue) public int GetValueOrDefault(string key, int defaultValue)
{ {
return Xamarin.Essentials.Preferences.Get(key, defaultValue); return _sharedName != null ? Xamarin.Essentials.Preferences.Get(key, defaultValue, _sharedName) :
Xamarin.Essentials.Preferences.Get(key, defaultValue);
} }
public long GetValueOrDefault(string key, long defaultValue) public long GetValueOrDefault(string key, long defaultValue)
{ {
return Xamarin.Essentials.Preferences.Get(key, defaultValue); return _sharedName != null ? Xamarin.Essentials.Preferences.Get(key, defaultValue, _sharedName) :
Xamarin.Essentials.Preferences.Get(key, defaultValue);
} }
public void AddOrUpdateValue(string key, string value) public void AddOrUpdateValue(string key, string value)
{
if(_sharedName != null)
{
Xamarin.Essentials.Preferences.Set(key, value, _sharedName);
}
else
{ {
Xamarin.Essentials.Preferences.Set(key, value); Xamarin.Essentials.Preferences.Set(key, value);
} }
}
public void AddOrUpdateValue(string key, DateTime value) public void AddOrUpdateValue(string key, DateTime value)
{
if(_sharedName != null)
{
Xamarin.Essentials.Preferences.Set(key, value, _sharedName);
}
else
{ {
Xamarin.Essentials.Preferences.Set(key, value); Xamarin.Essentials.Preferences.Set(key, value);
} }
}
public void AddOrUpdateValue(string key, bool value) public void AddOrUpdateValue(string key, bool value)
{
if(_sharedName != null)
{
Xamarin.Essentials.Preferences.Set(key, value, _sharedName);
}
else
{ {
Xamarin.Essentials.Preferences.Set(key, value); Xamarin.Essentials.Preferences.Set(key, value);
} }
}
public void AddOrUpdateValue(string key, long value) public void AddOrUpdateValue(string key, long value)
{
if(_sharedName != null)
{
Xamarin.Essentials.Preferences.Set(key, value, _sharedName);
}
else
{ {
Xamarin.Essentials.Preferences.Set(key, value); Xamarin.Essentials.Preferences.Set(key, value);
} }
}
public void AddOrUpdateValue(string key, int value) public void AddOrUpdateValue(string key, int value)
{
if(_sharedName != null)
{
Xamarin.Essentials.Preferences.Set(key, value, _sharedName);
}
else
{ {
Xamarin.Essentials.Preferences.Set(key, value); Xamarin.Essentials.Preferences.Set(key, value);
} }
}
public void Remove(string key) public void Remove(string key)
{
if(_sharedName != null)
{
Xamarin.Essentials.Preferences.Remove(key, _sharedName);
}
else
{ {
Xamarin.Essentials.Preferences.Remove(key); Xamarin.Essentials.Preferences.Remove(key);
} }
} }
}
} }

View file

@ -1,8 +1,4 @@
using System; using System.IO;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Bit.App.Services; using Bit.App.Services;
@ -20,6 +16,8 @@ namespace Bit.iOS.Core.Utilities
public static class iOSCoreHelpers public static class iOSCoreHelpers
{ {
public static string AppId = "com.8bit.bitwarden"; public static string AppId = "com.8bit.bitwarden";
public static string AppAutofillId = "com.8bit.bitwarden.autofill";
public static string AppExtensionId = "com.8bit.bitwarden.find-login-action-extension";
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";

View file

@ -245,7 +245,7 @@ namespace Bit.iOS
// Migration services // Migration services
ServiceContainer.Register<ILogService>("logService", new ConsoleLogService()); ServiceContainer.Register<ILogService>("logService", new ConsoleLogService());
ServiceContainer.Register("settingsShim", new App.Migration.SettingsShim()); ServiceContainer.Register("settingsShim", new App.Migration.SettingsShim(iOSCoreHelpers.AppGroupId));
if(App.Migration.MigrationHelpers.NeedsMigration()) if(App.Migration.MigrationHelpers.NeedsMigration())
{ {
ServiceContainer.Register<App.Migration.Abstractions.IOldSecureStorageService>( ServiceContainer.Register<App.Migration.Abstractions.IOldSecureStorageService>(
@ -418,8 +418,7 @@ namespace Bit.iOS
{ {
CompletionHandler = (activityType, completed) => CompletionHandler = (activityType, completed) =>
{ {
extensionPageViewModel.EnabledExtension( extensionPageViewModel.EnabledExtension(completed && activityType == iOSCoreHelpers.AppExtensionId);
completed && activityType == "com.8bit.bitwarden.find-login-action-extension");
} }
}; };
var modal = UIApplication.SharedApplication.KeyWindow.RootViewController.ModalViewController; var modal = UIApplication.SharedApplication.KeyWindow.RootViewController.ModalViewController;

View file

@ -181,24 +181,12 @@
<Project>{4b8a8c41-9820-4341-974c-41e65b7f4366}</Project> <Project>{4b8a8c41-9820-4341-974c-41e65b7f4366}</Project>
<Name>Core</Name> <Name>Core</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\iOS.Autofill\iOS.Autofill.csproj">
<Project>{8a3ecd75-3ec8-4cb3-b3a2-a73a724c279a}</Project>
<Name>iOS.Autofill</Name>
<IsAppExtension>true</IsAppExtension>
<IsWatchApp>false</IsWatchApp>
</ProjectReference>
<ProjectReference Include="..\iOS.Core\iOS.Core.csproj"> <ProjectReference Include="..\iOS.Core\iOS.Core.csproj">
<Project>{e71f3053-056c-4381-9638-048ed73bdff6}</Project> <Project>{e71f3053-056c-4381-9638-048ed73bdff6}</Project>
<Name>iOS.Core</Name> <Name>iOS.Core</Name>
<IsAppExtension>false</IsAppExtension> <IsAppExtension>false</IsAppExtension>
<IsWatchApp>false</IsWatchApp> <IsWatchApp>false</IsWatchApp>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\iOS.Extension\iOS.Extension.csproj">
<Project>{324be76c-38fa-4f11-8bb1-95c7b3b1b545}</Project>
<Name>iOS.Extension</Name>
<IsAppExtension>true</IsAppExtension>
<IsWatchApp>false</IsWatchApp>
</ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<BundleResource Include="Resources\autofill-kb.png" /> <BundleResource Include="Resources\autofill-kb.png" />