Skip to content

Commit

Permalink
chore(backend): add lifecycle app type for ios (#1767)
Browse files Browse the repository at this point in the history
- add new `terminated` type for `lifecycle_app.type` for iOS
- document `terminated` type for `lifecycle_app.type`

fixes #1754

---------

Signed-off-by: detj <[email protected]>
  • Loading branch information
detj authored Jan 22, 2025
1 parent 12f1809 commit 8b32ae3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
36 changes: 28 additions & 8 deletions backend/api/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ const LifecycleSwiftUITypeOnDisappear = "on_disappear"
const LifecycleAppTypeBackground = "background"
const LifecycleAppTypeForeground = "foreground"

// LifecycleAppTypeTerminated is used only for iOS
const LifecycleAppTypeTerminated = "terminated"

// NominalColdLaunchThreshold defines the upper bound
// of a nominal cold launch duration.
const NominalColdLaunchThreshold = 30 * time.Second
Expand Down Expand Up @@ -188,13 +191,6 @@ var ValidLifecycleFragmentTypes = []string{
LifecycleFragmentTypeDetached,
}

// ValidLifecycleAppTypes defines allowed
// `lifecycle_app.type` values.
var ValidLifecycleAppTypes = []string{
LifecycleAppTypeBackground,
LifecycleAppTypeForeground,
}

// ValidLifecycleViewControllerTypes defines allowed
// `lifecycle_view_controller.type` values.
var ValidLifecycleViewControllerTypes = []string{
Expand Down Expand Up @@ -237,6 +233,27 @@ var ValidNetworkGenerations = []string{
NetworkGenerationUnknown,
}

// getValidLifecycleAppTypes defines valid
// `lifecycle_app.type` values according
// to the platform.
func getValidLifecycleAppTypes(p string) (types []string) {
switch p {
case platform.Android:
types = []string{
LifecycleAppTypeBackground,
LifecycleAppTypeForeground,
}
case platform.IOS:
types = []string{
LifecycleAppTypeBackground,
LifecycleAppTypeForeground,
LifecycleAppTypeTerminated,
}
}

return types
}

// makeTitle appends the message to the type
// if message is present.
func makeTitle(t, m string) (typeMessage string) {
Expand Down Expand Up @@ -980,7 +997,10 @@ func (e *EventField) Validate() error {
if len(e.LifecycleApp.Type) > maxLifecycleAppTypeChars {
return fmt.Errorf(`%q exceeds maximum allowed characters of (%d)`, `lifecycle_app.type`, maxLifecycleAppTypeChars)
}
if !slices.Contains(ValidLifecycleAppTypes, e.LifecycleApp.Type) {

validTypes := getValidLifecycleAppTypes(e.Attribute.Platform)

if !slices.Contains(validTypes, e.LifecycleApp.Type) {
return fmt.Errorf(`%q contains invalid lifecycle app type`, `lifecycle_app.type`)
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/api/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,11 @@ Use the `lifecycle_swift_ui` type for iOS SwiftUI view lifecycle events.

#### **`lifecycle_app`**

Use the `lifecycle_app` type for Android's app lifecycle events.
Use the `lifecycle_app` type for app's lifecycle events.

| Field | Type | Optional | Comment |
| ------ | ------ | -------- | ------------------------------------------------------------- |
| `type` | string | No | One of the following:<br />- `background`<br />- `foreground`<br />- `terminated` |
| `type` | string | No | One of the following:<br />- `background`<br />- `foreground`<br />- `terminated`. `terminated` option is only supported on iOS. |

#### **`cold_launch`**

Expand Down

0 comments on commit 8b32ae3

Please sign in to comment.