From 4a2dd44f7c7fd6eb7b7eceddceae80c8fd327226 Mon Sep 17 00:00:00 2001 From: TSI-amrutwaghmare <96108296+TSI-amrutwaghmare@users.noreply.github.com> Date: Fri, 13 Oct 2023 15:15:47 +0530 Subject: [PATCH 1/4] NMC 2575 - App update using remote config --- iOSClient/AppUpdate/AppUpdater.swift | 91 ++++++++++++++++++++++++++++ iOSClient/SceneDelegate.swift | 39 +++++++++++- 2 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 iOSClient/AppUpdate/AppUpdater.swift diff --git a/iOSClient/AppUpdate/AppUpdater.swift b/iOSClient/AppUpdate/AppUpdater.swift new file mode 100644 index 0000000000..9fab18b4ff --- /dev/null +++ b/iOSClient/AppUpdate/AppUpdater.swift @@ -0,0 +1,91 @@ +// +// AppUpdater.swift +// Nextcloud +// +// Created by Amrut Waghmare on 09/10/23. +// Copyright © 2023 Marino Faggiana. All rights reserved. +// + +import Foundation +import FirebaseRemoteConfig + +struct AppUpdaterKey { + static let lastUpdateCheckDate : String = "lastUpdateCheckDate" +} + +class AppUpdater { + func checkForUpdate() { + checkUpdate{ (version, isForceupdate) in + DispatchQueue.main.async { + if let version = version, let isForceupdate = isForceupdate { + if (isForceupdate) { + self.showUpdateAlert(version: version, isForceUpdate: isForceupdate) + } else { + if self.checkLastUpdate() { + self.showUpdateAlert(version: version, isForceUpdate: isForceupdate) + } + } + } + } + } + } + + func showUpdateAlert(version: String, isForceUpdate: Bool){ + guard let appDelegate = UIApplication.shared.delegate as? AppDelegate, let viewControlller = appDelegate.window?.rootViewController else { return } + let descriptionMsg = String(format: NSLocalizedString("update_description", comment: ""), version) + let alert = UIAlertController(title: NSLocalizedString("update_available", comment: ""), message: descriptionMsg, preferredStyle: .alert) + let updateAction = UIAlertAction(title: NSLocalizedString("update", comment: ""), style: .default, handler: { action in + guard let url = URL(string: NCBrandOptions.shared.appStoreUrl) else { return } + UIApplication.shared.open(url) + }) + alert.addAction(updateAction) + if !isForceUpdate { + alert.addAction(UIAlertAction(title: NSLocalizedString("not_now", comment: ""), style: .default, handler: { action in + self.saveAppUpdateCheckDate() + })) + } + alert.preferredAction = updateAction + viewControlller.present(alert, animated: true, completion: {}) + } + + func checkLastUpdate() -> Bool { + if let lastUpdateCheckDate = UserDefaults.standard.object(forKey: AppUpdaterKey.lastUpdateCheckDate) as? Date { + return daysBetweenDate(from: lastUpdateCheckDate) > 7 + } else { + return true + } + } + + func checkUpdate(completion: @escaping (String?, Bool?) -> Void) { + let remoteConfig = RemoteConfig.remoteConfig() + remoteConfig.fetch(withExpirationDuration: 1) { (status, error) in + if status == .success { + remoteConfig.activate { value, error in + // Remote config values fetched successfully + let iOSVersion = remoteConfig["ios_app_version"].stringValue ?? "default_value" + let isForcheUpdate = remoteConfig["ios_force_update"].boolValue + if let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { + if iOSVersion != currentVersion { + // There is an update available + completion(iOSVersion,isForcheUpdate) + } else { + completion(nil, nil) + } + } + } + } else { + // Handle error + print("Error fetching remote config: \(error?.localizedDescription ?? "Unknown error")") + completion(nil, nil) + } + } + } + + func saveAppUpdateCheckDate() { + UserDefaults.standard.setValue(Date(), forKey: AppUpdaterKey.lastUpdateCheckDate) + } + + func daysBetweenDate(from date: Date) -> Int { + return Calendar.current.dateComponents([.day], from: date, to: Date()).day ?? 0 + } +} diff --git a/iOSClient/SceneDelegate.swift b/iOSClient/SceneDelegate.swift index cd3903f02a..05f80bae3a 100644 --- a/iOSClient/SceneDelegate.swift +++ b/iOSClient/SceneDelegate.swift @@ -110,7 +110,11 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { NCPreferences().removeAll() if let bundleID = Bundle.main.bundleIdentifier { + let lastUpdateCheckDate = UserDefaults.standard.object(forKey: AppUpdaterKey.lastUpdateCheckDate) UserDefaults.standard.removePersistentDomain(forName: bundleID) + if lastUpdateCheckDate != nil { + UserDefaults.standard.setValue(lastUpdateCheckDate, forKey: AppUpdaterKey.lastUpdateCheckDate) + } } if NCBrandOptions.shared.disable_intro { @@ -206,13 +210,46 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { let session = SceneManager.shared.getSession(scene: scene) let controller = SceneManager.shared.getController(scene: scene) - activateSceneForAccount(scene, account: session.account, controller: controller) + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + Task { + if let tableAccount = await self.database.getTableAccountAsync(account: session.account) { + let num = await NCAutoUpload.shared.initAutoUpload(tblAccount: tableAccount) + nkLog(start: "Auto upload with \(num) photo") + } + } + } + AppUpdater().checkForUpdate() + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterRichdocumentGrabFocus) } func sceneDidBecomeActive(_ scene: UIScene) { + let session = SceneManager.shared.getSession(scene: scene) + let controller = SceneManager.shared.getController(scene: scene) + NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Scene did become active") + hidePrivacyProtectionWindow() + + DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { + NCService().startRequestServicesServer(account: session.account, controller: controller) + } + + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + Task { + await NCNetworking.shared.verifyZombie() + } + } + + NotificationCenter.default.postOnMainThread(name: global.notificationCenterRichdocumentGrabFocus) + } +// func sceneDidBecomeActive(_ scene: UIScene) { +// let session = SceneManager.shared.getSession(scene: scene) +// guard !session.account.isEmpty else { return } +// +// hidePrivacyProtectionWindow() +// } + func sceneWillResignActive(_ scene: UIScene) { nkLog(debug: "Scene will resign active") From d0e5907340b0558146c2032c481ab6015ce17fe8 Mon Sep 17 00:00:00 2001 From: harshada-15-tsys Date: Tue, 8 Apr 2025 14:08:35 +0530 Subject: [PATCH 2/4] NMC 2575 - App update changes --- Nextcloud.xcodeproj/project.pbxproj | 16 ++++++++++++++++ iOSClient/SceneDelegate.swift | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 8dd4c5545f..9d02bf5a76 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -85,6 +85,10 @@ AFCE353527E4ED5900FEA6C2 /* DateFormatter+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */; }; AFCE353727E4ED7B00FEA6C2 /* NCShareCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */; }; AFCE353927E5DE0500FEA6C2 /* Shareable.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* Shareable.swift */; }; + AFCE353927E5DE0500FEA6C2 /* NCShare+Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */; }; + B5D45E732DA5172900773929 /* AppUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5D45E712DA5172900773929 /* AppUpdater.swift */; }; + C04E2F232A17BB4D001BAD85 /* FilesIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04E2F222A17BB4D001BAD85 /* FilesIntegrationTests.swift */; }; + D575039F27146F93008DC9DC /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extension.swift */; }; D5B6AA7827200C7200D49C24 /* NCActivityTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */; }; F310B1EF2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = F310B1EE2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift */; }; F321DA8A2B71205A00DDA0E6 /* NCTrashSelectTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = F321DA892B71205A00DDA0E6 /* NCTrashSelectTabBar.swift */; }; @@ -1221,6 +1225,8 @@ AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+Extension.swift"; sourceTree = ""; }; AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareCells.swift; sourceTree = ""; }; AFCE353827E5DE0400FEA6C2 /* Shareable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shareable.swift; sourceTree = ""; }; + AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCShare+Helper.swift"; sourceTree = ""; }; + B5D45E712DA5172900773929 /* AppUpdater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppUpdater.swift; sourceTree = ""; }; C0046CDA2A17B98400D87C9D /* NextcloudUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; C04E2F202A17BB4D001BAD85 /* NextcloudIntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudIntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityTableViewCell.swift; sourceTree = ""; }; @@ -2062,6 +2068,14 @@ path = Advanced; sourceTree = ""; }; + B5D45E722DA5172900773929 /* AppUpdate */ = { + isa = PBXGroup; + children = ( + B5D45E712DA5172900773929 /* AppUpdater.swift */, + ); + path = AppUpdate; + sourceTree = ""; + }; C0046CDB2A17B98400D87C9D /* NextcloudUITests */ = { isa = PBXGroup; children = ( @@ -3226,6 +3240,7 @@ isa = PBXGroup; children = ( AA517BB42D66149900F8D37C /* .tx */, + B5D45E722DA5172900773929 /* AppUpdate */, F702F2CC25EE5B4F008F8E80 /* AppDelegate.swift */, F794E13E2BBC0F70003693D7 /* SceneDelegate.swift */, F7CF067A2E0FF38F0063AD04 /* NCAppStateManager.swift */, @@ -4504,6 +4519,7 @@ F70898692EDDB51700EF85BD /* NCSelectOpen+SelectDelegate.swift in Sources */, F7D4BF412CA2E8D800A5E746 /* TOPasscodeViewControllerAnimatedTransitioning.m in Sources */, F7D4BF422CA2E8D800A5E746 /* TOPasscodeSettingsViewController.m in Sources */, + B5D45E732DA5172900773929 /* AppUpdater.swift in Sources */, F7D4BF432CA2E8D800A5E746 /* TOPasscodeCircleImage.m in Sources */, F78026102E9CFA3700B63436 /* NCTransfersView.swift in Sources */, F7D4BF442CA2E8D800A5E746 /* TOPasscodeView.m in Sources */, diff --git a/iOSClient/SceneDelegate.swift b/iOSClient/SceneDelegate.swift index 05f80bae3a..5694f64bbe 100644 --- a/iOSClient/SceneDelegate.swift +++ b/iOSClient/SceneDelegate.swift @@ -219,6 +219,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } } AppUpdater().checkForUpdate() + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterRichdocumentGrabFocus) } @@ -227,6 +228,20 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { let controller = SceneManager.shared.getController(scene: scene) NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Scene did become active") + let oldVersion = UserDefaults.standard.value(forKey: NCSettingsBundleHelper.SettingsBundleKeys.BuildVersionKey) as? String + AppUpdater().checkForUpdate() + AnalyticsHelper.shared.trackAppVersion(oldVersion: oldVersion) + if let userAccount = NCManageDatabase.shared.getActiveTableAccount() { + AnalyticsHelper.shared.trackUsedStorageData(quotaUsed: userAccount.quotaUsed) + } + + NCSettingsBundleHelper.setVersionAndBuildNumber() + NCSettingsBundleHelper.checkAndExecuteSettings(delay: 0.5) + +// if !NCAskAuthorization().isRequesting { +// NCPasscode.shared.hidePrivacyProtectionWindow() +// } + hidePrivacyProtectionWindow() DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { From 89f5c9f76196e0a9752c867261fb283a17776c62 Mon Sep 17 00:00:00 2001 From: harshada-15-tsys Date: Tue, 30 Sep 2025 21:09:12 +0530 Subject: [PATCH 3/4] NMC 2575 - App update changes --- iOSClient/AppUpdate/AppUpdater.swift | 19 ++++++++++++++++--- iOSClient/SceneDelegate.swift | 4 ++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/iOSClient/AppUpdate/AppUpdater.swift b/iOSClient/AppUpdate/AppUpdater.swift index 9fab18b4ff..15dd5f6991 100644 --- a/iOSClient/AppUpdate/AppUpdater.swift +++ b/iOSClient/AppUpdate/AppUpdater.swift @@ -62,16 +62,29 @@ class AppUpdater { if status == .success { remoteConfig.activate { value, error in // Remote config values fetched successfully - let iOSVersion = remoteConfig["ios_app_version"].stringValue ?? "default_value" + let iOSVersionString = remoteConfig["ios_app_version"].stringValue ?? "default_value" let isForcheUpdate = remoteConfig["ios_force_update"].boolValue - if let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { + if let currentVersionString = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String, + let currentVersion = Int(currentVersionString.replacingOccurrences(of: ".", with: "")), + let iOSVersion = Int(iOSVersionString.replacingOccurrences(of: ".", with: "")) { +// if let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { if iOSVersion != currentVersion { // There is an update available - completion(iOSVersion,isForcheUpdate) + completion(iOSVersionString,isForcheUpdate) } else { completion(nil, nil) } } +// let iOSVersion = remoteConfig["ios_app_version"].stringValue ?? "default_value" +// let isForcheUpdate = remoteConfig["ios_force_update"].boolValue +// if let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { +// if iOSVersion != currentVersion { +// // There is an update available +// completion(iOSVersion,isForcheUpdate) +// } else { +// completion(nil, nil) +// } +// } } } else { // Handle error diff --git a/iOSClient/SceneDelegate.swift b/iOSClient/SceneDelegate.swift index 5694f64bbe..b1830a51e4 100644 --- a/iOSClient/SceneDelegate.swift +++ b/iOSClient/SceneDelegate.swift @@ -504,6 +504,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } private func showPrivacyProtectionWindow() { + guard privacyProtectionWindow == nil else { + privacyProtectionWindow?.isHidden = false + return + } guard let windowScene = self.window?.windowScene else { return } From 17d0ae0ffc15e8a93de17c9a9353999385603a83 Mon Sep 17 00:00:00 2001 From: harshada-15-tsys Date: Mon, 15 Dec 2025 13:13:45 +0530 Subject: [PATCH 4/4] NMC 2575 - App update changes --- iOSClient/AppUpdate/AppUpdater.swift | 25 +++------ iOSClient/SceneDelegate.swift | 76 +++++++++------------------- 2 files changed, 31 insertions(+), 70 deletions(-) diff --git a/iOSClient/AppUpdate/AppUpdater.swift b/iOSClient/AppUpdate/AppUpdater.swift index 15dd5f6991..5f1b0e54eb 100644 --- a/iOSClient/AppUpdate/AppUpdater.swift +++ b/iOSClient/AppUpdate/AppUpdater.swift @@ -29,8 +29,8 @@ class AppUpdater { } } } - - func showUpdateAlert(version: String, isForceUpdate: Bool){ + + func showUpdateAlert(version: String, isForceUpdate: Bool) { guard let appDelegate = UIApplication.shared.delegate as? AppDelegate, let viewControlller = appDelegate.window?.rootViewController else { return } let descriptionMsg = String(format: NSLocalizedString("update_description", comment: ""), version) let alert = UIAlertController(title: NSLocalizedString("update_available", comment: ""), message: descriptionMsg, preferredStyle: .alert) @@ -47,7 +47,7 @@ class AppUpdater { alert.preferredAction = updateAction viewControlller.present(alert, animated: true, completion: {}) } - + func checkLastUpdate() -> Bool { if let lastUpdateCheckDate = UserDefaults.standard.object(forKey: AppUpdaterKey.lastUpdateCheckDate) as? Date { return daysBetweenDate(from: lastUpdateCheckDate) > 7 @@ -56,7 +56,7 @@ class AppUpdater { } } - func checkUpdate(completion: @escaping (String?, Bool?) -> Void) { + func checkUpdate(completion: @escaping (String?, Bool?) -> Void) { let remoteConfig = RemoteConfig.remoteConfig() remoteConfig.fetch(withExpirationDuration: 1) { (status, error) in if status == .success { @@ -70,21 +70,12 @@ class AppUpdater { // if let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { if iOSVersion != currentVersion { // There is an update available - completion(iOSVersionString,isForcheUpdate) + completion(iOSVersionString, isForcheUpdate) } else { completion(nil, nil) } } -// let iOSVersion = remoteConfig["ios_app_version"].stringValue ?? "default_value" -// let isForcheUpdate = remoteConfig["ios_force_update"].boolValue -// if let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { -// if iOSVersion != currentVersion { -// // There is an update available -// completion(iOSVersion,isForcheUpdate) -// } else { -// completion(nil, nil) -// } -// } + } } else { // Handle error @@ -93,11 +84,11 @@ class AppUpdater { } } } - + func saveAppUpdateCheckDate() { UserDefaults.standard.setValue(Date(), forKey: AppUpdaterKey.lastUpdateCheckDate) } - + func daysBetweenDate(from date: Date) -> Int { return Calendar.current.dateComponents([.day], from: date, to: Date()).day ?? 0 } diff --git a/iOSClient/SceneDelegate.swift b/iOSClient/SceneDelegate.swift index b1830a51e4..15ffee150f 100644 --- a/iOSClient/SceneDelegate.swift +++ b/iOSClient/SceneDelegate.swift @@ -110,11 +110,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { NCPreferences().removeAll() if let bundleID = Bundle.main.bundleIdentifier { - let lastUpdateCheckDate = UserDefaults.standard.object(forKey: AppUpdaterKey.lastUpdateCheckDate) UserDefaults.standard.removePersistentDomain(forName: bundleID) - if lastUpdateCheckDate != nil { - UserDefaults.standard.setValue(lastUpdateCheckDate, forKey: AppUpdaterKey.lastUpdateCheckDate) - } } if NCBrandOptions.shared.disable_intro { @@ -124,7 +120,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { window?.makeKeyAndVisible() } } else { - if let navigationController = UIStoryboard(name: "NCIntro", bundle: nil).instantiateInitialViewController() as? UINavigationController { + if let viewController = UIStoryboard(name: "NCIntro", bundle: nil).instantiateInitialViewController() as? NCIntroViewController { + let navigationController = UINavigationController(rootViewController: viewController) window?.rootViewController = navigationController window?.makeKeyAndVisible() } @@ -201,7 +198,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { func sceneWillEnterForeground(_ scene: UIScene) { hidePrivacyProtectionWindow() - + if let rootHostingController = scene.rootHostingController() { if rootHostingController.anyRootView is Maintenance { return @@ -209,7 +206,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } let session = SceneManager.shared.getSession(scene: scene) let controller = SceneManager.shared.getController(scene: scene) - + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { Task { if let tableAccount = await self.database.getTableAccountAsync(account: session.account) { @@ -219,52 +216,25 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } } AppUpdater().checkForUpdate() - + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterRichdocumentGrabFocus) + activateSceneForAccount(scene, account: session.account, controller: controller) } func sceneDidBecomeActive(_ scene: UIScene) { - let session = SceneManager.shared.getSession(scene: scene) - let controller = SceneManager.shared.getController(scene: scene) - NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Scene did become active") - - let oldVersion = UserDefaults.standard.value(forKey: NCSettingsBundleHelper.SettingsBundleKeys.BuildVersionKey) as? String - AppUpdater().checkForUpdate() - AnalyticsHelper.shared.trackAppVersion(oldVersion: oldVersion) - if let userAccount = NCManageDatabase.shared.getActiveTableAccount() { - AnalyticsHelper.shared.trackUsedStorageData(quotaUsed: userAccount.quotaUsed) - } - - NCSettingsBundleHelper.setVersionAndBuildNumber() - NCSettingsBundleHelper.checkAndExecuteSettings(delay: 0.5) - -// if !NCAskAuthorization().isRequesting { -// NCPasscode.shared.hidePrivacyProtectionWindow() -// } - hidePrivacyProtectionWindow() - - DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { - NCService().startRequestServicesServer(account: session.account, controller: controller) - } - - DispatchQueue.main.asyncAfter(deadline: .now() + 2) { - Task { - await NCNetworking.shared.verifyZombie() - } - } - - NotificationCenter.default.postOnMainThread(name: global.notificationCenterRichdocumentGrabFocus) - +// if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene { +// for window in windowScene.windows { +// let imageViews = window.allImageViews() +// // Do something with the imageViews +// for imageView in imageViews { +// print("Found image view: \(imageView)") +// imageView.tintColor = UITraitCollection.current.userInterfaceStyle == .dark ? .white : .black +// } +// } +// } } -// func sceneDidBecomeActive(_ scene: UIScene) { -// let session = SceneManager.shared.getSession(scene: scene) -// guard !session.account.isEmpty else { return } -// -// hidePrivacyProtectionWindow() -// } - func sceneWillResignActive(_ scene: UIScene) { nkLog(debug: "Scene will resign active") @@ -273,6 +243,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { return } + WidgetCenter.shared.reloadAllTimelines() + if NCPreferences().privacyScreenEnabled { if SwiftEntryKit.isCurrentlyDisplaying { SwiftEntryKit.dismiss { @@ -288,6 +260,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { let app = UIApplication.shared var bgID: UIBackgroundTaskIdentifier = .invalid let isBackgroundRefreshStatus = (UIApplication.shared.backgroundRefreshStatus == .available) + // Must be outside the Task otherwise isSuspendingDatabaseOperation suspends it let session = SceneManager.shared.getSession(scene: scene) guard let tblAccount = NCManageDatabase.shared.getTableAccount(predicate: NSPredicate(format: "account == %@", session.account)) else { return @@ -504,10 +477,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } private func showPrivacyProtectionWindow() { - guard privacyProtectionWindow == nil else { - privacyProtectionWindow?.isHidden = false - return - } guard let windowScene = self.window?.windowScene else { return } @@ -544,9 +513,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { Task { try? await Task.sleep(nanoseconds: 1_000_000_000) - - let num = await NCAutoUpload.shared.initAutoUpload() - nkLog(start: "Auto upload with \(num) photo") + if let tblAccount = await NCManageDatabase.shared.getTableAccountAsync(account: account) { + let num = await NCAutoUpload.shared.initAutoUpload(tblAccount: tblAccount) + nkLog(start: "Auto upload with \(num) photo") + } try? await Task.sleep(nanoseconds: 1_500_000_000) await NCService().startRequestServicesServer(account: account, controller: controller)