Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
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 */; };
B5C980182DACD51C0041B146 /* NCMediaCommandView.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5C980172DACD51C0041B146 /* NCMediaCommandView.xib */; };
B5C9801A2DACD56C0041B146 /* NCMedia+Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C980192DACD56C0041B146 /* NCMedia+Menu.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 */; };
Expand Down Expand Up @@ -1221,6 +1226,9 @@
AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+Extension.swift"; sourceTree = "<group>"; };
AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareCells.swift; sourceTree = "<group>"; };
AFCE353827E5DE0400FEA6C2 /* Shareable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shareable.swift; sourceTree = "<group>"; };
AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCShare+Helper.swift"; sourceTree = "<group>"; };
B5C980172DACD51C0041B146 /* NCMediaCommandView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCMediaCommandView.xib; sourceTree = "<group>"; };
B5C980192DACD56C0041B146 /* NCMedia+Menu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCMedia+Menu.swift"; sourceTree = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -1986,6 +1994,7 @@
F376A3732E5CC5FF0067EE25 /* ContextMenuActions.swift */,
F77A697C250A0FBC00FF1708 /* NCCollectionViewCommon+Menu.swift */,
F78C6FDD296D677300C952C3 /* NCContextMenu.swift */,
B5C980192DACD56C0041B146 /* NCMedia+Menu.swift */,
3704EB2923D5A58400455C5B /* NCMenu.storyboard */,
371B5A2D23D0B04500FAFAE9 /* NCMenu.swift */,
AF935066276B84E700BD078F /* NCMenu+FloatingPanel.swift */,
Expand Down Expand Up @@ -3125,6 +3134,7 @@
F7EC9CB921185F2000F1C5CE /* Media */ = {
isa = PBXGroup;
children = (
B5C980172DACD51C0041B146 /* NCMediaCommandView.xib */,
F720B5B72507B9A5008C94E5 /* Cell */,
F7501C302212E57400FB1415 /* NCMedia.storyboard */,
F7501C312212E57400FB1415 /* NCMedia.swift */,
Expand Down Expand Up @@ -3946,6 +3956,7 @@
F74C0437253F1CDC009762AB /* NCShares.storyboard in Resources */,
F7F4F10C27ECDBDB008676F9 /* Inconsolata-Regular.ttf in Resources */,
F7B8B83025681C3400967775 /* GoogleService-Info.plist in Resources */,
B5C980182DACD51C0041B146 /* NCMediaCommandView.xib in Resources */,
F7381EE5218218C9000B1560 /* NCOffline.storyboard in Resources */,
F768822D2C0DD1E7001CF441 /* Acknowledgements.rtf in Resources */,
F76D3CF32428B94E005DFA87 /* NCViewerPDFSearchCell.xib in Resources */,
Expand Down Expand Up @@ -4704,6 +4715,7 @@
F758B45E212C569D00515F55 /* NCScanCell.swift in Sources */,
F78B87E72B62527100C65ADC /* NCMediaDataSource.swift in Sources */,
F76882272C0DD1E7001CF441 /* NCManageE2EEView.swift in Sources */,
B5C9801A2DACD56C0041B146 /* NCMedia+Menu.swift in Sources */,
F7864ACC2A78FE73004870E0 /* NCManageDatabase+LocalFile.swift in Sources */,
F7327E302B73A86700A462C7 /* NCNetworking+WebDAV.swift in Sources */,
F7D61EA82EBF1694007F865B /* NCManageDatabase+TableCapabilities.swift in Sources */,
Expand Down
194 changes: 188 additions & 6 deletions iOSClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import RealmSwift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
var backgroundSessionCompletionHandler: (() -> Void)?
var activeLogin: NCLogin?
var activeLoginWeb: NCLoginWeb?
var taskAutoUploadDate: Date = Date()
var orientationLock = UIInterfaceOrientationMask.all
@objc let adjust = AdjustHelper()
var isUiTestingEnabled: Bool {
return ProcessInfo.processInfo.arguments.contains("UI_TESTING")
}
Expand All @@ -31,7 +36,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD

var bgTask: UIBackgroundTaskIdentifier = .invalid
var pushSubscriptionTask: Task<Void, Never>?

var window: UIWindow?
var sceneIdentifier: String = ""
var activeViewController: UIViewController?
var account: String = ""
var urlBase: String = ""
var user: String = ""
var userId: String = ""
var password: String = ""
var timerErrorNetworking: Timer?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if isUiTestingEnabled {
Task {
Expand All @@ -45,6 +59,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
utilityFileSystem.emptyTemporaryDirectory()
utilityFileSystem.clearCacheDirectory("com.limit-point.LivePhoto")

UINavigationBar.appearance().tintColor = NCBrandColor.shared.brand
UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = NCBrandColor.shared.brand

let versionNextcloudiOS = String(format: NCBrandOptions.shared.textCopyrightNextcloudiOS, utility.getVersionBuild())

NCAppVersionManager.shared.checkAndUpdateInstallState()
Expand Down Expand Up @@ -119,6 +136,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
if NCBrandOptions.shared.enforce_passcode_lock {
NCPreferences().requestPasscodeAtStart = true
}

// 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
// }
// }
// }

return true
}
Expand Down Expand Up @@ -200,7 +228,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
task.setTaskCompleted(success: true)
}

await backgroundSync(task: task)
guard let tblAccount = await NCManageDatabase.shared.getActiveTableAccountAsync() else {
nkLog(tag: self.global.logTagTask, emoji: .info, message: "No active account or background task already running")
return
}

await backgroundSync(tblAccount: tblAccount, task: task)
}
}

Expand Down Expand Up @@ -281,12 +314,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
guard !expired else { return }

