Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support duration and durationInForeground on macOS #848

Merged
merged 1 commit into from
Oct 16, 2020

Conversation

kstenerud
Copy link
Contributor

Goal

Currently, the duration and durationInForeground fields are always zero on macos because we don't record that information. This PR makes macOS start recording this information so that users can see it in their reports.

Design

MacOS does record foreground/background state changes, but uses notification names that are confusing when compared to ios. However, they serve purposes that are close enough to be useful for our needs.

MacOS:

Notification Meaning
NSApplicationDidBecomeActiveNotification Application is in foreground
NSApplicationDidResignActiveNotification Application is in background
NSApplicationWillTerminateNotification Application is shutting down

iOS:

Notification Meaning
UIApplicationDidBecomeActiveNotification Application is active
UIApplicationWillResignActiveNotification Application is interrupted
UIApplicationDidEnterBackgroundNotification Application is in background
UIApplicationWillEnterForegroundNotification Application is in foreground
UIApplicationWillTerminateNotification Application is shutting down

The approach here simply uses the macOS equivalents to trigger the same handler code as for iOS, allowing existing handlers to do the calculations as they have always done.

Changeset

Added compile-time-conditional code to add notification handlers for macOS to handle foreground/background and app termination.

Testing

E2e tests don't exist yet for macos, so I manually triggered events in the macos test apps and verified that durations were recorded on the backend.

Note: macOS uses "active" notifications for the same purpose as ios uses "foreground" notifications. ios-style "active" notifications don't exist on macos.
@kstenerud kstenerud marked this pull request as ready for review October 16, 2020 12:19
@nickdowell nickdowell changed the base branch from master to next October 16, 2020 12:34
@kstenerud kstenerud merged commit 08c7ba9 into next Oct 16, 2020
@kstenerud kstenerud deleted the 3631-macos-duration branch October 16, 2020 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants