|
@@ -29,20 +29,21 @@ import Firebase
|
|
|
import WidgetKit
|
|
|
import Queuer
|
|
|
import EasyTipView
|
|
|
+import SwiftUI
|
|
|
|
|
|
@UIApplicationMain
|
|
|
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, NCUserBaseUrl {
|
|
|
|
|
|
- @objc var account: String = ""
|
|
|
- @objc var urlBase: String = ""
|
|
|
- @objc var user: String = ""
|
|
|
- @objc var userId: String = ""
|
|
|
- @objc var password: String = ""
|
|
|
+ var account: String = ""
|
|
|
+ var urlBase: String = ""
|
|
|
+ var user: String = ""
|
|
|
+ var userId: String = ""
|
|
|
+ var password: String = ""
|
|
|
|
|
|
var tipView: EasyTipView?
|
|
|
var backgroundSessionCompletionHandler: (() -> Void)?
|
|
|
var activeLogin: NCLogin?
|
|
|
- var activeLoginWeb: NCLoginWeb?
|
|
|
+ var activeLoginWeb: NCLoginProvider?
|
|
|
var timerErrorNetworking: Timer?
|
|
|
var timerErrorNetworkingDisabled: Bool = false
|
|
|
var taskAutoUploadDate: Date = Date()
|
|
@@ -51,6 +52,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
}
|
|
|
var notificationSettings: UNNotificationSettings?
|
|
|
|
|
|
+ var loginFlowV2Token = ""
|
|
|
+ var loginFlowV2Endpoint = ""
|
|
|
+ var loginFlowV2Login = ""
|
|
|
+
|
|
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
|
|
if isUiTestingEnabled {
|
|
|
deleteAllAccounts()
|
|
@@ -183,8 +188,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
@discussion Schedule a refresh task request to ask that the system launch your app briefly so that you can download data and keep your app's contents up-to-date. The system will fulfill this request intelligently based on system conditions and app usage.
|
|
|
*/
|
|
|
func scheduleAppRefresh() {
|
|
|
-
|
|
|
let request = BGAppRefreshTaskRequest(identifier: NCGlobal.shared.refreshTask)
|
|
|
+
|
|
|
request.earliestBeginDate = Date(timeIntervalSinceNow: 60) // Refresh after 60 seconds.
|
|
|
do {
|
|
|
try BGTaskScheduler.shared.submit(request)
|
|
@@ -197,8 +202,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
@discussion Schedule a processing task request to ask that the system launch your app when conditions are favorable for battery life to handle deferrable, longer-running processing, such as syncing, database maintenance, or similar tasks. The system will attempt to fulfill this request to the best of its ability within the next two days as long as the user has used your app within the past week.
|
|
|
*/
|
|
|
func scheduleAppProcessing() {
|
|
|
-
|
|
|
let request = BGProcessingTaskRequest(identifier: NCGlobal.shared.processingTask)
|
|
|
+
|
|
|
request.earliestBeginDate = Date(timeIntervalSinceNow: 5 * 60) // Refresh after 5 minutes.
|
|
|
request.requiresNetworkConnectivity = false
|
|
|
request.requiresExternalPower = false
|
|
@@ -270,7 +275,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
// MARK: - Background Networking Session
|
|
|
|
|
|
func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
|
|
|
-
|
|
|
NextcloudKit.shared.nkCommonInstance.writeLog("[DEBUG] Start handle Events For Background URLSession: \(identifier)")
|
|
|
WidgetCenter.shared.reloadAllTimelines()
|
|
|
backgroundSessionCompletionHandler = completionHandler
|
|
@@ -283,7 +287,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
}
|
|
|
|
|
|
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
|
|
-
|
|
|
if let pref = UserDefaults(suiteName: NCBrandOptions.shared.capabilitiesGroups),
|
|
|
let data = pref.object(forKey: "NOTIFICATION_DATA") as? [String: AnyObject] {
|
|
|
nextcloudPushNotificationAction(data: data)
|
|
@@ -296,13 +299,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
|
|
NCNetworking.shared.checkPushNotificationServerProxyCertificateUntrusted(viewController: UIApplication.shared.firstWindow?.rootViewController) { error in
|
|
|
if error == .success {
|
|
|
- NCPushNotification.shared().registerForRemoteNotifications(withDeviceToken: deviceToken)
|
|
|
+ NCPushNotification.shared.registerForRemoteNotificationsWithDeviceToken(deviceToken)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
|
|
|
- NCPushNotification.shared().applicationdidReceiveRemoteNotification(userInfo) { result in
|
|
|
+ NCPushNotification.shared.applicationdidReceiveRemoteNotification(userInfo: userInfo) { result in
|
|
|
completionHandler(result)
|
|
|
}
|
|
|
}
|
|
@@ -340,7 +343,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
|
|
|
// MARK: - Login
|
|
|
|
|
|
- @objc func openLogin(selector: Int, openLoginWeb: Bool, windowForRootViewController: UIWindow? = nil) {
|
|
|
+ func openLogin(selector: Int, openLoginWeb: Bool, windowForRootViewController: UIWindow? = nil) {
|
|
|
func showLoginViewController(_ viewController: UIViewController?) {
|
|
|
guard let viewController else { return }
|
|
|
let navigationController = NCLoginNavigationController(rootViewController: viewController)
|
|
@@ -361,45 +364,55 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
}
|
|
|
|
|
|
// [WEBPersonalized] [AppConfig]
|
|
|
- if NCBrandOptions.shared.use_login_web_personalized || NCBrandOptions.shared.use_AppConfig {
|
|
|
- if activeLoginWeb?.view.window == nil {
|
|
|
- activeLoginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb
|
|
|
- activeLoginWeb?.urlBase = NCBrandOptions.shared.loginBaseUrl
|
|
|
- showLoginViewController(activeLoginWeb)
|
|
|
+ if NCBrandOptions.shared.use_AppConfig {
|
|
|
+ if activeLogin?.view.window == nil {
|
|
|
+ urlBase = NCBrandOptions.shared.loginBaseUrl
|
|
|
+ NextcloudKit.shared.getLoginFlowV2(serverUrl: urlBase) { token, endpoint, login, _, error in
|
|
|
+ // Login Flow V2
|
|
|
+ if error == .success, let token, let endpoint, let login {
|
|
|
+ let vc = UIHostingController(rootView: NCLoginPoll(loginFlowV2Token: token, loginFlowV2Endpoint: endpoint, loginFlowV2Login: login, cancelButtonDisabled: NCManageDatabase.shared.getAccounts().isEmptyOrNil))
|
|
|
+ UIApplication.shared.firstWindow?.rootViewController?.present(vc, animated: true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
}
|
|
|
- return
|
|
|
}
|
|
|
|
|
|
// Nextcloud standard login
|
|
|
if selector == NCGlobal.shared.introSignup {
|
|
|
- if activeLoginWeb?.view.window == nil {
|
|
|
- activeLoginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb
|
|
|
+ if activeLogin?.view.window == nil {
|
|
|
+ activeLogin = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLogin") as? NCLogin
|
|
|
if selector == NCGlobal.shared.introSignup {
|
|
|
- activeLoginWeb?.urlBase = NCBrandOptions.shared.linkloginPreferredProviders
|
|
|
+ activeLogin?.urlBase = NCBrandOptions.shared.linkloginPreferredProviders
|
|
|
+ let web = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginProvider") as? NCLoginProvider
|
|
|
+ web?.urlBase = NCBrandOptions.shared.linkloginPreferredProviders
|
|
|
+ showLoginViewController(web)
|
|
|
} else {
|
|
|
- activeLoginWeb?.urlBase = self.urlBase
|
|
|
+ activeLogin?.urlBase = self.urlBase
|
|
|
+ showLoginViewController(activeLogin)
|
|
|
}
|
|
|
- showLoginViewController(activeLoginWeb)
|
|
|
}
|
|
|
|
|
|
} else if NCBrandOptions.shared.disable_intro && NCBrandOptions.shared.disable_request_login_url {
|
|
|
- if activeLoginWeb?.view.window == nil {
|
|
|
- activeLoginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb
|
|
|
- activeLoginWeb?.urlBase = NCBrandOptions.shared.loginBaseUrl
|
|
|
- showLoginViewController(activeLoginWeb)
|
|
|
+ if activeLogin?.view.window == nil {
|
|
|
+ activeLogin = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLogin") as? NCLogin
|
|
|
+ activeLogin?.urlBase = NCBrandOptions.shared.loginBaseUrl
|
|
|
+ showLoginViewController(activeLogin)
|
|
|
}
|
|
|
-
|
|
|
} else if openLoginWeb {
|
|
|
// Used also for reinsert the account (change passwd)
|
|
|
- if activeLoginWeb?.view.window == nil {
|
|
|
- activeLoginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb
|
|
|
- activeLoginWeb?.urlBase = urlBase
|
|
|
- activeLoginWeb?.user = user
|
|
|
- showLoginViewController(activeLoginWeb)
|
|
|
+ if activeLogin?.view.window == nil {
|
|
|
+ activeLogin = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLogin") as? NCLogin
|
|
|
+ activeLogin?.urlBase = urlBase
|
|
|
+ activeLogin?.disableUrlField = true
|
|
|
+ activeLogin?.disableCloseButton = true
|
|
|
+ showLoginViewController(activeLogin)
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
if activeLogin?.view.window == nil {
|
|
|
+ activeLogin?.disableCloseButton = true
|
|
|
+
|
|
|
activeLogin = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLogin") as? NCLogin
|
|
|
showLoginViewController(activeLogin)
|
|
|
}
|
|
@@ -408,7 +421,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
|
|
|
// MARK: - Error Networking
|
|
|
|
|
|
- @objc func startTimerErrorNetworking(scene: UIScene) {
|
|
|
+ func startTimerErrorNetworking(scene: UIScene) {
|
|
|
timerErrorNetworkingDisabled = false
|
|
|
timerErrorNetworking = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(checkErrorNetworking(_:)), userInfo: nil, repeats: true)
|
|
|
}
|
|
@@ -421,13 +434,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
}
|
|
|
|
|
|
func trustCertificateError(host: String) {
|
|
|
-
|
|
|
guard let currentHost = URL(string: self.urlBase)?.host,
|
|
|
let pushNotificationServerProxyHost = URL(string: NCBrandOptions.shared.pushNotificationServerProxy)?.host,
|
|
|
host != pushNotificationServerProxyHost,
|
|
|
host == currentHost
|
|
|
else { return }
|
|
|
-
|
|
|
let certificateHostSavedPath = NCUtilityFileSystem().directoryCertificates + "/" + host + ".der"
|
|
|
var title = NSLocalizedString("_ssl_certificate_changed_", comment: "")
|
|
|
|
|
@@ -457,8 +468,35 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
|
|
|
// MARK: - Account
|
|
|
|
|
|
- @objc func changeAccount(_ account: String, userProfile: NKUserProfile?) {
|
|
|
+ func createAccount(server: String, username: String, password: String, completion: @escaping (_ error: NKError) -> Void) {
|
|
|
+ var urlBase = server
|
|
|
+ if urlBase.last == "/" { urlBase = String(urlBase.dropLast()) }
|
|
|
+ let account: String = "\(username) \(urlBase)"
|
|
|
+ let user = username
|
|
|
+
|
|
|
+ NextcloudKit.shared.setup(account: account, user: user, userId: user, password: password, urlBase: urlBase)
|
|
|
+ NextcloudKit.shared.getUserProfile { _, userProfile, _, error in
|
|
|
+
|
|
|
+ if error == .success, let userProfile {
|
|
|
+
|
|
|
+ NCManageDatabase.shared.deleteAccount(account)
|
|
|
+ NCManageDatabase.shared.addAccount(account, urlBase: urlBase, user: user, userId: userProfile.userId, password: password)
|
|
|
+
|
|
|
+ NCKeychain().setClientCertificate(account: account, p12Data: NCNetworking.shared.p12Data, p12Password: NCNetworking.shared.p12Password)
|
|
|
+
|
|
|
+ self.changeAccount(account, userProfile: userProfile)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ let alertController = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: error.errorDescription, preferredStyle: .alert)
|
|
|
+ alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
|
|
|
+ UIApplication.shared.firstWindow?.rootViewController?.present(alertController, animated: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ completion(error)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ func changeAccount(_ account: String, userProfile: NKUserProfile?) {
|
|
|
NCNetworking.shared.cancelAllQueue()
|
|
|
NCNetworking.shared.cancelDataTask()
|
|
|
NCNetworking.shared.cancelDownloadTasks()
|
|
@@ -489,7 +527,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
NCManageDatabase.shared.setAccountUserProfile(account: account, userProfile: userProfile)
|
|
|
}
|
|
|
|
|
|
- NCPushNotification.shared().pushNotification()
|
|
|
+ NCPushNotification.shared.pushNotification()
|
|
|
|
|
|
NCService().startRequestServicesServer()
|
|
|
|
|
@@ -500,12 +538,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeUser)
|
|
|
}
|
|
|
|
|
|
- @objc func deleteAccount(_ account: String, wipe: Bool) {
|
|
|
-
|
|
|
+ func deleteAccount(_ account: String, wipe: Bool) {
|
|
|
UIApplication.shared.allSceneSessionDestructionExceptFirst()
|
|
|
|
|
|
if let account = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) {
|
|
|
- NCPushNotification.shared().unsubscribingNextcloudServerPushNotification(account.account, urlBase: account.urlBase, user: account.user, withSubscribing: false)
|
|
|
+ NCPushNotification.shared.unsubscribingNextcloudServerPushNotification(account: account.account, urlBase: account.urlBase, user: account.user, withSubscribing: false)
|
|
|
}
|
|
|
|
|
|
NextcloudKit.shared.deleteAppPassword(serverUrl: urlBase, username: userId, password: password) { _, error in
|
|
@@ -550,9 +587,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
|
|
|
func updateShareAccounts() -> Error? {
|
|
|
guard let dirGroupApps = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroupApps) else { return nil }
|
|
|
-
|
|
|
let tableAccount = NCManageDatabase.shared.getAllAccount()
|
|
|
var accounts = [NKShareAccounts.DataAccounts]()
|
|
|
+
|
|
|
for account in tableAccount {
|
|
|
let name = account.alias.isEmpty ? account.displayName : account.alias
|
|
|
let userBaseUrl = account.user + "-" + (URL(string: account.urlBase)?.host ?? "")
|
|
@@ -566,8 +603,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
|
|
|
// MARK: - Reset Application
|
|
|
|
|
|
- @objc func resetApplication() {
|
|
|
-
|
|
|
+ func resetApplication() {
|
|
|
let utilityFileSystem = NCUtilityFileSystem()
|
|
|
|
|
|
NCNetworking.shared.cancelAllTask()
|
|
@@ -587,7 +623,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|
|
// MARK: - Universal Links
|
|
|
|
|
|
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
|
|
|
-
|
|
|
let applicationHandle = NCApplicationHandle()
|
|
|
return applicationHandle.applicationOpenUserActivity(userActivity)
|
|
|
}
|