Skip to content

Commit

Permalink
Merge branch 'master' into v3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Sep 20, 2023
2 parents 900ba17 + 12d1073 commit e967615
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ body:
options:
- label: I have supplied a reproducible sample that is NOT FROM THE SHINY SAMPLES!
required: true
- label: I am a Sponsor OR I am using the LATEST stable/beta version from nuget (v3.0 stable - ALPHAS are not taking issues - Sponsors: I'll still take v2 issues for you')
- label: I am a Sponsor OR I am using the LATEST stable/beta version from nuget (v3.0 stable - ALPHAS are not taking issues - Sponsors can still send v2 issues)
required: true
- label: I am Sponsor OR My GitHub account is 30+ days old
required: true
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ jobs:
fetch-depth: 0

- name: Setup .NET 7.0
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.307'
dotnet-version: '7.0.x'
# dotnet-quality: 'preview'

- name: Add .NET Workloads
run: dotnet workload install maui-ios maui-android maui-maccatalyst maui-windows
Expand Down
3 changes: 3 additions & 0 deletions build/Tasks/Library/BuildTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public override void Run(BuildContext context)
//context.MSBuild("Shiny.sln", x => x
context.MSBuild("Build.slnf", x => x
.WithRestore()
//.SetMSBuildPlatform(MSBuildPlatform.Automatic)
//.UseToolVersion(MSBuildToolVersion.VS2022)
//.UseToolVersion("17.7")
.WithTarget("Clean")
.WithTarget("Build")
.WithProperty("PublicRelease", "true")
Expand Down
17 changes: 0 additions & 17 deletions src/Shiny.BluetoothLE/IBleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,6 @@ public interface IBleManager
IObservable<ScanResult> Scan(ScanConfig? scanConfig = null);
}


public record ScanConfig(
/// <summary>
/// Filters scan to peripherals that advertise specified service UUIDs
/// iOS - you must set this to initiate a background scan
/// </summary>
params string[] ServiceUuids
);


public record ScanResult(
IPeripheral Peripheral,
int Rssi,
IAdvertisementData AdvertisementData
);


//IObservable<IPeripheral> WhenPeripheralStatusChanged();
//IObservable<AccessState> WhenStatusChanged()
// this really needs to be handled by a delegate because that's where the status changes, user should still call RequestAccess or trap when it fails starting a scan operation
33 changes: 0 additions & 33 deletions src/Shiny.BluetoothLE/IPeripheral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,6 @@
namespace Shiny.BluetoothLE;


public record BleServiceInfo(string Uuid);

public record BleCharacteristicInfo(
BleServiceInfo Service,
string Uuid,
bool IsNotifying,
CharacteristicProperties Properties
);

public record BleDescriptorInfo(
BleCharacteristicInfo Characteristic,
string Uuid
);

public record BleCharacteristicResult(
BleCharacteristicInfo Characteristic,
BleCharacteristicEvent Event,
byte[]? Data
);

public enum BleCharacteristicEvent
{
Read,
Write,
WriteWithoutResponse,
Notification
}

public record BleDescriptorResult(
BleDescriptorInfo Descriptor,
byte[]? Data
);

