Skip to content

Commit 0d57fb6

Browse files
Use shared name.
1 parent 4c3da54 commit 0d57fb6

File tree

6 files changed

+53
-16
lines changed

6 files changed

+53
-16
lines changed

sample/Sample/NotifoStartup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class NotifoStartup : INotifoStartup
1616
public void ConfigureService(INotifoMobilePush notifo)
1717
{
1818
notifo
19+
.SetSharedName("notifo.Sample")
1920
.SetBaseUrl(Constants.ApiUrl)
2021
.UseFirebasePluginEventsProvider();
2122

sample/SampleNotificationServiceExtension/NotificationService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public override async void DidReceiveNotificationRequest(UNNotificationRequest r
3333
//Save the notification and create a mutable copy
3434
BestAttemptContent = (UNMutableNotificationContent)request.Content.MutableCopy();
3535

36-
NotifoIO.Current.SetNotificationHandler(new NotificationHandler());
36+
NotifoIO.Current
37+
.SetSharedName("notifo.Sample")
38+
.SetNotificationHandler(new NotificationHandler());
3739

3840
await NotifoIO.DidReceiveNotificationRequestAsync(request, BestAttemptContent);
3941

sdk/Notifo.SDK/CommandQueue/ICommandQueue.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ internal interface ICommandQueue
1515

1616
void Trigger();
1717

18+
void Clear();
19+
1820
Task CompleteAsync(
1921
CancellationToken ct);
2022
}

sdk/Notifo.SDK/INotifoMobilePush.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,20 @@ public partial interface INotifoMobilePush
4747
/// <summary>
4848
/// Clears all settings that are currently stored.
4949
/// </summary>
50-
void ClearAllSettings();
50+
/// <returns>The current instance.</returns>
51+
INotifoMobilePush ClearAllSettings();
52+
53+
/// <summary>
54+
/// Sets the shared name to store settings.
55+
/// </summary>
56+
/// <param name="sharedName">The shared name.</param>
57+
/// <returns>The current instance.</returns>
58+
INotifoMobilePush SetSharedName(string sharedName);
5159

5260
/// <summary>
5361
/// Sets the API key to use.
5462
/// </summary>
55-
/// <param name="apiKey">
56-
/// The API key.
57-
/// </param>
63+
/// <param name="apiKey">The API key.</param>
5864
/// <returns>The current instance.</returns>
5965
INotifoMobilePush SetApiKey(string apiKey);
6066

sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,37 @@ public NotifoMobilePushImplementation(
5959
partial void SetupPlatform();
6060

6161
/// <inheritdoc/>
62-
public void ClearAllSettings()
62+
public INotifoMobilePush ClearAllSettings()
6363
{
64-
commandStore.Clear();
65-
credentialsStore.Clear();
66-
seenNotificationsStore.Clear();
64+
static void Clear(object store)
65+
{
66+
if (store is IClearableStore clearable)
67+
{
68+
clearable.Clear();
69+
}
70+
}
71+
72+
Clear(commandStore);
73+
Clear(credentialsStore);
74+
Clear(seenNotificationsStore);
75+
return this;
76+
}
77+
78+
/// <inheritdoc/>
79+
public INotifoMobilePush SetSharedName(string sharedName)
80+
{
81+
static void Configure(object store, string sharedName)
82+
{
83+
if (store is ISettingsStore settings)
84+
{
85+
settings.SharedName = sharedName;
86+
}
87+
}
88+
89+
Configure(commandStore, sharedName);
90+
Configure(credentialsStore, sharedName);
91+
Configure(seenNotificationsStore, sharedName);
92+
return this;
6793
}
6894

6995
/// <inheritdoc/>

sdk/Notifo.SDK/Services/Settings.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,19 @@
1414

1515
namespace Notifo.SDK.Services;
1616

17-
internal sealed class Settings : ISeenNotificationsStore, ICommandStore, ICredentialsStore
17+
internal sealed class Settings : ISeenNotificationsStore, ICommandStore, ICredentialsStore, ISettingsStore, IClearableStore
1818
{
1919
private const string KeyCommand = "CommandV2";
2020
private const string KeyApiKey = nameof(ApiKey);
2121
private const string KeyApiUrl = nameof(ApiUrl);
2222
private const string KeySeenNotifications = "SeenNotificationsV2";
23-
private static readonly string PrimaryPackageName = Regex.Replace(AppInfo.PackageName, @"\.([^.]*)ServiceExtension$", string.Empty);
24-
private static readonly string SharedName = $"group.{PrimaryPackageName}.notifo";
2523

2624
private static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings
2725
{
2826
TypeNameHandling = TypeNameHandling.Auto
2927
};
3028

31-
public void Clear()
32-
{
33-
Preferences.Clear(SharedName);
34-
}
29+
public string? SharedName { get; set; }
3530

3631
public string? ApiKey
3732
{
@@ -45,6 +40,11 @@ public string? ApiUrl
4540
set => Preferences.Set(KeyApiUrl, value);
4641
}
4742

43+
public void Clear()
44+
{
45+
Preferences.Clear(SharedName);
46+
}
47+
4848
public async ValueTask AddSeenNotificationIdsAsync(int maxCapacity, IEnumerable<Guid> ids)
4949
{
5050
await Task.Run(() =>

0 commit comments

Comments
 (0)