Skip to content

Commit 7bcd4d2

Browse files
UI window scene (#4172)
* resolvedWindow Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * wip Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * fix Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> --------- Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com>
1 parent d53569b commit 7bcd4d2

11 files changed

Lines changed: 82 additions & 22 deletions

Nextcloud.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@
789789
F7C55CCA2FB5CE74004A974F /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F7C55CC42FB5CE74004A974F /* Images.xcassets */; };
790790
F7C55CCC2FB5CE74004A974F /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7C55CC72FB5CE74004A974F /* MainInterface.storyboard */; };
791791
F7C630712FFE206100257EEB /* NCMediaMetadataBackgroundProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C630702FFE206100257EEB /* NCMediaMetadataBackgroundProcessor.swift */; };
792+
F7C6307F2FFE4F8000257EEB /* UIWindowScene+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C6307E2FFE4F8000257EEB /* UIWindowScene+Extension.swift */; };
793+
F7C630802FFE4F8000257EEB /* UIWindowScene+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C6307E2FFE4F8000257EEB /* UIWindowScene+Extension.swift */; };
792794
F7C687E92D22BD46004757BC /* NCManageDatabase+RecommendedFiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C687E82D22BD46004757BC /* NCManageDatabase+RecommendedFiles.swift */; };
793795
F7C687EA2D22BDE5004757BC /* NCManageDatabase+RecommendedFiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C687E82D22BD46004757BC /* NCManageDatabase+RecommendedFiles.swift */; };
794796
F7C687EB2D22BDE5004757BC /* NCManageDatabase+RecommendedFiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C687E82D22BD46004757BC /* NCManageDatabase+RecommendedFiles.swift */; };
@@ -1808,6 +1810,7 @@
18081810
F7C55CC42FB5CE74004A974F /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
18091811
F7C55CC62FB5CE74004A974F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = "<group>"; };
18101812
F7C630702FFE206100257EEB /* NCMediaMetadataBackgroundProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCMediaMetadataBackgroundProcessor.swift; sourceTree = "<group>"; };
1813+
F7C6307E2FFE4F8000257EEB /* UIWindowScene+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIWindowScene+Extension.swift"; sourceTree = "<group>"; };
18111814
F7C687E82D22BD46004757BC /* NCManageDatabase+RecommendedFiles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCManageDatabase+RecommendedFiles.swift"; sourceTree = "<group>"; };
18121815
F7C7B488245EBA4100D93E60 /* NCViewerQuickLook.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCViewerQuickLook.swift; sourceTree = "<group>"; };
18131816
F7C9555221F0C4CA0024296E /* NCActivity.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCActivity.storyboard; sourceTree = "<group>"; };
@@ -3029,6 +3032,7 @@
30293032
AFCE353227E4ED1900FEA6C2 /* UIToolbar+Extension.swift */,
30303033
F7E41315294A19B300839300 /* UIView+Extension.swift */,
30313034
F77BB745289984CA0090FC19 /* UIViewController+Extension.swift */,
3035+
F7C6307E2FFE4F8000257EEB /* UIWindowScene+Extension.swift */,
30323036
F7E8A390295DC5E0006CB2D0 /* View+Extension.swift */,
30333037
);
30343038
path = Extensions;
@@ -4523,6 +4527,7 @@
45234527
F78295311F962EFA00A572F5 /* NCEndToEndEncryption.m in Sources */,
45244528
F7C30DFE291BD0B80017149B /* NCNetworkingE2EEDelete.swift in Sources */,
45254529
F7D4BF2C2CA2E8D800A5E746 /* TOPasscodeKeypadView.m in Sources */,
4530+
F7C630802FFE4F8000257EEB /* UIWindowScene+Extension.swift in Sources */,
45264531
F7D4BF2D2CA2E8D800A5E746 /* TOPasscodeSettingsKeypadView.m in Sources */,
45274532
F7D4BF2E2CA2E8D800A5E746 /* TOPasscodeFixedInputView.m in Sources */,
45284533
F7D61EA92EBF1694007F865B /* NCManageDatabase+TableCapabilities.swift in Sources */,
@@ -5087,6 +5092,7 @@
50875092
F77C3F5B2D9BF8CD00F3C471 /* UITabBar+Extension.swift in Sources */,
50885093
F7D7A76E2DCDD437003D2007 /* NCManageDatabase+AutoUpload.swift in Sources */,
50895094
F7F563042E15762B00631A11 /* MigrationMultiDomains.swift in Sources */,
5095+
F7C6307F2FFE4F8000257EEB /* UIWindowScene+Extension.swift in Sources */,
50905096
F75CA1472962F13700B01130 /* NCHUDView.swift in Sources */,
50915097
F77BB748289985270090FC19 /* UITabBarController+Extension.swift in Sources */,
50925098
F7DA0F672F66AA0D0033020C /* ShowBanner.swift in Sources */,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-FileCopyrightText: Nextcloud GmbH
2+
// SPDX-FileCopyrightText: 2026 Marino Faggiana
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
import UIKit
6+
7+
extension UIWindowScene {
8+
@MainActor
9+
var resolvedWindow: UIWindow? {
10+
if let window = resolvedWindow(in: [self]) {
11+
return window
12+
}
13+
14+
#if !EXTENSION
15+
let scenes = UIApplication.shared.connectedScenes
16+
.compactMap { $0 as? UIWindowScene }
17+
18+
if let window = resolvedWindow(
19+
in: scenes.filter { $0.activationState == .foregroundActive }
20+
) {
21+
return window
22+
}
23+
24+
if let window = resolvedWindow(
25+
in: scenes.filter { $0.activationState == .foregroundInactive }
26+
) {
27+
return window
28+
}
29+
30+
return resolvedWindow(in: scenes)
31+
#else
32+
return nil
33+
#endif
34+
}
35+
36+
@MainActor
37+
private func resolvedWindow(in scenes: [UIWindowScene]) -> UIWindow? {
38+
let windows = scenes.flatMap { $0.windows }
39+
40+
return windows.first(where: \.isKeyWindow) ??
41+
windows.first(where: { !$0.isHidden && $0.alpha > 0 }) ??
42+
windows.first(where: { !$0.isHidden }) ??
43+
windows.first
44+
}
45+
}

