Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions osu.Framework.iOS/IOSCallObserver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using CallKit;
using Foundation;

namespace osu.Framework.iOS
{
internal class IOSCallObserver : NSObject, ICXCallObserverDelegate
{
private readonly Action incomingCall;
private readonly Action endedCall;

private readonly CXCallController callController;

public IOSCallObserver(Action incomingCall, Action endedCall)
{
this.incomingCall = incomingCall;
this.endedCall = endedCall;

callController = new CXCallController();
callController.CallObserver.SetDelegate(this, null);
}

public void CallChanged(CXCallObserver callObserver, CXCall call)
{
if (!call.HasEnded)
incomingCall();
else
endedCall();
}

protected override void Dispose(bool disposing)
{
callController.Dispose();
base.Dispose(disposing);
}
}
}
10 changes: 9 additions & 1 deletion osu.Framework.iOS/IOSWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
internal class IOSWindow : SDL3MobileWindow
{
private UIWindow? window;
private IOSCallObserver callObserver;

public override Size Size
{
Expand All @@ -32,7 +33,7 @@
}
}

public IOSWindow(GraphicsSurfaceType surfaceType, string appName)

Check warning on line 36 in osu.Framework.iOS/IOSWindow.cs

View workflow job for this annotation

GitHub Actions / Build only (iOS)

Non-nullable field 'callObserver' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 36 in osu.Framework.iOS/IOSWindow.cs

View workflow job for this annotation

GitHub Actions / Build only (iOS)

Non-nullable field 'callObserver' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
: base(surfaceType, appName)
{
}
Expand All @@ -43,8 +44,15 @@

base.Create();

window = Runtime.GetNSObject<UIWindow>(WindowHandle);
window = Runtime.GetNSObject<UIWindow>(WindowHandle)!;
updateSafeArea();

UIScene.Notifications.ObserveWillDeactivate(window.WindowScene!, (_, _) => Focused = false);
UIScene.Notifications.ObserveDidActivate(window.WindowScene!, (_, _) => Focused = true);

callObserver = new IOSCallObserver(
incomingCall: () => Focused = false,
endedCall: () => Focused = true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I end a call when the game is not active (in the background, as I'm probably in the phone app), does it trigger this and make the game Focused?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one, this call observer component is completely detached from whether the app is in foreground or background. This should be addressed in ab7cafa

}

protected override unsafe void RunMainLoop()
Expand Down
Loading