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
16 changes: 12 additions & 4 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@
F72EC7242F45C81600A2135C /* NotificationCenter+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72EC7232F45C81600A2135C /* NotificationCenter+Extension.swift */; };
F72EC7262F45C91E00A2135C /* NCContextMenuNavigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72EC7252F45C90600A2135C /* NCContextMenuNavigation.swift */; };
F72EC7282F45FF1400A2135C /* NCContextMenuPlus.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72EC7272F45FF0600A2135C /* NCContextMenuPlus.swift */; };
4E3A0C13000D000100A00002 /* NCMenuButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3A0C13000D000100A00001 /* NCMenuButton.swift */; };
4E3A0C13000D000100A00004 /* NCMenuPresentationMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3A0C13000D000100A00003 /* NCMenuPresentationMonitor.swift */; };
4E3A0C13000D000100A00006 /* NCMenuPresentationMonitorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3A0C13000D000100A00005 /* NCMenuPresentationMonitorTests.swift */; };
F72EC7292F4617F600A2135C /* NotificationCenter+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72EC7232F45C81600A2135C /* NotificationCenter+Extension.swift */; };
F72FD3B5297ED49A00075D28 /* NCManageDatabase+E2EE.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72FD3B4297ED49A00075D28 /* NCManageDatabase+E2EE.swift */; };
F72FD3B6297ED49A00075D28 /* NCManageDatabase+E2EE.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72FD3B4297ED49A00075D28 /* NCManageDatabase+E2EE.swift */; };
Expand Down Expand Up @@ -953,7 +956,6 @@
F7C9B9232B582F550064EA91 /* NCManageDatabase+SecurityGuard.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C9B91C2B582F550064EA91 /* NCManageDatabase+SecurityGuard.swift */; };
F7CADEFD2EA159210057849E /* NCMetadataUploadTranfersSuccess.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CADEFA2EA1591D0057849E /* NCMetadataUploadTranfersSuccess.swift */; };
F7CAFE182F164B9500DB35A5 /* NCCollectionViewCommon+CellDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CAFE172F164B9200DB35A5 /* NCCollectionViewCommon+CellDelegate.swift */; };
F7CAFE1B2F16AA8D00DB35A5 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CAFE1A2F16AA8600DB35A5 /* main.swift */; };
F7CAFE1D2F17A35F00DB35A5 /* ProgressQuantizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CAFE1C2F17A34F00DB35A5 /* ProgressQuantizer.swift */; };
F7CAFE1E2F17A37C00DB35A5 /* ProgressQuantizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CAFE1C2F17A34F00DB35A5 /* ProgressQuantizer.swift */; };
F7CAFE1F2F17A37C00DB35A5 /* ProgressQuantizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CAFE1C2F17A34F00DB35A5 /* ProgressQuantizer.swift */; };
Expand Down Expand Up @@ -1594,6 +1596,9 @@
F72EC7232F45C81600A2135C /* NotificationCenter+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NotificationCenter+Extension.swift"; sourceTree = "<group>"; };
F72EC7252F45C90600A2135C /* NCContextMenuNavigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCContextMenuNavigation.swift; sourceTree = "<group>"; };
F72EC7272F45FF0600A2135C /* NCContextMenuPlus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCContextMenuPlus.swift; sourceTree = "<group>"; };
4E3A0C13000D000100A00001 /* NCMenuButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCMenuButton.swift; sourceTree = "<group>"; };
4E3A0C13000D000100A00003 /* NCMenuPresentationMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCMenuPresentationMonitor.swift; sourceTree = "<group>"; };
4E3A0C13000D000100A00005 /* NCMenuPresentationMonitorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCMenuPresentationMonitorTests.swift; sourceTree = "<group>"; };
F72FD3B4297ED49A00075D28 /* NCManageDatabase+E2EE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCManageDatabase+E2EE.swift"; sourceTree = "<group>"; };
F7313A71302F0A15000C8E98 /* NCRichWorkspaceCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCRichWorkspaceCoordinator.swift; sourceTree = "<group>"; };
F7320934201B812F008A0888 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2030,7 +2035,6 @@
F7C9B91C2B582F550064EA91 /* NCManageDatabase+SecurityGuard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NCManageDatabase+SecurityGuard.swift"; sourceTree = "<group>"; };
F7CADEFA2EA1591D0057849E /* NCMetadataUploadTranfersSuccess.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCMetadataUploadTranfersSuccess.swift; sourceTree = "<group>"; };
F7CAFE172F164B9200DB35A5 /* NCCollectionViewCommon+CellDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCCollectionViewCommon+CellDelegate.swift"; sourceTree = "<group>"; };
F7CAFE1A2F16AA8600DB35A5 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
F7CAFE1C2F17A34F00DB35A5 /* ProgressQuantizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressQuantizer.swift; sourceTree = "<group>"; };
F7CB77632F5843D700DE649A /* UIFont+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+Extension.swift"; sourceTree = "<group>"; };
F7CBC1212BAC8B0000EC1D55 /* NCSectionFirstHeaderEmptyData.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCSectionFirstHeaderEmptyData.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2282,6 +2286,8 @@
AF93471127E2341B002537EE /* NCContextMenuShare.swift */,
F75D19E225EFE09000D74598 /* NCContextMenuTrash.swift */,
F710D2012405826100A6033D /* NCContextMenuViewer.swift */,
4E3A0C13000D000100A00001 /* NCMenuButton.swift */,
4E3A0C13000D000100A00003 /* NCMenuPresentationMonitor.swift */,
);
path = Menu;
sourceTree = "<group>";
Expand Down Expand Up @@ -2317,6 +2323,7 @@
C0DEDA7E30C1000100A00001 /* NCAutoUploadDateTests.swift */,
4463A0C1300D000100A00003 /* NCAutoUploadKnownFilesTests.swift */,
4437B0C1300D000100A00001 /* NCBackupExclusionTests.swift */,
4E3A0C13000D000100A00005 /* NCMenuPresentationMonitorTests.swift */,
320C20803A58DAF7575440A8 /* NKErrorUserFriendlyMessageTests.swift */,
C0DEA070306D000100000007 /* NCAutoUploadAssetTests.swift */,
F76BED7B306D0000002E1442 /* NCPhotoLibraryAssetTests.swift */,
Expand Down Expand Up @@ -3801,7 +3808,6 @@
F7BDC1DD300F4FF800C5D9FA /* Processor */,
F7BDC1DE300F502C00C5D9FA /* Refresh */,
F702F2CC25EE5B4F008F8E80 /* AppDelegate.swift */,
F7CAFE1A2F16AA8600DB35A5 /* main.swift */,
F794E13E2BBC0F70003693D7 /* SceneDelegate.swift */,
F7CF067A2E0FF38F0063AD04 /* NCAppStateManager.swift */,
F77DD6A72C5CC093009448FB /* NCSession.swift */,
Expand Down Expand Up @@ -4698,6 +4704,7 @@
C0DEDA7E30C1000100A00002 /* NCAutoUploadDateTests.swift in Sources */,
4463A0C1300D000100A00004 /* NCAutoUploadKnownFilesTests.swift in Sources */,
4437B0C1300D000100A00002 /* NCBackupExclusionTests.swift in Sources */,
4E3A0C13000D000100A00006 /* NCMenuPresentationMonitorTests.swift in Sources */,
C0DEA070306D000100000008 /* NCAutoUploadAssetTests.swift in Sources */,
F76BED7E306D0000002E1442 /* NCPhotoLibraryAssetTests.swift in Sources */,
A1E2EE01000000000000000A /* NCEndToEndKeySetArchiveTests.swift in Sources */,
Expand Down Expand Up @@ -5122,6 +5129,8 @@
AFCE353727E4ED7B00FEA6C2 /* NCShareCells.swift in Sources */,
F75A9EE623796C6F0044CFCE /* NCNetworking.swift in Sources */,
F72EC7282F45FF1400A2135C /* NCContextMenuPlus.swift in Sources */,
4E3A0C13000D000100A00002 /* NCMenuButton.swift in Sources */,
4E3A0C13000D000100A00004 /* NCMenuPresentationMonitor.swift in Sources */,
AA8D31552D41052300FE2775 /* NCManageDatabase+DownloadLimit.swift in Sources */,
F758B460212C56A400515F55 /* NCScan.swift in Sources */,
F76882262C0DD1E7001CF441 /* NCSettingsView.swift in Sources */,
Expand Down Expand Up @@ -5288,7 +5297,6 @@
F73EF7DF2B02266D0087E6E9 /* NCManageDatabase+Trash.swift in Sources */,
F79B646026CA661600838ACA /* UIControl+Extension.swift in Sources */,
F768823E2C0DD305001CF441 /* LazyView.swift in Sources */,
F7CAFE1B2F16AA8D00DB35A5 /* main.swift in Sources */,
F3E173B02C9AF637006D177A /* ScreenAwakeManager.swift in Sources */,
F764C3E52FFB7DFA00029FD5 /* NCManageDatabase+MediaMetadataBackfill.swift in Sources */,
F747EB0D2C4AC1FF00F959A8 /* NCCollectionViewCommon+CollectionViewDelegateFlowLayout.swift in Sources */,
Expand Down
133 changes: 133 additions & 0 deletions Tests/NextcloudUnitTests/NCMenuPresentationMonitorTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// SPDX-FileCopyrightText: Nextcloud GmbH
// SPDX-FileCopyrightText: 2026 Marino Faggiana
// SPDX-License-Identifier: GPL-3.0-or-later

