Skip to content

Commit fce328d

Browse files
Merge pull request #13 from notifo-io/worker-package
Worker package.
2 parents 6afba7f + ac9fdf5 commit fce328d

16 files changed

+529
-33
lines changed

sdk/Notifo.SDK.FirebasePlugin/Directory.Build.props renamed to Directory.Build.props

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
<Authors>sebastianstehle</Authors>
44
<Company>Squidex UG (haftungsbeschränkt)</Company>
55
<Copyright>MIT</Copyright>
6-
<Description>Notifo SDK for Xamarin - Plugin.FirebasePushNotification integration.</Description>
7-
<PackageId>Notifo.Xamarin.Firebase</PackageId>
6+
<Description>Notifo SDK for Xamarin.</Description>
87
<PackageIcon>logo-squared.png</PackageIcon>
98
<PackageLicenseExpression>MIT</PackageLicenseExpression>
109
<PackageProjectUrl>https://notifo.io</PackageProjectUrl>

Notifo.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleNotificationServiceEx
3030
EndProject
3131
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.iOS.Shared", "sample\Sample.iOS.Shared\Sample.iOS.Shared.csproj", "{7D4A0E79-8075-42A6-ACC5-E5B666F75313}"
3232
EndProject
33+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notifo.SDK.Worker", "sdk\Notifo.SDK.Worker\Notifo.SDK.Worker.csproj", "{938B1A56-1C33-40CB-8569-8625997945C8}"
34+
EndProject
3335
Global
3436
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3537
Debug|Any CPU = Debug|Any CPU
@@ -154,6 +156,18 @@ Global
154156
{7D4A0E79-8075-42A6-ACC5-E5B666F75313}.Release|iPhone.Build.0 = Release|Any CPU
155157
{7D4A0E79-8075-42A6-ACC5-E5B666F75313}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
156158
{7D4A0E79-8075-42A6-ACC5-E5B666F75313}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
159+
{938B1A56-1C33-40CB-8569-8625997945C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
160+
{938B1A56-1C33-40CB-8569-8625997945C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
161+
{938B1A56-1C33-40CB-8569-8625997945C8}.Debug|iPhone.ActiveCfg = Debug|Any CPU
162+
{938B1A56-1C33-40CB-8569-8625997945C8}.Debug|iPhone.Build.0 = Debug|Any CPU
163+
{938B1A56-1C33-40CB-8569-8625997945C8}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
164+
{938B1A56-1C33-40CB-8569-8625997945C8}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
165+
{938B1A56-1C33-40CB-8569-8625997945C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
166+
{938B1A56-1C33-40CB-8569-8625997945C8}.Release|Any CPU.Build.0 = Release|Any CPU
167+
{938B1A56-1C33-40CB-8569-8625997945C8}.Release|iPhone.ActiveCfg = Release|Any CPU
168+
{938B1A56-1C33-40CB-8569-8625997945C8}.Release|iPhone.Build.0 = Release|Any CPU
169+
{938B1A56-1C33-40CB-8569-8625997945C8}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
170+
{938B1A56-1C33-40CB-8569-8625997945C8}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
157171
EndGlobalSection
158172
GlobalSection(SolutionProperties) = preSolution
159173
HideSolutionNode = FALSE
@@ -167,6 +181,7 @@ Global
167181
{C4EF6311-9993-40BD-BEF8-3C495F571302} = {4270D4B1-5081-4E4F-8BDF-61ED888E936E}
168182
{1B35BAEA-5666-408C-BED4-DB6114F3070E} = {4270D4B1-5081-4E4F-8BDF-61ED888E936E}
169183
{7D4A0E79-8075-42A6-ACC5-E5B666F75313} = {4270D4B1-5081-4E4F-8BDF-61ED888E936E}
184+
{938B1A56-1C33-40CB-8569-8625997945C8} = {4D2C377A-D9F6-4EF3-A342-1B5A84F391DB}
170185
EndGlobalSection
171186
GlobalSection(ExtensibilityGlobals) = postSolution
172187
SolutionGuid = {87BCC08F-EAE5-4433-97FE-0DE5A56DBF78}

UpgradeLog.htm

Lines changed: 284 additions & 0 deletions
Large diffs are not rendered by default.

sdk/Notifo.SDK.FirebasePlugin/Notifo.SDK.FirebasePlugin.csproj

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<Project Sdk="MSBuild.Sdk.Extras/3.0.22">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.1;xamarinios10;monoandroid12.0;</TargetFrameworks>
5-
<LangVersion>8.0</LangVersion>
6-
<RootNamespace>Notifo.SDK.FirebasePlugin</RootNamespace>
7-
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8-
<GenerateDocumentationFile>true</GenerateDocumentationFile>
4+
<NoWarn>CS1591;CS0618</NoWarn>
95
<AssemblyName>Notifo.Xamarin.FirebasePlugin</AssemblyName>
6+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
7+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8+
<LangVersion>latest</LangVersion>
9+
<PackageId>Notifo.Xamarin.Firebase</PackageId>
10+
<RootNamespace>Notifo.SDK.FirebasePlugin</RootNamespace>
1011
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
1112
<RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
12-
<NoWarn>CS1591;CS0618</NoWarn>
13+
<TargetFrameworks>netstandard2.1;xamarinios10;monoandroid12.0;</TargetFrameworks>
1314
</PropertyGroup>
1415

1516
<ItemGroup>
@@ -53,8 +54,8 @@
5354
</ItemGroup>
5455

5556
<ItemGroup>
56-
<PackageReference Include="Notifo.SDK" Version="1.6.4" />
57-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" />
57+
<PackageReference Include="Notifo.SDK" Version="1.6.4" />
58+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" />
5859
</ItemGroup>
5960

6061
<ItemGroup>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<Project Sdk="MSBuild.Sdk.Extras/3.0.22">
2+
3+
<PropertyGroup>
4+
<NoWarn>CS1591;CS0618</NoWarn>
5+
<AssemblyName>Notifo.Xamarin.Worker</AssemblyName>
6+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
7+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8+
<LangVersion>latest</LangVersion>
9+
<RootNamespace>Notifo.SDK</RootNamespace>
10+
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
11+
<RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
12+
<TargetFrameworks>monoandroid12.0;</TargetFrameworks>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<None Include="logo-squared.png" Pack="true" PackagePath="\" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<Compile Remove="**\*.netstandard.cs" />
21+
<Compile Remove="**\*.android.cs" />
22+
<Compile Remove="**\*.ios.cs" />
23+
</ItemGroup>
24+
25+
<ItemGroup Condition="$(TargetFramework.StartsWith('netstandard'))">
26+
<Compile Include="**\*.netstandard.cs" />
27+
<None Include="**\*.android.cs" />
28+
<None Include="**\*.ios.cs" />
29+
</ItemGroup>
30+
31+
<ItemGroup Condition="$(TargetFramework.StartsWith('monoandroid'))">
32+
<Compile Include="**\*.android.cs" />
33+
<None Include="**\*.netstandard.cs" />
34+
<None Include="**\*.ios.cs" />
35+
</ItemGroup>
36+
37+
<ItemGroup Condition="$(TargetFramework.StartsWith('xamarinios'))">
38+
<Compile Include="**\*.ios.cs" />
39+
<None Include="**\*.netstandard.cs" />
40+
<None Include="**\*.android.cs" />
41+
</ItemGroup>
42+
43+
<ItemGroup>
44+
<ProjectReference Include="..\Notifo.SDK\Notifo.SDK.Core.csproj" />
45+
</ItemGroup>
46+
47+
<ItemGroup Condition="'$(TargetFramework)' == 'monoandroid12.0'">
48+
<PackageReference Include="Xamarin.Android.Arch.Work.Runtime">
49+
<Version>1.0.0.3</Version>
50+
</PackageReference>
51+
</ItemGroup>
52+
</Project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// ==========================================================================
2+
// Notifo.io
3+
// ==========================================================================
4+
// Copyright (c) Sebastian Stehle
5+
// All rights reserved. Licensed under the MIT license.
6+
// ==========================================================================
7+
8+
9+
using AndroidX.Work;
10+
using System;
11+
using System.Collections.Generic;
12+
using System.Text;
13+
14+
namespace Notifo.SDK
15+
{
16+
/// <summary>
17+
/// The <see cref="INotifoMobilePush"/> extension methods.
18+
/// </summary>
19+
public static class NotifoMobilePushExtensions
20+
{
21+
private static bool isWorkerRegistered;
22+
23+
/// <summary>
24+
/// Register a worker to update the mobile push automatically.
25+
/// </summary>
26+
/// <param name="notifoMobilePush">The <see cref="INotifoMobilePush"/> instance.</param>
27+
/// <param name="period">The update period.</param>
28+
/// <returns>The current instance.</returns>
29+
public static INotifoMobilePush UseTokenUpdateWorker(this INotifoMobilePush notifoMobilePush, TimeSpan period = default)
30+
{
31+
if (isWorkerRegistered)
32+
{
33+
return notifoMobilePush;
34+
}
35+
36+
if (period == default)
37+
{
38+
period = TimeSpan.FromDays(30);
39+
}
40+
41+
var workerRequest = PeriodicWorkRequest.Builder.From<UpdateWorker>(period).Build();
42+
43+
WorkManager.Instance.Enqueue(workerRequest);
44+
isWorkerRegistered = true;
45+
46+
return notifoMobilePush;
47+
}
48+
}
49+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// ==========================================================================
2+
// Notifo.io
3+
// ==========================================================================
4+
// Copyright (c) Sebastian Stehle
5+
// All rights reserved. Licensed under the MIT license.
6+
// ==========================================================================
7+
8+
using Android.Runtime;
9+
using AndroidX.Work;
10+
using System;
11+
using System.Collections.Generic;
12+
using System.Text;
13+
using System.Threading;
14+
15+
namespace Notifo.SDK
16+
{
17+
internal sealed class UpdateWorker : Worker
18+
{
19+
public UpdateWorker(IntPtr javaReference, JniHandleOwnership transfer)
20+
: base(javaReference, transfer)
21+
{
22+
}
23+
24+
public override Result DoWork()
25+
{
26+
NotifoIO.Current.Register();
27+
28+
try
29+
{
30+
using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(10)))
31+
{
32+
NotifoIO.Current.WaitForBackgroundTasksAsync(cts.Token).Wait(cts.Token);
33+
}
34+
}
35+
catch (OperationCanceledException)
36+
{
37+
return new Result.Retry();
38+
}
39+
40+
return new Result.Success();
41+
}
42+
}
43+
}
27.5 KB
Loading

sdk/Notifo.SDK/CommandQueue/DefaultCommandQueue.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Linq;
1313
using System.Threading;
1414
using System.Threading.Tasks;
15+
using Notifo.SDK.Extensions;
1516
using Notifo.SDK.Resources;
1617

1718
namespace Notifo.SDK.CommandQueue
@@ -42,6 +43,21 @@ public DefaultCommandQueue(
4243
task = Task.Run(RunAsync);
4344
}
4445

46+
public async Task CompleteAsync(
47+
CancellationToken ct)
48+
{
49+
queue.CompleteAdding();
50+
51+
Trigger();
52+
53+
foreach (var trigger in commandTriggers.OfType<IDisposable>())
54+
{
55+
trigger.Dispose();
56+
}
57+
58+
await task.WithCancellation(ct);
59+
}
60+
4561
public void Dispose()
4662
{
4763
queue.CompleteAdding();

sdk/Notifo.SDK/CommandQueue/ICommandQueue.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// ==========================================================================
77

88
using System;
9+
using System.Threading;
10+
using System.Threading.Tasks;
911

1012
namespace Notifo.SDK.CommandQueue
1113
{
@@ -16,5 +18,8 @@ internal interface ICommandQueue
1618
void Run(ICommand command);
1719

1820
void Trigger();
21+
22+
Task CompleteAsync(
23+
CancellationToken ct);
1924
}
2025
}

0 commit comments

Comments
 (0)