Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Mar 26, 2024
2 parents 8b1a700 + c763bbb commit 659b846
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 37 deletions.
1 change: 0 additions & 1 deletion Shiny.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libs", "libs", "{6374E4D9-1
ProjectSection(SolutionItems) = preProject
src\Directory.build.props = src\Directory.build.props
src\Directory.build.targets = src\Directory.build.targets
src\global.json = src\global.json
src\nuget.png = src\nuget.png
src\nuget.txt = src\nuget.txt
version.json = version.json
Expand Down
76 changes: 51 additions & 25 deletions src/Shiny.Push/Platforms/Android/PushManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class PushManager : NotifyPropertyChanged,
readonly FirebaseConfig config;
readonly ILogger logger;
readonly IPushProvider provider;

bool registrationRequest = false;

public PushManager(
AndroidPlatform platform,
Expand Down Expand Up @@ -109,39 +109,58 @@ void TryCreateConfiguredChannel()

public async Task<PushAccessState> RequestAccess(CancellationToken cancelToken = default)
{
if (OperatingSystemShim.IsAndroidVersionAtLeast(33))
this.registrationRequest = true;
try
{
var access = await this.platform
.RequestAccess(Manifest.Permission.PostNotifications)
.ToTask(cancelToken);
// TODO: verify google signed in
if (OperatingSystem.IsAndroidVersionAtLeast(33))

Check failure on line 116 in src/Shiny.Push/Platforms/Android/PushManager.cs

View workflow job for this annotation

GitHub Actions / build

'OperatingSystem' does not contain a definition for 'IsAndroidVersionAtLeast'
{
var access = await this.platform
.RequestAccess(Manifest.Permission.PostNotifications)
.ToTask(cancelToken);

if (access != AccessState.Available)
return PushAccessState.Denied;
}
if (access != AccessState.Available)
return PushAccessState.Denied;
}

var nativeToken = await this.RequestNativeToken();
var regToken = await this.provider.Register(nativeToken); // never null on firebase
var nativeToken = await this.RequestNativeToken();
var regToken = await this.provider.Register(nativeToken); // never null on firebase

if (regToken != null && this.RegistrationToken != regToken)
if (regToken != null && this.RegistrationToken != regToken)
{
await this.services
.RunDelegates<IPushDelegate>(
x => x.OnNewToken(regToken),
this.logger
)
.ConfigureAwait(false);
}
this.NativeRegistrationToken = nativeToken;
this.RegistrationToken = regToken;

return new PushAccessState(AccessState.Available, this.RegistrationToken);
}
finally
{
await this.services
.RunDelegates<IPushDelegate>(
x => x.OnNewToken(regToken),
this.logger
)
.ConfigureAwait(false);
this.registrationRequest = false;
}
this.NativeRegistrationToken = nativeToken;
this.RegistrationToken = regToken;

return new PushAccessState(AccessState.Available, this.RegistrationToken);
}


public async Task UnRegister()
{
await this.provider.UnRegister().ConfigureAwait(false);
await FirebaseMessaging.Instance.DeleteToken().AsAsync().ConfigureAwait(false);
if (this.RegistrationToken == null)
return;

await this.provider
.UnRegister()
.ConfigureAwait(false);

await FirebaseMessaging
.Instance
.DeleteToken()
.AsAsync()
.ConfigureAwait(false);

await this.services
.RunDelegates<IPushDelegate>(
Expand Down Expand Up @@ -183,7 +202,9 @@ public void Handle(Activity activity, Intent intent)
x => x.OnEntry(data),
this.logger
)
.ContinueWith(x => this.logger.LogInformation("Finished executing push delegates"));
.ContinueWith(x =>
this.logger.LogInformation("Finished executing push delegates")
);
}


Expand Down Expand Up @@ -223,11 +244,16 @@ void DoInit()
FirebaseApp.InitializeApp(this.platform.AppContext, options);
}
}

ShinyFirebaseService.NewToken = async token =>
{
if (this.NativeRegistrationToken == token || this.registrationRequest)
return;
var regToken = await this.provider.Register(token);
await this.services
.RunDelegates<IPushDelegate>(
x => x.OnNewToken(token),
x => x.OnNewToken(regToken),
this.logger
)
.ConfigureAwait(false);
Expand Down
10 changes: 0 additions & 10 deletions src/global.json

This file was deleted.

2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "3.3.0-beta.{height}",
"version": "3.3.1-beta.{height}",
"assemblyVersion": {
"precision": "revision"
},
Expand Down

0 comments on commit 659b846

Please sign in to comment.