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 Oct 27, 2023
2 parents e967615 + a719bcd commit f9ea2ac
Show file tree
Hide file tree
Showing 23 changed files with 311 additions and 215 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

Expand All @@ -52,7 +52,7 @@ jobs:
run: dotnet run --project build/ShinyBuild.csproj

- name: Publish Artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: nugets
path: ${{ github.workspace }}/artifacts
Expand Down
2 changes: 1 addition & 1 deletion samples/Sample.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7133;http://localhost:5282;https://192.168.1.5:7133",
"applicationUrl": "https://localhost:7133;http://localhost:5282",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
Expand Down
2 changes: 1 addition & 1 deletion samples/Sample.Api/Sample.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PropertyGroup Condition=" '$(RunConfiguration)' == 'https' " />
<PropertyGroup Condition=" '$(RunConfiguration)' == 'http' " />
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.10" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.12" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions samples/Sample.Maui/Dev/HttpTransfersPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
Grid.Column="1" />

<CollectionView ItemsSource="{Binding Transfers}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Grid.Row="1"
Grid.ColumnSpan="2">

Expand Down
5 changes: 1 addition & 4 deletions samples/Sample.Maui/Dev/HttpTransfersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ await this.manager.Queue(new HttpTransferRequest(
}



[Reactive] public int TransferCount { get; private set; }
public INotifyReadOnlyCollection<HttpTransferObject> Transfers { get; private set; } = new ObservableList<HttpTransferObject>();
public INotifyReadOnlyCollection<HttpTransferObject> Transfers => this.monitor.Transfers;
public ICommand AddDownload { get; }
public ICommand AddUpload { get; }
public ICommand CancelAll { get; }
Expand All @@ -99,8 +98,6 @@ await this.monitor.Start(
false,
RxApp.MainThreadScheduler
);

this.Transfers = this.monitor.Transfers;
}
catch (Exception ex)
{
Expand Down
3 changes: 2 additions & 1 deletion samples/Sample.Maui/HttpTransfers/PendingPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
</ContentPage.ToolbarItems>

<ContentPage.Content>
<Grid>
<Grid HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
Expand Down
9 changes: 6 additions & 3 deletions samples/Sample.Maui/Sample.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Nullable>enable</Nullable>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>

<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
<ApplicationTitle>Shiny</ApplicationTitle>
<ApplicationId>org.shiny.samples</ApplicationId>
<ApplicationIdGuid>3E54A75D-D399-4272-8326-54510C872263</ApplicationIdGuid>
Expand All @@ -32,6 +32,9 @@
-->
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
</PropertyGroup>
<ItemGroup>
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
Expand All @@ -46,11 +49,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="ReactiveUI.Fody" Version="19.4.1" />
<PackageReference Include="ReactiveUI.Fody" Version="19.5.1" />
<PackageReference Include="Prism.DryIoc.Maui" Version="8.1.273-pre" />
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.141-beta" />
<PackageReference Include="CommunityToolkit.Maui.Markup" Version="3.2.0" />
<PackageReference Include="CommunityToolkit.Maui.Markup" Version="3.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
19 changes: 0 additions & 19 deletions src/Shiny.Core/Platforms/Android/AndroidExtensions.cs

This file was deleted.

27 changes: 8 additions & 19 deletions src/Shiny.Core/Platforms/Android/AndroidPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,25 @@ public async Task<AccessState> RequestForegroundServicePermissions()
public const string ActionServiceStop = "ACTION_STOP_FOREGROUND_SERVICE";
public const string IntentActionStopWithTask = "StopWithTask";

public void StartService(Type serviceType, bool stopWithTask = false)
public void StartService(Type serviceType, bool stopWithTask = true)
{
var intent = new Intent(this.AppContext, serviceType);
intent.SetAction(ActionServiceStart);
intent.PutExtra(IntentActionStopWithTask, stopWithTask);

if (OperatingSystemShim.IsAndroidVersionAtLeast(31))
{
intent.SetAction(ActionServiceStart);
intent.PutExtra(IntentActionStopWithTask, stopWithTask);
this.AppContext.StartForegroundService(intent);
}
else
{
this.AppContext.StartService(intent);
}
}


public void StopService(Type serviceType)
{
//if (!this.IsShinyForegroundService(serviceType))
//{
this.AppContext.StopService(new Intent(this.AppContext, serviceType));
//}
//else
//{
// // HACK: this re-runs the intent to stop the service since OnTaskRemoved isn't running
// var intent = new Intent(this.AppContext, serviceType);
// intent.SetAction(ActionServiceStop);
// this.AppContext.StartService(intent);
//}
}
var intent = new Intent(this.AppContext, serviceType);
intent.SetAction(ActionServiceStop);
this.AppContext.StopService(intent);
}


