Skip to content
Merged
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
6 changes: 3 additions & 3 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5759,7 +5759,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -5825,7 +5825,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -6002,7 +6002,7 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/marinofaggiana/LucidBanner";
requirement = {
branch = 0.5.0;
branch = main;
kind = branch;
};
};
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Favorites/NCFavorite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class NCFavorite: NCCollectionViewCommon {
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

stopSyncMetadata()
Task {
await stopSyncMetadata()
await NCNetworking.shared.networkingTasks.cancel(identifier: "NCFavorite")
}
}
Expand Down
7 changes: 5 additions & 2 deletions iOSClient/Files/NCFiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class NCFiles: NCCollectionViewCommon {
}

NotificationCenter.default.addObserver(forName: UIApplication.didEnterBackgroundNotification, object: nil, queue: nil) { _ in
self.stopSyncMetadata()
Task {
await self.stopSyncMetadata()
await self.searchOperationHandle.cancel()
}
}

if self.serverUrl.isEmpty {
Expand Down Expand Up @@ -127,8 +130,8 @@ class NCFiles: NCCollectionViewCommon {
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

stopSyncMetadata()
Task {
await stopSyncMetadata()
await NCNetworking.shared.networkingTasks.cancel(identifier: "\(self.serverUrl)_NCFiles")
}
}
Expand Down
32 changes: 22 additions & 10 deletions iOSClient/GUI/Lucid Banner/BannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import SwiftUI
import LucidBanner
import Alamofire

// MARK: - Show Banner
#if !EXTENSION
Expand Down Expand Up @@ -133,7 +134,7 @@
backgroundColor: UIColor = .systemBackground,
errorCode: Int? = nil) async {
#if !EXTENSION
guard !bannerContainsErrorCode(errorCode: errorCode) else {
guard !bannerContainsError(errorCode: errorCode) else {
return
}
let scene = scene ?? UIApplication.shared.mainAppWindow?.windowScene
Expand Down Expand Up @@ -176,7 +177,8 @@
foregroundColor: UIColor = .white,
backgroundColor: UIColor = .red,
sleepBefore: Double = 1,
errorCode: Int) async {
errorCode: Int,
afError: AFError? = nil) async {
for scene in UIApplication.shared.foregroundActiveScenes {
await showErrorBanner(scene: scene,
title: title,
Expand All @@ -185,7 +187,8 @@
foregroundColor: foregroundColor,
backgroundColor: backgroundColor,
sleepBefore: sleepBefore,
errorCode: errorCode)
errorCode: errorCode,
afError: afError)
}
}

Expand All @@ -197,15 +200,17 @@
foregroundColor: UIColor = .white,
backgroundColor: UIColor = .red,
sleepBefore: Double = 1,
errorCode: Int) async {
errorCode: Int,
afError: AFError? = nil) async {
let scene = SceneManager.shared.getWindow(controller: controller)?.windowScene
await showErrorBanner(scene: scene,
text: text,
footnote: footnote,
foregroundColor: foregroundColor,
backgroundColor: backgroundColor,
sleepBefore: sleepBefore,
errorCode: errorCode)
errorCode: errorCode,
afError: afError)
}

@MainActor
Expand All @@ -216,15 +221,17 @@
foregroundColor: UIColor = .white,
backgroundColor: UIColor = .red,
sleepBefore: Double = 1,
errorCode: Int) async {
errorCode: Int,
afError: AFError? = nil) async {
await showErrorBanner(controller: SceneManager.shared.getController(sceneIdentifier: sceneIdentifier),
title: title,
text: text,
footnote: footnote,
foregroundColor: foregroundColor,
backgroundColor: backgroundColor,
sleepBefore: sleepBefore,
errorCode: errorCode)
errorCode: errorCode,
afError: afError)
}

#endif
Expand All @@ -237,9 +244,10 @@
foregroundColor: UIColor = .white,
backgroundColor: UIColor = .red,
sleepBefore: Double = 1,
errorCode: Int) async {
errorCode: Int,
afError: AFError? = nil) async {
#if !EXTENSION
guard !bannerContainsErrorCode(errorCode: errorCode) else {
guard !bannerContainsError(errorCode: errorCode, afError: afError) else {
return
}
let scene = scene ?? UIApplication.shared.mainAppWindow?.windowScene
Expand Down Expand Up @@ -280,14 +288,17 @@

// MARK: - Helper
#if !EXTENSION
func bannerContainsErrorCode(errorCode: Int?) -> Bool {
func bannerContainsError(errorCode: Int?, afError: AFError? = nil) -> Bool {
guard let errorCode else {
return false
}
// List of errors not to be displayed
if errorCode == -999 {
return true
}
if let afError, case .explicitlyCancelled = afError {
return true
}
// Prevent repeated display of the same user-facing error during the current foreground session.
// If this error code has already been shown, do nothing.
// Otherwise, record it and allow the UX notification to be displayed once.
Expand Down Expand Up @@ -382,3 +393,4 @@
.padding()
}
}

Check warning on line 396 in iOSClient/GUI/Lucid Banner/BannerView.swift

View workflow job for this annotation

GitHub Actions / Lint

Trailing Newline Violation: Files should have a single trailing newline (trailing_newline)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import Foundation
import NextcloudKit
import Alamofire

extension NCCollectionViewCommon {
@MainActor
Expand All @@ -18,7 +19,7 @@

self.networkSearchInProgress = true
// STOP PREEMPTIVE SYNC METADATA
self.stopSyncMetadata()
await self.stopSyncMetadata()
// Clear datasotce
self.dataSource.removeAll()
self.collectionView.reloadData()
Expand Down Expand Up @@ -112,24 +113,17 @@
self.collectionView.reloadData()

// ---> Get providers
let results = await NextcloudKit.shared.unifiedSearchProviders(account: session.account) { _ in
let results = await NextcloudKit.shared.unifiedSearchProviders(account: session.account, handle: searchOperationHandle) { _ in
// example filter
// ["calendar", "files", "fulltextsearch"].contains(provider.id)
return true
} taskHandler: { task in
Task {
let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(
account: self.session.account,
name: "unifiedSearchProviders"
)
await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task)
self.searchTask = task
self.collectionView.reloadData()
}
}

if results.error != .success {
await showErrorBanner(controller: self.controller, text: results.error.errorDescription, errorCode: results.error.errorCode)
await showErrorBanner(controller: self.controller,
text: results.error.errorDescription,
errorCode: results.error.errorCode,
afError: results.error.error as? AFError)
}

guard isSearchingMode,
Expand All @@ -154,21 +148,15 @@
limit: 5,
cursor: 0,
timeout: 90,
account: session.account
) { task in
Task {
let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(
account: self.session.account,
name: "unifiedSearch"
)
await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task)
self.searchTask = task
self.collectionView.reloadData()
}
}
account: session.account,
handle: searchOperationHandle
)

