Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit 779b5bb

Browse files
authored
Adding app backgrounded result to rule compilation (#3533)
Task/Issue URL: https://app.asana.com/0/1204556816597738/1208691511506504/f Tech Design URL: CC: **Description**: <!-- If at any point it isn't actively being worked on/ready for review/otherwise moving forward strongly consider closing it (or not opening it in the first place). If you decide not to close it, use Draft PR while work is still in progress or use `DO NOT MERGE` label to clarify the PRs state and comment with more information. --> **Steps to test this PR**: 1. 2. <!-- Before submitting a PR, please ensure you have tested the combinations you expect the reviewer to test, then delete configurations you *know* do not need explicit testing. Using a simulator where a physical device is unavailable is acceptable. --> **Definition of Done (Internal Only)**: * [ ] Does this PR satisfy our [Definition of Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)? **Copy Testing**: * [ ] Use of correct apostrophes in new copy, ie `’` rather than `'` **Orientation Testing**: * [ ] Portrait * [ ] Landscape **Device Testing**: * [ ] iPhone SE (1st Gen) * [ ] iPhone 8 * [ ] iPhone X * [ ] iPhone 14 Pro * [ ] iPad **OS Testing**: * [ ] iOS 15 * [ ] iOS 16 * [ ] iOS 17 **Theme Testing**: * [ ] Light theme * [ ] Dark theme --- ###### Internal references: [Software Engineering Expectations](https://app.asana.com/0/59792373528535/199064865822552) [Technical Design Template](https://app.asana.com/0/59792373528535/184709971311943)
1 parent 1a978c2 commit 779b5bb

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Core/PixelEvent.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,7 @@ extension Pixel.Event {
17291729

17301730
case tabClosed = "tab_closed"
17311731
case appQuit = "app_quit"
1732+
case appBackgrounded = "app_backgrounded"
17321733
case success
17331734

17341735
}

DuckDuckGo/RulesCompilationMonitor.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ final class RulesCompilationMonitor {
4141
selector: #selector(applicationWillTerminate(_:)),
4242
name: UIApplication.willTerminateNotification,
4343
object: nil)
44+
45+
NotificationCenter.default.addObserver(self,
46+
selector: #selector(applicationDidEnterBackground),
47+
name: UIApplication.didEnterBackgroundNotification,
48+
object: nil)
4449
}
4550

4651
/// Called when a Tab is going to wait for Content Blocking Rules compilation
@@ -88,6 +93,18 @@ final class RulesCompilationMonitor {
8893

8994
reportWaitTime(CACurrentMediaTime() - waitStart, result: .appQuit)
9095
}
96+
97+
/// If App is going into the background while the rules are still being compiled, report the time so that we
98+
/// do not continue to count the time in background
99+
@objc func applicationDidEnterBackground() {
100+
guard !didReport,
101+
!waiters.isEmpty,
102+
let waitStart = waitStart
103+
else { return }
104+
105+
reportWaitTime(CACurrentMediaTime() - waitStart, result: .appBackgrounded)
106+
}
107+
91108

92109
private func reportWaitTime(_ waitTime: TimeInterval, result: Pixel.Event.CompileRulesResult) {
93110
didReport = true

0 commit comments

Comments
 (0)