public AccessState GetCurrentAccessState(string androidPermission)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using AndroidX.Lifecycle;
using Java.Interop;
Expand All @@ -23,7 +24,8 @@ public class AndroidLifecycleExecutor : Java.Lang.Object, IShinyStartupTask, ILi


public AndroidLifecycleExecutor(IntPtr handle, JniHandleOwnership ownership) : base(handle, ownership) { }
public AndroidLifecycleExecutor(

public AndroidLifecycleExecutor(
ILogger<AndroidLifecycleExecutor> logger,
AndroidPlatform platform,
IEnumerable<IAndroidLifecycle.IApplicationLifecycle> appHandlers,
Expand Down Expand Up @@ -76,6 +78,9 @@ public void Start()
// Console.WriteLine("LIFECYCLE: OnDestory");
//}

public void OnActivityOnCreate(Activity activity, Bundle? savedInstanceState)
=> this.Execute(this.onCreateHandlers, x => x.ActivityOnCreate(activity, savedInstanceState));

public void OnRequestPermissionsResult(Activity activity, int requestCode, string[] permissions, Permission[] grantResults)
=> this.Execute(this.permissionHandlers, x => x.Handle(activity, requestCode, permissions, grantResults));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;

namespace Shiny.Hosting;

Expand All @@ -15,7 +16,7 @@ public interface IApplicationLifecycle

public interface IOnActivityOnCreate
{

void ActivityOnCreate(Activity activity, Bundle? savedInstanceState);
}

public interface IOnActivityRequestPermissionsResult
Expand Down
45 changes: 34 additions & 11 deletions src/Shiny.Core/Platforms/Android/ShinyAndroidForegroundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ protected int NotificationId

public override StartCommandResult OnStartCommand(Intent? intent, StartCommandFlags flags, int startId)
{
var action = intent?.Action ?? AndroidPlatform.ActionServiceStart;
this.Logger.LogDebug($"Foreground Service OnStartCommand - Action: {action} - Notification ID: {this.NotificationId}");

switch (action)
this.Logger.LogDebug($"Foreground Service OnStartCommand - Action: {intent?.Action} - Notification ID: {this.NotificationId}");
switch (intent?.Action)
{
case AndroidPlatform.ActionServiceStart:
this.StopWithTask = intent?.GetBooleanExtra(AndroidPlatform.IntentActionStopWithTask, false) ?? false;
Expand All @@ -65,6 +63,10 @@ public override StartCommandResult OnStartCommand(Intent? intent, StartCommandFl
case AndroidPlatform.ActionServiceStop:
this.Stop();
break;

default:
this.Logger.LogDebug($"Invalid Intent Action - {intent?.Action}");
break;
}

return StartCommandResult.Sticky;
Expand All @@ -90,32 +92,52 @@ protected virtual void Start(Intent? intent)

this.Logger.LogDebug("Starting Foreground Notification: " + this.NotificationId);
var notification = this.Builder.Build();
notification.Flags |= NotificationFlags.ForegroundService;

this.NotificationManager!.Notify(this.NotificationId, notification);

if (OperatingSystemShim.IsAndroidVersionAtLeast(31))
{
this.StartForeground(this.NotificationId, notification);
this.Logger.LogDebug("Started Foreground Service");
}
else
{
this.NotificationManager!.Notify(this.NotificationId!, notification);
this.Logger.LogDebug("Started Classic Foreground Service");
}

this.OnStart(intent);
}


protected void Stop()
{
this.Logger.LogDebug("Calling for foreground service stop");
this.Logger.LogDebug($"Calling for foreground service stop. Notification ID: {this.NotificationId}");
this.DestroyWith?.Dispose();
this.DestroyWith = null;

//if (OperatingSystemShim.IsAndroidVersionAtLeast(33))
//{
// this.Logger.LogDebug("API level 33+ foreground service shutdown");
// this.StopForeground(StopForegroundFlags.Detach);
// this.StopSelf();
//}
//else
if (OperatingSystemShim.IsAndroidVersionAtLeast(31))
{
this.Logger.LogDebug("API level requires foreground detach");
this.StopForeground(StopForegroundFlags.Detach);
this.Logger.LogDebug("API level 31+ foreground service shutdown");
this.StopForeground(true);
this.StopSelf();
}
else
{
this.Logger.LogDebug("API level classic foreground service shutdown");
this.StopSelf();
this.NotificationManager!.Cancel(this.NotificationId);
}
this.Logger.LogDebug($"Foreground service calling for notification ID: {this.NotificationId} to cancel");
this.NotificationManager?.Cancel(this.NotificationId);
this.StopSelf();

this.Logger.LogDebug("Foreground service stopped successfully");
this.OnStop();
}

Expand All @@ -140,7 +162,8 @@ protected virtual NotificationCompat.Builder CreateNotificationBuilder()
var build = new NotificationCompat.Builder(this.Platform.AppContext, NotificationChannelId)
.SetSmallIcon(this.Platform.GetNotificationIconResource())
.SetForegroundServiceBehavior((int)NotificationForegroundService.Immediate)
.SetOngoing(true)
.SetOngoing(false) //.SetOngoing(true)
.SetOnlyAlertOnce(true)
.SetTicker("...")
.SetContentTitle("Shiny Service")
.SetContentText("Shiny service is continuing to process data in the background");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if PLATFORM
using System.Runtime.InteropServices;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Shiny.Hosting;
Expand Down
1 change: 1 addition & 0 deletions src/Shiny.Hosting.Maui/ShinyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static MauiAppBuilder UseShiny(this MauiAppBuilder builder)
#if ANDROID
events.AddAndroid(android => android
// Shiny will supply app foreground/background events
.OnCreate((activity, savedInstanceState) => Host.Lifecycle.OnActivityOnCreate(activity, savedInstanceState))
.OnRequestPermissionsResult((activity, requestCode, permissions, grantResults) => Host.Lifecycle.OnRequestPermissionsResult(activity, requestCode, permissions, grantResults))
.OnActivityResult((activity, requestCode, result, intent) => Host.Lifecycle.OnActivityResult(activity, requestCode, result, intent))
.OnNewIntent((activity, intent) => Host.Lifecycle.OnNewIntent(activity, intent))
Expand Down
14 changes: 11 additions & 3 deletions src/Shiny.Hosting.Native/Platforms/Android/ShinyAndroidActivity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using AndroidX.AppCompat.App;
using Shiny.Hosting;
Expand All @@ -10,10 +11,10 @@ namespace Shiny;

public abstract class ShinyAndroidActivity : AppCompatActivity
{
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent? data)
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnActivityResult(requestCode, resultCode, data);
Host.Lifecycle.OnActivityResult(this, requestCode, resultCode, data);
base.OnCreate(savedInstanceState);
Host.Lifecycle.OnActivityOnCreate(this, savedInstanceState);
}


Expand All @@ -24,6 +25,13 @@ protected override void OnNewIntent(Intent? intent)
}


protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent? data)
{
base.OnActivityResult(requestCode, resultCode, data);
Host.Lifecycle.OnActivityResult(this, requestCode, resultCode, data);
}


public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
Expand Down
6 changes: 3 additions & 3 deletions src/Shiny.Jobs/Infrastructure/JobLifecycleTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public override void Start()
{
if (job.JobType == null)
{
this.logger.LogWarning($"Job Type for '{job.Identifier}' cannot be found and has been removed");
this.logger.LogInformation($"Job Type for '{job.Identifier}' cannot be found and has been removed");
this.jobManager.Cancel(job.Identifier);
}
else if (job.IsSystemJob)
{
this.logger.LogWarning($"Clearing System Job '{job.Identifier}' - If being registered, job manager will bring it back in a moment");
this.logger.LogInformation($"Clearing System Job '{job.Identifier}' - If being registered, job manager will bring it back in a moment");
this.jobManager.Cancel(job.Identifier);
}
}
Expand All @@ -88,7 +88,7 @@ public override void Start()
// we won't crash out, we'll just log a full error
this.jobManager.Register(jobNew);

this.logger.LogWarning($"Registered System Job '{job.Identifier}' of Type '{job.JobType}'");
this.logger.LogInformation($"Registered System Job '{job.Identifier}' of Type '{job.JobType}'");
}
}
catch (Exception ex)
Expand Down
Loading

0 comments on commit f9ea2ac

Please sign in to comment.