Skip to content

Commit

Permalink
feat: CoreApplication EnteredBackground and LeavingBackground events
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Mar 10, 2022
1 parent 712fe9a commit e461b69
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 70 deletions.
102 changes: 64 additions & 38 deletions src/Uno.UWP/ApplicationModel/Core/CoreApplication.cs
Original file line number Diff line number Diff line change
@@ -1,59 +1,85 @@
#pragma warning disable 108 // new keyword hiding
#pragma warning disable 114 // new keyword hiding

using System;
using System.Collections.Generic;
using Uno.Helpers.Theming;

namespace Windows.ApplicationModel.Core
namespace Windows.ApplicationModel.Core;

public partial class CoreApplication
{
public partial class CoreApplication
private static CoreApplicationView _currentView;
private static List<CoreApplicationView> _views;

static CoreApplication()
{
private static CoreApplicationView _currentView;
private static List<CoreApplicationView> _views;
_currentView = new CoreApplicationView();
}

public static event global::System.EventHandler<object> Resuming;
/// <summary>
/// Occurs when an app is resuming.
/// </summary>
public static event EventHandler<object> Resuming;

public static event global::System.EventHandler<global::Windows.ApplicationModel.SuspendingEventArgs> Suspending;
/// <summary>
/// Occurs when the app is suspending.
/// </summary>
public static event EventHandler<SuspendingEventArgs> Suspending;

static CoreApplication()
{
_currentView = new CoreApplicationView();
}
/// <summary>
/// Fired when the app enters the running in the background state.
/// </summary>
public static event EventHandler<EnteredBackgroundEventArgs> EnteredBackground;

/// <summary>
/// Fired just before application UI becomes visible.
/// </summary>
public static event EventHandler<LeavingBackgroundEventArgs> LeavingBackground;

/// <summary>
/// Raises the <see cref="Resuming"/> event
/// </summary>
internal static void RaiseResuming()
=> Resuming?.Invoke(null, null);
/// <summary>
/// Raises the <see cref="Resuming"/> event.
/// </summary>
internal static void OnResuming() => Resuming?.Invoke(null, null);

/// <summary>
/// Raises the <see cref="Suspending"/> event
/// </summary>
internal static void RaiseSuspending(SuspendingEventArgs args)
=> Suspending?.Invoke(null, args);
/// <summary>
/// Raises the <see cref="Suspending"/> event.
/// </summary>
/// <param name="args">Suspending event args.</param>
internal static void OnSuspending(SuspendingEventArgs args) => Suspending?.Invoke(null, args);

public static CoreApplicationView GetCurrentView()
=> _currentView;
/// <summary>
/// Raises the <see cref="EnteredBackground"/> event.
/// </summary>
/// <param name="args">Entered background event args.</param>
internal static void OnEnteredBackground(EnteredBackgroundEventArgs args) => EnteredBackground?.Invoke(null, args);

public static global::Windows.ApplicationModel.Core.CoreApplicationView MainView
=> _currentView;
/// <summary>
/// Raises the <see cref="LeavingBackground"/> event.
/// </summary>
/// <param name="args">Leaving background event args.</param>
internal static void OnLeavingBackground(LeavingBackgroundEventArgs args) => LeavingBackground?.Invoke(null, args);

public static IReadOnlyList<CoreApplicationView> Views
public static CoreApplicationView GetCurrentView() => _currentView;

public static CoreApplicationView MainView => _currentView;

public static IReadOnlyList<CoreApplicationView> Views
{
get
{
get
if (_views == null)
{
if(_views == null)
{
_views = new List<CoreApplicationView> { _currentView };
}

return _views;
_views = new List<CoreApplicationView> { _currentView };
}
}

/// <summary>
/// This property is kept in sync with the Application.RequestedTheme to enable
/// native UI elements in non Uno.UWP to resolve the currently set Application theme.
/// </summary>
internal static SystemTheme RequestedTheme { get; set; }
return _views;
}
}

/// <summary>
/// This property is kept in sync with the Application.RequestedTheme to enable
/// native UI elements in non Uno.UWP to resolve the currently set Application theme.
/// </summary>
internal static SystemTheme RequestedTheme { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,38 +173,8 @@ public static void RunWithActivationFactories( global::Windows.Foundation.IGetAc
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static event global::System.EventHandler<global::Windows.ApplicationModel.EnteredBackgroundEventArgs> EnteredBackground
{
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
add
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.ApplicationModel.Core.CoreApplication", "event EventHandler<EnteredBackgroundEventArgs> CoreApplication.EnteredBackground");
}
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
remove
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.ApplicationModel.Core.CoreApplication", "event EventHandler<EnteredBackgroundEventArgs> CoreApplication.EnteredBackground");
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static event global::System.EventHandler<global::Windows.ApplicationModel.LeavingBackgroundEventArgs> LeavingBackground
{
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
add
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.ApplicationModel.Core.CoreApplication", "event EventHandler<LeavingBackgroundEventArgs> CoreApplication.LeavingBackground");
}
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
remove
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.ApplicationModel.Core.CoreApplication", "event EventHandler<LeavingBackgroundEventArgs> CoreApplication.LeavingBackground");
}
}
#endif
// Skipping already declared event Windows.ApplicationModel.Core.CoreApplication.EnteredBackground
// Skipping already declared event Windows.ApplicationModel.Core.CoreApplication.LeavingBackground
// Skipping already declared event Windows.ApplicationModel.Core.CoreApplication.Resuming
// Skipping already declared event Windows.ApplicationModel.Core.CoreApplication.Suspending
}
Expand Down

0 comments on commit e461b69

Please sign in to comment.