public interface IPeripheral
{
string Uuid { get; }
Expand Down
56 changes: 56 additions & 0 deletions src/Shiny.BluetoothLE/Models.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace Shiny.BluetoothLE;


public record ScanConfig(
/// <summary>
/// Filters scan to peripherals that advertise specified service UUIDs
/// iOS - you must set this to initiate a background scan
/// </summary>
params string[] ServiceUuids
);


public record ScanResult(
IPeripheral Peripheral,
int Rssi,
IAdvertisementData AdvertisementData
);


public record BleServiceInfo(string Uuid);


public record BleCharacteristicInfo(
BleServiceInfo Service,
string Uuid,
bool IsNotifying,
CharacteristicProperties Properties
);


public record BleDescriptorInfo(
BleCharacteristicInfo Characteristic,
string Uuid
);


public record BleCharacteristicResult(
BleCharacteristicInfo Characteristic,
BleCharacteristicEvent Event,
byte[]? Data
);


public enum BleCharacteristicEvent
{
Read,
Write,
WriteWithoutResponse,
Notification
}


public record BleDescriptorResult(
BleDescriptorInfo Descriptor,
byte[]? Data
);
6 changes: 0 additions & 6 deletions src/Shiny.Core/Shiny.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<RootNamespace>Shiny</RootNamespace>
</PropertyGroup>

<ItemGroup>
<None Remove="Reflection\" />
</ItemGroup>
<ItemGroup>
<None Include="Shiny.Core.targets" Pack="True" PackagePath="buildTransitive" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
Expand All @@ -27,8 +24,5 @@
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Common" Version="2.5.1.1" />
</ItemGroup>

<ItemGroup>
<Folder Include="Reflection\" />
</ItemGroup>
<Import Project="Sdk.targets" Sdk="MSBuild.Sdk.Extras" Version="$(MSBuildSdkExtrasVersion)" Condition="'$(UseMSBuild)' == 'true'" />
</Project>
50 changes: 16 additions & 34 deletions src/Shiny.Core/ShinySubject.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using Microsoft.Extensions.Logging;

Expand All @@ -15,56 +17,36 @@ public class ShinySubject<T> : ISubject<T>
public ILogger? Logger { get; set; }


public void OnCompleted()
{
foreach (var observer in this.observers)
{
try
{
observer.OnCompleted();
}
catch (Exception ex)
{
this.Logger?.LogWarning(ex, "ShinySubject OnCompleted error on observer");
}
}
}
public void OnCompleted() => this.Pub(x => x.OnCompleted(), "OnCompleted error on observer");
public void OnError(Exception error) => this.Pub(x => x.OnError(error), "OnError error on observer");
public void OnNext(T value) => this.Pub(x => x.OnNext(value), "OnNext error on observer");


public void OnError(Exception error)
protected virtual void Pub(Action<IObserver<T>> action, string errorDescription)
{
foreach (var observer in this.observers)
{
try
{
observer.OnError(error);
}
catch (Exception ex)
{
this.Logger?.LogWarning(ex, "ShinySubject OnError error on observer");
}
}
}

List<IObserver<T>> copy;
lock (this.observers)
copy = this.observers.ToList();

public void OnNext(T value)
{
foreach (var observer in this.observers)
foreach (var observer in copy)
{
try
{
observer.OnNext(value);
action(observer);
}
catch (Exception ex)
{
this.Logger?.LogWarning(ex, "ShinySubject OnNext error on observer");
this.Logger?.LogWarning(ex, errorDescription);
}
}
}


public IDisposable Subscribe(IObserver<T> observer)
{
this.observers.Add(observer);
lock (this.observers)
this.observers.Add(observer);

return Disposable.Create(() => this.observers.Remove(observer));
}
}
6 changes: 0 additions & 6 deletions src/Shiny.Hosting.Maui/Shiny.Hosting.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Shiny.Core\Shiny.Core.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Firebase.CloudMessaging;
using Firebase.Core;
Expand All @@ -13,16 +12,13 @@ namespace Shiny.Push;

public class FirebasePushProvider : NotifyPropertyChanged, IPushProvider, IPushTagSupport
{
readonly ILogger logger;
readonly FirebaseConfiguration config;


public FirebasePushProvider(
ILogger<FirebasePushProvider> logger,
FirebaseConfiguration config
)
{
this.logger = logger;
this.config = config;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
<Description>Shiny Push Integration - Google Firebase Cloud Messaging</Description>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<CreatePackage>false</CreatePackage>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<CreatePackage>false</CreatePackage>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Shiny.Push\Shiny.Push.csproj" />
</ItemGroup>
Expand Down
17 changes: 15 additions & 2 deletions src/Shiny.Push/Platforms/Android/PushManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,21 @@ public async Task<PushAccessState> RequestAccess(CancellationToken cancelToken =
return PushAccessState.Denied;
}

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

if (this.RegistrationToken != null && this.RegistrationToken != regToken)
{
// TODO: do we want to fire this here, the user may call this and store from the result anyhow
await this.services
.RunDelegates<IPushDelegate>(
x => x.OnTokenRefreshed(regToken),
this.logger
)
.ConfigureAwait(false);
}
this.NativeToken = nativeToken;
this.RegistrationToken = regToken;

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

0 comments on commit e967615

Please sign in to comment.