let err = await NCNetworking.shared.createFolderForAutoUpload(
serverUrlFileName: metadata.serverUrlFileName,
account: metadata.account
serverUrlFileName: meta.serverUrlFileName,
account: meta.account
)
// Fail-fast: abort the whole sync on first failure
if err != .success {
nkLog(tag: self.global.logTagBgSync, emoji: .error, message: "Create folder '\(metadata.serverUrlFileName)' failed: \(err.errorCode) – aborting sync")
nkLog(tag: self.global.logTagBgSync, emoji: .error, message: "Create folder '\(meta.serverUrlFileName)' failed: \(err.errorCode) – aborting sync")
return
}
}
Expand Down Expand Up @@ -437,7 +470,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}
}

// MARK: -
// MARK: - Trust Certificate Error

func trustCertificateError(host: String) {
guard let activeTblAccount = NCManageDatabase.shared.getActiveTableAccount(),
Expand Down Expand Up @@ -489,6 +522,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD

NCPreferences().removeAll()

// Reset App Icon badge / File Icon badge
if #available(iOS 17.0, *) {
UNUserNotificationCenter.current().setBadgeCount(0)
}
exit(0)
}

Expand All @@ -498,6 +535,151 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
let applicationHandle = NCApplicationHandle()
return applicationHandle.applicationOpenUserActivity(userActivity)
}

// MARK: - Login

func openLogin(selector: Int, window: UIWindow? = nil) {
UIApplication.shared.allSceneSessionDestructionExceptFirst()

// Nextcloud standard login
if selector == NCGlobal.shared.introSignup {
if activeLogin?.view.window == nil {
if selector == NCGlobal.shared.introSignup {
let web = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginProvider") as? NCLoginProvider
web?.initialURLString = NCBrandOptions.shared.linkloginPreferredProviders
showLoginViewController(web)
} else {
activeLogin = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLogin") as? NCLogin
if let controller = UIApplication.shared.firstWindow?.rootViewController as? NCMainTabBarController, !controller.account.isEmpty {
let session = NCSession.shared.getSession(account: controller.account)
activeLogin?.urlBase = session.urlBase
}
showLoginViewController(activeLogin)
}
}
} else {
if activeLogin?.view.window == nil {
activeLogin = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLogin") as? NCLogin
activeLogin?.urlBase = NCBrandOptions.shared.disable_request_login_url ? NCBrandOptions.shared.loginBaseUrl : ""
showLoginViewController(activeLogin)
}
}
}

func openLogin(viewController: UIViewController?, selector: Int, openLoginWeb: Bool) {
// openLogin(selector: NCGlobal.shared.introLogin)
// [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, contextViewController: viewController)
}
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 selector == NCGlobal.shared.introSignup {
activeLoginWeb?.urlBase = NCBrandOptions.shared.linkloginPreferredProviders
} else {
activeLoginWeb?.urlBase = self.urlBase
}
showLoginViewController(activeLoginWeb, contextViewController: viewController)
}

} 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, contextViewController: viewController)
}

} 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, contextViewController: viewController)
}

} else {

if activeLogin?.view.window == nil {
activeLogin = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLogin") as? NCLogin
showLoginViewController(activeLogin, contextViewController: viewController)
}
}
}

func showLoginViewController(_ viewController: UIViewController?) {
guard let viewController else { return }
let navigationController = UINavigationController(rootViewController: viewController)

navigationController.modalPresentationStyle = .fullScreen
navigationController.navigationBar.barStyle = .black
navigationController.navigationBar.tintColor = NCBrandColor.shared.customerText
navigationController.navigationBar.barTintColor = NCBrandColor.shared.customer
navigationController.navigationBar.isTranslucent = false

if let controller = UIApplication.shared.firstWindow?.rootViewController {
if let presentedVC = controller.presentedViewController, !(presentedVC is UINavigationController) {
presentedVC.dismiss(animated: false) {
controller.present(navigationController, animated: true)
}
} else {
controller.present(navigationController, animated: true)
}
} else {
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
}
}

func showLoginViewController(_ viewController: UIViewController?, contextViewController: UIViewController?) {

if contextViewController == nil {
if let viewController = viewController {
let navigationController = UINavigationController(rootViewController: viewController)
navigationController.navigationBar.barStyle = .black
navigationController.navigationBar.tintColor = NCBrandColor.shared.customerText
navigationController.navigationBar.barTintColor = NCBrandColor.shared.customer
navigationController.navigationBar.isTranslucent = false
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
}
} else if contextViewController is UINavigationController {
if let contextViewController = contextViewController, let viewController = viewController {
(contextViewController as? UINavigationController)?.pushViewController(viewController, animated: true)
}
} else {
if let viewController = viewController, let contextViewController = contextViewController {
let navigationController = UINavigationController(rootViewController: viewController)
navigationController.modalPresentationStyle = .fullScreen
navigationController.navigationBar.barStyle = .black
navigationController.navigationBar.tintColor = NCBrandColor.shared.customerText
navigationController.navigationBar.barTintColor = NCBrandColor.shared.customer
navigationController.navigationBar.isTranslucent = false
contextViewController.present(navigationController, animated: true) { }
}
}
}

@objc func startTimerErrorNetworking() {
timerErrorNetworking = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(checkErrorNetworking), userInfo: nil, repeats: true)
}

@objc private func checkErrorNetworking() {
guard !account.isEmpty, NCKeychain().getPassword(account: account).isEmpty else { return }
openLogin(viewController: window?.rootViewController, selector: NCGlobal.shared.introLogin, openLoginWeb: true)
}
}

// MARK: - Extension
Expand Down
Loading