From c1db131409487e6dbcd4e986c5793e396e665435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20=C5=81yp?= Date: Tue, 10 Dec 2024 11:17:27 +0100 Subject: [PATCH 1/2] Add InactiveBackground state and handle openURL event in different states --- DuckDuckGo.xcodeproj/project.pbxproj | 4 +++ .../AppLifecycle/AppStateTransitions.swift | 20 +++++++++++--- .../AppStates/InactiveBackground.swift | 26 +++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 DuckDuckGo/AppLifecycle/AppStates/InactiveBackground.swift diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index cb345089c4..ef192fa646 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -964,6 +964,7 @@ CB2A7EEF283D185100885F67 /* RulesCompilationMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB2A7EEE283D185100885F67 /* RulesCompilationMonitor.swift */; }; CB2A7EF128410DF700885F67 /* PixelEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB2A7EF028410DF700885F67 /* PixelEvent.swift */; }; CB2A7EF4285383B300885F67 /* AppLastCompiledRulesStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB2A7EF3285383B300885F67 /* AppLastCompiledRulesStore.swift */; }; + CB3C78912D08484800A7E4ED /* InactiveBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB3C78902D08483F00A7E4ED /* InactiveBackground.swift */; }; CB48D3332B90CE9F00631D8B /* PageRefreshStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB48D3312B90CE9F00631D8B /* PageRefreshStore.swift */; }; CB4FA44E2C78AACE00A16F5A /* SpecialErrorPageUserScript.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB4FA44D2C78AACE00A16F5A /* SpecialErrorPageUserScript.swift */; }; CB5516D0286500290079B175 /* TrackerRadarIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85519124247468580010FDD0 /* TrackerRadarIntegrationTests.swift */; }; @@ -2805,6 +2806,7 @@ CB2A7EF028410DF700885F67 /* PixelEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PixelEvent.swift; sourceTree = ""; }; CB2A7EF3285383B300885F67 /* AppLastCompiledRulesStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppLastCompiledRulesStore.swift; sourceTree = ""; }; CB2C47822AF6D55800AEDCD9 /* nb */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nb; path = nb.lproj/InfoPlist.strings; sourceTree = ""; }; + CB3C78902D08483F00A7E4ED /* InactiveBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InactiveBackground.swift; sourceTree = ""; }; CB4448752AF6D51D001F93F7 /* hr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hr; path = hr.lproj/InfoPlist.strings; sourceTree = ""; }; CB48D3312B90CE9F00631D8B /* PageRefreshStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PageRefreshStore.swift; sourceTree = ""; }; CB4FA44D2C78AACE00A16F5A /* SpecialErrorPageUserScript.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpecialErrorPageUserScript.swift; sourceTree = ""; }; @@ -5516,6 +5518,7 @@ CBAD0EFC2CFE1D48006267B8 /* Active.swift */, CBAD0EFE2CFE1D4E006267B8 /* Inactive.swift */, CBAD0F002CFE1D54006267B8 /* Background.swift */, + CB3C78902D08483F00A7E4ED /* InactiveBackground.swift */, ); path = AppStates; sourceTree = ""; @@ -8134,6 +8137,7 @@ 1DEAADF42BA47B5300E25A97 /* WebTrackingProtectionView.swift in Sources */, F15D43201E706CC500BF2CDC /* AutocompleteViewController.swift in Sources */, BD862E092B30F63E0073E2EE /* VPNMetadataCollector.swift in Sources */, + CB3C78912D08484800A7E4ED /* InactiveBackground.swift in Sources */, D6E83C682B23B6A3006C8AFB /* FontSettings.swift in Sources */, 7BF78E022CA2CC3E0026A1FC /* TipKitAppEventHandling.swift in Sources */, 1DEAADF62BA4809400E25A97 /* CookiePopUpProtectionView.swift in Sources */, diff --git a/DuckDuckGo/AppLifecycle/AppStateTransitions.swift b/DuckDuckGo/AppLifecycle/AppStateTransitions.swift index 8e30596fee..a7c2a11f90 100644 --- a/DuckDuckGo/AppLifecycle/AppStateTransitions.swift +++ b/DuckDuckGo/AppLifecycle/AppStateTransitions.swift @@ -41,7 +41,9 @@ extension Launched { return Active(application: application) case .openURL: return self - case .launching, .suspending, .backgrounding: + case .backgrounding: + return InactiveBackground() + case .launching, .suspending: return handleUnexpectedEvent(event) } } @@ -54,7 +56,9 @@ extension Active { switch event { case .suspending(let application): return Inactive(application: application) - case .launching, .activating, .backgrounding, .openURL: + case .openURL: + return self + case .launching, .activating, .backgrounding: return handleUnexpectedEvent(event) } } @@ -69,7 +73,9 @@ extension Inactive { return Background(application: application) case .activating(let application): return Active(application: application) - case .launching, .suspending, .openURL: + case .openURL: + return self + case .launching, .suspending: return handleUnexpectedEvent(event) } } @@ -91,6 +97,14 @@ extension Background { } +extension InactiveBackground { + + func apply(event: AppEvent) -> any AppState { + handleUnexpectedEvent(event) + } + +} + extension AppEvent { var rawValue: String { diff --git a/DuckDuckGo/AppLifecycle/AppStates/InactiveBackground.swift b/DuckDuckGo/AppLifecycle/AppStates/InactiveBackground.swift new file mode 100644 index 0000000000..e4852a1239 --- /dev/null +++ b/DuckDuckGo/AppLifecycle/AppStates/InactiveBackground.swift @@ -0,0 +1,26 @@ +// +// InactiveBackground.swift +// DuckDuckGo +// +// Copyright © 2024 DuckDuckGo. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +struct InactiveBackground: AppState { + + init() { + + } + +} From f8d4bd7777f35a04827745e19b6c16c7985c0246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20=C5=81yp?= Date: Tue, 10 Dec 2024 12:02:54 +0100 Subject: [PATCH 2/2] Remove unneeded init --- DuckDuckGo/AppLifecycle/AppStates/InactiveBackground.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/DuckDuckGo/AppLifecycle/AppStates/InactiveBackground.swift b/DuckDuckGo/AppLifecycle/AppStates/InactiveBackground.swift index e4852a1239..e9c87477d9 100644 --- a/DuckDuckGo/AppLifecycle/AppStates/InactiveBackground.swift +++ b/DuckDuckGo/AppLifecycle/AppStates/InactiveBackground.swift @@ -19,8 +19,4 @@ struct InactiveBackground: AppState { - init() { - - } - }