iOSClient/GUI/Lucid Banner/AlertActionBannerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func showAlertActionBanner(lucidBanner: LucidBanner?,
1313
onConfirm: (() -> Void)? = nil) {
1414
guard let lucidBanner,
1515
let windowScene,
16-
let window = windowScene.windows.first(where: \.isKeyWindow) else {
16+
let window = windowScene.resolvedWindow else {
1717
return
1818
}
1919
let horizontalLayout = horizontalLayoutBanner(bounds: window.bounds,

iOSClient/GUI/Lucid Banner/ErrorBannerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func showErrorBanner(windowScene: UIWindowScene?,
2424
errorCode: Int? = nil,
2525
afError: AFError? = nil) async {
2626
guard let windowScene,
27-
let window = windowScene.windows.first(where: \.isKeyWindow) else {
27+
let window = windowScene.resolvedWindow else {
2828
return
2929
}
3030

iOSClient/GUI/Lucid Banner/HudBannerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func showHudBanner(windowScene: UIWindowScene?,
1212
stage: LucidBanner.Stage? = nil,
1313
onButtonTap: (() -> Void)? = nil) -> (banner: LucidBanner?, token: Int?) {
1414
guard let windowScene,
15-
let window = windowScene.windows.first(where: \.isKeyWindow) else {
15+
let window = windowScene.resolvedWindow else {
1616
return (nil, nil)
1717
}
1818
let localizedTitle = title.map { NSLocalizedString($0, comment: "") }

iOSClient/GUI/Lucid Banner/HudIndeterminateBannerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func showHudIndeterminateBanner(windowScene: UIWindowScene?,
1212
stage: LucidBanner.Stage? = nil,
1313
onButtonTap: (() -> Void)? = nil) -> (banner: LucidBanner?, token: Int?) {
1414
guard let windowScene,
15-
let window = windowScene.windows.first(where: \.isKeyWindow) else {
15+
let window = windowScene.resolvedWindow else {
1616
return (nil, nil)
1717
}
1818
let localizedTitle = title.map { NSLocalizedString($0, comment: "") }

iOSClient/GUI/Lucid Banner/InfoBannerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func showInfoBanner(windowScene: UIWindowScene?,
1414
footnote: String? = nil,
1515
errorCode: Int? = nil) async {
1616
guard let windowScene,
17-
let window = windowScene.windows.first(where: \.isKeyWindow) else {
17+
let window = windowScene.resolvedWindow else {
1818
return
1919
}
2020

iOSClient/GUI/Lucid Banner/ShowBanner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func showBanner(windowScene: UIWindowScene?,
2727
policy: LucidBanner.ShowPolicy = .replace,
2828
errorCode: Int? = nil) async -> (banner: LucidBanner?, token: Int?) {
2929
guard let windowScene,
30-
let window = windowScene.windows.first(where: \.isKeyWindow) else {
30+
let window = windowScene.resolvedWindow else {
3131
return(nil, nil)
3232
}
3333

iOSClient/GUI/Lucid Banner/UploadBannerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func showUploadBanner(windowScene: UIWindowScene?,
1111
allowMinimizeOnTap: Bool,
1212
onButtonTap: (() -> Void)? = nil) -> (banner: LucidBanner?, token: Int?) {
1313
guard let windowScene,
14-
let window = windowScene.windows.first(where: \.isKeyWindow) else {
14+
let window = windowScene.resolvedWindow else {
1515
return (nil, nil)
1616
}
1717
let horizontalLayout = horizontalLayoutBanner(bounds: window.bounds,

iOSClient/GUI/Lucid Banner/WarningBannerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func showWarningBanner(windowScene: UIWindowScene?,
1616
imageAnimation: LucidBanner.LucidBannerAnimationStyle,
1717
errorCode: Int? = nil) async {
1818
guard let windowScene,
19-
let window = windowScene.windows.first(where: \.isKeyWindow) else {
19+
let window = windowScene.resolvedWindow else {
2020
return
2121
}
2222

0 commit comments

Comments
 (0)