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

Platform support, Application property wrapper and notifications support #98

Merged
merged 10 commits into from
Feb 19, 2024

Conversation

Supereg
Copy link
Member

@Supereg Supereg commented Feb 13, 2024

Platform support, Application property wrapper and notifications support

♻️ Current situation & Problem

Currently, the Core Spezi infrastructure is only developed for iOS. However, we are aiming to support Spezi on all Apple platforms. This step required to reengineer some Spezi infrastructure that was heavily tailored towards the iOS platform (e.g., the LifecycleHandler). This PR deprecates the LifecycleHandler in favor of using SwiftUI native approaches like the ScenePhase environment property or platform-specific publisher-based solutions like willEnterForegroundNotification.
Further we introduce the new @Application property wrapper for Modules and the Standard to access application-specific properties like launchOptions.

Based on the new @Application infrastructure we resolve issues like #80 to provide Modules with Module-specific Logger instances.

To further validate our @Application approach, we added infrastructure around (Remote Push) Notifications. You can use @Application to trigger application actions like registerRemoteNotifications or unregisterRemoteNotifications and additionally adopt protocols like NotificationTokenHandler and NotificationHandler to react to notification actions, control how notifications are delivered in foreground or fetch additional content for background notifications.

⚙️ Release Notes

  • Add support for visionOS, tvOS, watchOS and macOS.
  • Deprecated the LifecycleHandler protocol.
  • Added new @Application property wrapper to access application properties and actions in a a platform-agnostic way.
  • New protocol NotificationTokenHandler and NotificationHandler to easily support notification handling within your apps.

📚 Documentation

There are two new articles Interactions with Application and User Notifications that provide an overview for those new infrastructure elements.

✅ Testing

TBA

📝 Code of Conduct & Contributing Guidelines

By submitting creating this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

@Supereg Supereg linked an issue Feb 18, 2024 that may be closed by this pull request
1 task
@Supereg Supereg changed the title Support visionOS, macOS, tvOS and watchOS Platform support, Application property wrapper and notifications support Feb 18, 2024
Copy link

codecov bot commented Feb 18, 2024

Codecov Report

Attention: 85 lines in your changes are missing coverage. Please review.

Comparison is base (c4bf0e9) 91.34% compared to head (975db64) 84.78%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #98      +/-   ##
==========================================
- Coverage   91.34%   84.78%   -6.55%     
==========================================
  Files          34       40       +6     
  Lines         704      959     +255     
==========================================
+ Hits          643      813     +170     
- Misses         61      146      +85     
Files Coverage Δ
...pezi/Capabilities/Lifecycle/LifecycleHandler.swift 88.89% <100.00%> (ø)
...ications/UnregisterRemoteNotificationsAction.swift 100.00% <100.00%> (ø)
...Capabilities/Observable/ModelPropertyWrapper.swift 53.58% <ø> (ø)
Sources/Spezi/Configuration/Configuration.swift 100.00% <100.00%> (ø)
Sources/Spezi/Spezi/SpeziPropertyWrapper.swift 100.00% <100.00%> (ø)
Sources/Spezi/Spezi/SpeziSceneDelegate.swift 83.34% <100.00%> (ø)
Sources/Spezi/Spezi/View+Spezi.swift 100.00% <100.00%> (ø)
...es/Spezi/Standard/AnyStandardPropertyWrapper.swift 100.00% <100.00%> (ø)
Sources/Spezi/Spezi/Spezi+Preview.swift 96.16% <90.00%> (+17.21%) ⬆️
Sources/Spezi/Spezi/Spezi.swift 96.67% <97.23%> (+1.43%) ⬆️
... and 8 more

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c4bf0e9...975db64. Read the comment docs.

@Supereg Supereg marked this pull request as ready for review February 18, 2024 05:29
Copy link
Member

@PSchmiedmayer PSchmiedmayer left a comment

Choose a reason for hiding this comment

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

Thank you for all the improvements and additions @Supereg; I added some comments here and there but it all looks great and can be merged after all of them are resolved 🚀

I would suggest to tag a minor release after one other small documentation PR that I will hopefully merge later tonight or tomorrow 🚀

CITATION.cff Show resolved Hide resolved
.github/workflows/build-and-test.yml Outdated Show resolved Hide resolved
Sources/Spezi/Spezi.docc/Module/Notifications.md Outdated Show resolved Hide resolved
Sources/Spezi/Spezi/AnySpezi.swift Show resolved Hide resolved
Sources/Spezi/Spezi/Spezi+Logger.swift Show resolved Hide resolved
Sources/Spezi/Spezi/SpeziAppDelegate.swift Outdated Show resolved Hide resolved
@Supereg
Copy link
Member Author

Supereg commented Feb 19, 2024

Thanks for the review @PSchmiedmayer. Will try to add some minimal unit testing where possible and sensible to validate functionality. Should make the codecov checks go green ✅

@PSchmiedmayer
Copy link
Member

Thank you @Supereg; sounds like a great plan!

@Supereg
Copy link
Member Author

Supereg commented Feb 19, 2024

@PSchmiedmayer Added some tests to cover the new notification registration actions and test most of the new delegate functionality. We can't test the UserNotification delegate functionality as those types cannot be constructed by us and the NotificationCenter itself is not available in the testing environment.
This results in a slightly decreased coverage (also like 5 lines that are just comments). I would propose to force merge this PR because of the above-stated.

@PSchmiedmayer PSchmiedmayer merged commit cbc1bb3 into main Feb 19, 2024
12 of 13 checks passed
@PSchmiedmayer PSchmiedmayer deleted the feature/platform-support branch February 19, 2024 21:02
@PSchmiedmayer
Copy link
Member

Sounds great; I merged the PR @Supereg 👍

PSchmiedmayer added a commit that referenced this pull request Aug 26, 2024
# Fix registerRemoteNotifications action would never return

## ♻️ Current situation & Problem
#98 introduced the `registerRemoteNotifications` action. However, the
knowledge source that stores the continuation was never persisted in the
store. Therefore, the continuation was never resumed and allocated
resources forever.
This was fixed with this PR. We originally discussed supporting
cancellation of the registration processed, however I decided against as
it wasn't clear to properly handle cancellation (e.g., automatically
call the unregister action? How to handle the delegate call that might
arrive later. Especially when another call to the action might incur in
the mean time).
This PR changes the behavior when concurrently calling the
registerRemoteNotifications action. Now, the second caller will wait for
the first call to complete instead of throwing a concurrence access
error. This helps to share this resources with, e.g., multiple modules
trying to retrieve an device token.

**To emphasize: `registerRemoteNotifications` works on simulator
devices!**

## ⚙️ Release Notes 
* Fixed an issue where the `registerRemoteNotifications` actions would
never return.


## 📚 Documentation
Slightly updated docs to provide more guidance around requesting
authorization for notifications.


## ✅ Testing
Added a unit test that verifies that the action returns.


## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).

---------

Co-authored-by: Paul Schmiedmayer <[email protected]>
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.

Easily accessible logger infrastructure for Components and Modules
2 participants