if results.error != .success {
await showErrorBanner(controller: self.controller, text: results.error.errorDescription, errorCode: results.error.errorCode)
await showErrorBanner(controller: self.controller,
text: results.error.errorDescription,
errorCode: results.error.errorCode,
afError: results.error.error as? AFError)
}

guard isSearchingMode,
Expand Down Expand Up @@ -217,21 +205,15 @@
limit: 5,
cursor: cursor,
timeout: 60,
account: session.account
) { task in
Task {
let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(
account: self.session.account,
name: "unifiedSearch"
)
await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task)
self.searchTask = task
self.collectionView.reloadData()
}
}
account: session.account,
handle: searchOperationHandle
)

if results.error != .success {
await showErrorBanner(controller: self.controller, text: results.error.errorDescription, errorCode: results.error.errorCode)
await showErrorBanner(controller: self.controller,
text: results.error.errorDescription,
errorCode: results.error.errorCode,
afError: results.error.error as? AFError)
}

guard isSearchingMode,
Expand Down Expand Up @@ -339,3 +321,4 @@
return metadata
}
}

Check warning on line 324 in iOSClient/Main/Collection Common/NCCollectionViewCommon+Search.swift

View workflow job for this annotation

GitHub Actions / Lint

Trailing Newline Violation: Files should have a single trailing newline (trailing_newline)
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension NCCollectionViewCommon {
/// Cancels the running sync task (if any) and releases the reference.
///
/// Use this when the page/screen is about to disappear or the user navigates away.
func stopSyncMetadata() {
func stopSyncMetadata() async {
if let task = syncMetadatasTask {
if task.isCancelled {
nkLog(tag: global.logTagSpeedUpSyncMetadata, emoji: .stop, message: "Sync Metadata for \(self.serverUrl) was already cancelled.", consoleOnly: true)
Expand Down
27 changes: 23 additions & 4 deletions iOSClient/Main/Collection Common/NCCollectionViewCommon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class NCCollectionViewCommon: UIViewController, NCAccountSettingsModelDelegate,
var syncMetadatasTask: Task<Void, Never>?
// Search
var isSearchingMode: Bool = false
var searchOperationHandle = NKOperationHandle()
var searchTask: URLSessionTask?
var searchResultText: String?
var searchResultStore: String?
Expand Down Expand Up @@ -265,6 +266,24 @@ class NCCollectionViewCommon: UIViewController, NCAccountSettingsModelDelegate,
DispatchQueue.main.async {
self.collectionView?.collectionViewLayout.invalidateLayout()
}

Task {
for await event in await searchOperationHandle.events() {
switch event {
case .didSetTask(let task):
searchTask = task
if dataSource.isEmpty() {
collectionView.reloadData()
}
case .didSetRequest(let request):
print("Request available:", request)
case .didCancel:
print("Operation cancelled")
case .didClear:
print("Handle cleared")
}
}
}
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -315,13 +334,13 @@ class NCCollectionViewCommon: UIViewController, NCAccountSettingsModelDelegate,

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

self.searchTask?.cancel()
dismissTip()

// Cancel Queue & Retrieves Properties
self.networking.downloadThumbnailQueue.cancelAll()
searchTask?.cancel()
Task {
await searchOperationHandle.cancel()
}
}

override func viewDidDisappear(_ animated: Bool) {
Expand Down Expand Up @@ -516,13 +535,13 @@ class NCCollectionViewCommon: UIViewController, NCAccountSettingsModelDelegate,
//
mainNavigationController?.hiddenPlusButton(false)

self.searchTask?.cancel()
self.isSearchingMode = false
self.networkSearchInProgress = false
self.searchResultText = nil
self.searchResultStore = nil

Task {
await searchOperationHandle.cancel()
self.dataSource.removeAll()
await self.reloadDataSource()
}
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Shares/NCShares.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class NCShares: NCCollectionViewCommon {
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

stopSyncMetadata()
Task {
await stopSyncMetadata()
await NCNetworking.shared.networkingTasks.cancel(identifier: "NCShares")
backgroundTask?.cancel()
}
Expand Down
Loading