Skip to content

feat(v3): add cross-platform application lifecycle events (Resumed/Paused/Backgrounded/Foregrounded) - #5886

Open
mortenolsrud wants to merge 1 commit into
wailsapp:masterfrom
mortenolsrud:feat/common-lifecycle-events
Open

feat(v3): add cross-platform application lifecycle events (Resumed/Paused/Backgrounded/Foregrounded)#5886
mortenolsrud wants to merge 1 commit into
wailsapp:masterfrom
mortenolsrud:feat/common-lifecycle-events

Conversation

@mortenolsrud

@mortenolsrud mortenolsrud commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Description

Mobile and macOS apps need to react to lifecycle transitions (backgrounding, foregrounding, pausing, resuming), but Wails v3 only exposes these as platform-specific events (events.Android.ActivityPaused, events.IOS.ApplicationDidEnterBackground, events.Mac.ApplicationDidResignActive). Writing cross-platform code requires build-tagged listeners for each platform.

This adds four new Common events that map the platform-specific lifecycle transitions to a unified cross-platform contract:

app.Event.OnApplicationEvent(events.Common.ApplicationPaused, func(e *application.ApplicationEvent) {
    // save state, pause expensive ops — works on Android, iOS, and macOS
})
Common Event Description Android source iOS source macOS source
ApplicationResumed App became active/interactive ActivityResumed DidBecomeActive DidBecomeActive
ApplicationPaused App losing focus, going inactive ActivityPaused WillResignActive DidResignActive
ApplicationBackgrounded App fully moved to background ActivityStopped DidEnterBackground DidHide
ApplicationForegrounded App returning from background ActivityStarted WillEnterForeground WillUnhide

Windows and Linux do not have equivalent app-level lifecycle events and are left unmapped (they already map SystemWillSleep/SystemDidWake for machine-level suspend/resume).

The implementation uses the existing commonApplicationEventMap pattern that already maps ApplicationStarted, ThemeChanged, BatteryChanged, etc. — no new plumbing, just 4 new map entries per platform.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Desktop build (GTK3 + GTK4) — compiles clean.
  • Android cross-compile (android/arm64 via NDK) — compiles clean.
  • Events package tests — pass.
  • Host-side command tests — pass.
  • The event forwarding mechanism (setupCommonEvents + commonApplicationEventMap) is the same proven pattern used by the existing Common events (ApplicationStarted, ThemeChanged, BatteryChanged, etc.) since the mobile stack was introduced.

iOS compile-verified via the fork's macOS CI runner (same workflow used for #5808).

  • Windows
  • macOS
  • Linux

Linux: Ubuntu 24.04.4 LTS (build host).

Test Configuration

  • Wails CLI: v3.0.0-beta.3
  • Go: go1.26.5
  • OS: Ubuntu 24.04.4 LTS, amd64
  • Android NDK: 26.3.11579264

Checklist:

  • (v2 only) I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Notes:

  • Documentation: Updated the events reference guide (docs/src/content/docs/guides/events-reference.mdx) with all 4 new events, descriptions, and "when to use" guidance.
  • Tests: The event forwarding is exercised by the existing setupCommonEvents test path. Adding a device-level integration test would require an emulator (planned in a separate test-infrastructure PR). The mechanism is identical to the already-proven ApplicationStarted/ThemeChanged forwarding.

Summary by CodeRabbit

  • New Features

    • Added common application lifecycle events for resumed, paused, backgrounded, and foregrounded states.
    • Added consistent lifecycle event reporting across Android, iOS, and macOS.
    • Added event names and JavaScript mappings for lifecycle handling.
  • Documentation

    • Updated the events reference with platform behavior and usage guidance.
    • Clarified that Windows and Linux do not provide equivalent application-level transitions.

@github-actions github-actions Bot added Documentation Improvements or additions to documentation MacOS v3-alpha labels Aug 4, 2026
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0c02bf14-ba8a-4027-b733-fe4490de7474

📥 Commits

Reviewing files that changed from the base of the PR and between d9942eb and 2b3c159.

📒 Files selected for processing (7)
  • docs/src/content/docs/guides/events-reference.mdx
  • v3/pkg/application/events_common_android.go
  • v3/pkg/application/events_common_darwin.go
  • v3/pkg/application/events_common_ios.go
  • v3/pkg/events/events.go
  • v3/pkg/events/events.txt
  • v3/pkg/events/known_events.go