import Foundation
import Testing
@testable import Nextcloud

@Suite("Menu presentation monitor")
@MainActor
struct NCMenuPresentationMonitorTests {
/// Records the monitor notifications posted on a private notification center.
private final class Recorder: NSObject {
let center = NotificationCenter()
private(set) var names: [Notification.Name] = []

override init() {
super.init()
for name in [NCMenuPresentationMonitor.menuWillShowNotification, NCMenuPresentationMonitor.menuDidHideNotification] {
center.addObserver(self, selector: #selector(record(_:)), name: name, object: nil)
}
}

@objc private func record(_ notification: Notification) {
names.append(notification.name)
}
}

@Test("No menu is visible at start")
func startsHidden() {
let monitor = NCMenuPresentationMonitor(notificationCenter: NotificationCenter())

#expect(!monitor.isMenuVisible)
}

@Test("Opening and closing one menu posts show and hide once")
func singleMenu() {
let recorder = Recorder()
let monitor = NCMenuPresentationMonitor(notificationCenter: recorder.center)
let owner = NSObject()

monitor.menuWillShow(owner)
#expect(monitor.isMenuVisible)

monitor.menuDidHide(owner)
#expect(!monitor.isMenuVisible)

#expect(recorder.names == [NCMenuPresentationMonitor.menuWillShowNotification, NCMenuPresentationMonitor.menuDidHideNotification])
}

@Test("Hide is posted only when the last open menu closes")
func overlappingMenus() {
let recorder = Recorder()
let monitor = NCMenuPresentationMonitor(notificationCenter: recorder.center)
let first = NSObject()
let second = NSObject()

monitor.menuWillShow(first)
monitor.menuWillShow(second)
monitor.menuDidHide(first)
#expect(monitor.isMenuVisible)

monitor.menuDidHide(second)
#expect(!monitor.isMenuVisible)

#expect(recorder.names == [NCMenuPresentationMonitor.menuWillShowNotification, NCMenuPresentationMonitor.menuDidHideNotification])
}

@Test("Deferred actions run immediately when no menu is open")
func actionRunsImmediately() {
let monitor = NCMenuPresentationMonitor(notificationCenter: NotificationCenter())
var runs = 0

monitor.performWhenNoMenuVisible(for: NSObject()) { runs += 1 }

#expect(runs == 1)
}

@Test("Deferred actions of different owners wait for the last menu to close and run in order")
func actionsWaitForLastMenu() {
let monitor = NCMenuPresentationMonitor(notificationCenter: NotificationCenter())
let first = NSObject()
let second = NSObject()
var runs: [Int] = []

monitor.menuWillShow(first)
monitor.menuWillShow(second)
monitor.performWhenNoMenuVisible(for: first) { runs.append(1) }
monitor.performWhenNoMenuVisible(for: second) { runs.append(2) }

monitor.menuDidHide(first)
#expect(runs.isEmpty)

monitor.menuDidHide(second)
#expect(runs == [1, 2])

monitor.menuWillShow(first)
monitor.menuDidHide(first)
#expect(runs == [1, 2])
}

@Test("Only the last deferred action of the same owner runs")
func lastActionPerOwnerWins() {
let monitor = NCMenuPresentationMonitor(notificationCenter: NotificationCenter())
let menuOwner = NSObject()
let screen = NSObject()
var runs: [Int] = []

monitor.menuWillShow(menuOwner)
monitor.performWhenNoMenuVisible(for: screen) { runs.append(1) }
monitor.performWhenNoMenuVisible(for: screen) { runs.append(2) }
monitor.performWhenNoMenuVisible(for: screen) { runs.append(3) }
monitor.menuDidHide(menuOwner)

#expect(runs == [3])
}

@Test("Repeated or unmatched calls are ignored")
func unbalancedCalls() {
let recorder = Recorder()
let monitor = NCMenuPresentationMonitor(notificationCenter: recorder.center)
let owner = NSObject()

monitor.menuDidHide(owner)
monitor.menuWillShow(owner)
monitor.menuWillShow(owner)
monitor.menuDidHide(owner)
monitor.menuDidHide(owner)

#expect(!monitor.isMenuVisible)
#expect(recorder.names == [NCMenuPresentationMonitor.menuWillShowNotification, NCMenuPresentationMonitor.menuDidHideNotification])
}
}
1 change: 1 addition & 0 deletions iOSClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import SwiftUI
import RealmSwift
import Photos

@main
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
var backgroundSessionCompletionHandler: (() -> Void)?
var isUiTestingEnabled: Bool {
Expand Down
13 changes: 2 additions & 11 deletions iOSClient/Files/NCFilesNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@ class NCFilesNavigationController: NCMainNavigationController {
}
let image = utility.loadUserImage(for: tableAccount.user, displayName: tableAccount.displayName, urlBase: tableAccount.urlBase)

class AccountSwitcherButton: UIButton {
var onMenuOpened: (() -> Void)?

override func contextMenuInteraction(_ interaction: UIContextMenuInteraction, willDisplayMenuFor configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionAnimating?) {
super.contextMenuInteraction(interaction, willDisplayMenuFor: configuration, animator: animator)
onMenuOpened?()
}
}

@MainActor
func createLeftMenu() async -> UIMenu? {
var childrenAccountSubmenu: [UIMenuElement] = []
Expand Down Expand Up @@ -145,7 +136,7 @@ class NCFilesNavigationController: NCMainNavigationController {
let leftItems = groupedItems.isEmpty ? navigationItem?.leftBarButtonItems ?? [] : groupedItems
let accountItem = leftItems.first { $0.customView?.accessibilityIdentifier == "accountSwitcher" }
if accountItem == nil {
let accountButton = AccountSwitcherButton(type: .custom)
let accountButton = NCMenuButton(type: .custom)

accountButton.accessibilityIdentifier = "accountSwitcher"
accountButton.setImage(image, for: .normal)
Expand All @@ -155,7 +146,7 @@ class NCFilesNavigationController: NCMainNavigationController {
accountButton.menu = await createLeftMenu()
accountButton.showsMenuAsPrimaryAction = true

accountButton.onMenuOpened = {
accountButton.onMenuWillShow = {
self.collectionViewCommon?.dismissTip()
}

Expand Down
18 changes: 2 additions & 16 deletions iOSClient/Main/Collection Common/Cell/NCGridCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import NextcloudKit
import RealmSwift

protocol NCGridCellDelegate: AnyObject {
func onMenuIntent(with metadata: tableMetadata?)
func openContextMenu(with metadata: tableMetadata?, button: UIButton, sender: Any)
}

class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellMainProtocol {
class NCGridCell: UICollectionViewCell, NCCellMainProtocol {
@IBOutlet weak var imageItem: UIImageView!
@IBOutlet weak var imageSelect: UIImageView!
@IBOutlet weak var imageStatus: UIImageView!
Expand All @@ -24,7 +23,7 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellMainP
@IBOutlet weak var labelSubinfo: UILabel!
@IBOutlet weak var labelExtension: UILabel!

@IBOutlet weak var buttonMore: UIButton!
@IBOutlet weak var buttonMore: NCMenuButton!

@IBOutlet weak var imageVisualEffect: UIVisualEffectView!
@IBOutlet weak var iconsStackView: UIStackView!
Expand Down Expand Up @@ -57,11 +56,6 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellMainP
override func awakeFromNib() {
super.awakeFromNib()

let tapObserver = UITapGestureRecognizer(target: self, action: #selector(handleTapObserver(_:)))
tapObserver.cancelsTouchesInView = false
tapObserver.delegate = self
contentView.addGestureRecognizer(tapObserver)

initCell()
}

Expand Down Expand Up @@ -146,14 +140,6 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellMainP
return nil
}

@objc private func handleTapObserver(_ g: UITapGestureRecognizer) {
let location = g.location(in: contentView)

if buttonMore.frame.contains(location) {
delegate?.onMenuIntent(with: metadata)
}
}

func setButtonMore(image: UIImage) {
buttonMore.setImage(image, for: .normal)
}
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Main/Collection Common/Cell/NCGridCell.xib
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<constraint firstAttribute="width" constant="20" id="cZG-gx-gwt"/>
</constraints>
</imageView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="EJs-Ro-nbe" userLabel="buttonMoreGrid">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="EJs-Ro-nbe" userLabel="buttonMoreGrid" customClass="NCMenuButton" customModule="Nextcloud" customModuleProvider="target">
<rect key="frame" x="181" y="158" width="20" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="4Ba-Uy-pX2"/>
Expand Down
Loading
Loading