🚧 Files skipped from review as they are similar to previous changes (7)
  • v3/pkg/events/known_events.go
  • v3/pkg/application/events_common_ios.go
  • v3/pkg/events/events.txt
  • v3/pkg/application/events_common_darwin.go
  • docs/src/content/docs/guides/events-reference.mdx
  • v3/pkg/events/events.go
  • v3/pkg/application/events_common_android.go

Walkthrough

The change adds four common application lifecycle events. Android, Darwin, and iOS lifecycle callbacks map to these events. Event identifiers, JavaScript names, registry entries, and documentation are updated.

Changes

Application lifecycle events

Layer / File(s) Summary
Common event contract
v3/pkg/events/events.go, v3/pkg/events/events.txt, v3/pkg/events/known_events.go
Defines resumed, paused, backgrounded, and foregrounded events with IDs 1292–1295, JavaScript mappings, and registry entries.
Platform lifecycle mappings
v3/pkg/application/events_common_*.go
Maps Android, Darwin, and iOS lifecycle events to the common application events.
Event reference documentation
docs/src/content/docs/guides/events-reference.mdx
Documents the four common events and their platform-specific usage.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PlatformLifecycle
  participant EventMappings
  participant CommonEvents
  participant JavaScript
  PlatformLifecycle->>EventMappings: emit platform lifecycle callback
  EventMappings->>CommonEvents: map callback to common event
  CommonEvents->>JavaScript: expose common:event name
Loading

Poem

A rabbit hops through states anew,
Resumed and paused, then out of view.
Backgrounded, foregrounded, names align,
Across each platform, events now shine.
Four little signals bound and clear.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the addition of cross-platform application lifecycle events.
Description check ✅ Passed The description explains the feature, platform mappings, documentation changes, testing, configuration, and checklist status in sufficient detail.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/src/content/docs/guides/events-reference.mdx`:
- Around line 426-429: Update the documentation entries for
common:ApplicationResumed, common:ApplicationPaused,
common:ApplicationBackgrounded, and common:ApplicationForegrounded to state that
they are supported only on Android, iOS, and macOS, matching the mappings in
events_common_android.go, events_common_ios.go, and events_common_darwin.go; do
not describe them as available on all platforms unless Windows and Linux
forwarding mappings are also added.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c31cfc6f-09ac-4b85-8214-bbb0bf8e6561

📥 Commits

Reviewing files that changed from the base of the PR and between 2014eb6 and d9942eb.

📒 Files selected for processing (7)
  • docs/src/content/docs/guides/events-reference.mdx
  • v3/pkg/application/events_common_android.go
  • v3/pkg/application/events_common_darwin.go
  • v3/pkg/application/events_common_ios.go
  • v3/pkg/events/events.go
  • v3/pkg/events/events.txt
  • v3/pkg/events/known_events.go

Comment thread docs/src/content/docs/guides/events-reference.mdx Outdated
Add four new Common events that map platform-specific lifecycle
transitions to a unified cross-platform contract:

  - ApplicationResumed     (app became active/interactive)
  - ApplicationPaused      (app losing focus, going inactive)
  - ApplicationBackgrounded (app fully moved to background)
  - ApplicationForegrounded (app returning from background)

Platform mappings:
  Android: ActivityResumed/Paused/Stopped/Started → Common
  iOS:     DidBecomeActive/WillResignActive/DidEnterBackground/WillEnterForeground → Common
  macOS:   DidBecomeActive/DidResignActive/DidHide/WillUnhide → Common

The same Go listener now works on all three platforms:

  app.Event.OnApplicationEvent(events.Common.ApplicationPaused, func(e *application.ApplicationEvent) {
      // save state, pause expensive ops — works on Android, iOS, and macOS
  })

Windows and Linux do not have equivalent app-level lifecycle events and
are left unmapped (they already map SystemWillSleep/SystemDidWake for
machine-level suspend/resume).

Documentation updated in the events reference guide.
@mortenolsrud
mortenolsrud force-pushed the feat/common-lifecycle-events branch from d9942eb to 2b3c159 Compare August 4, 2026 08:20
@mortenolsrud

Copy link
Copy Markdown
Contributor Author

Good catch. Fixed in the force-push: the lifecycle events are now in their own subsection titled "Application Lifecycle Events (Android, iOS, macOS)" with an explicit note that Windows and Linux don't emit them (and a pointer to SystemWillSleep/SystemDidWake as the equivalent for those platforms).

The "These events work on all platforms" table header now covers only the events that actually work everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation MacOS v3-alpha

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants