Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell_integration/macOS: Add ability to share macOS VFS files via internal link shares #7787

Merged
merged 6 commits into from
Feb 10, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import NextcloudKit

extension NKShare {
enum ShareType: Int {
case internalLink = -1
case user = 0
case group = 1
case publicLink = 3
Expand All @@ -31,6 +32,11 @@ extension NKShare {
var typeImage: NSImage? {
var image: NSImage?
switch shareType {
case ShareType.internalLink.rawValue:
image = NSImage(
systemSymbolName: "square.and.arrow.up.circle.fill",
accessibilityDescription: "Internal link share icon"
)
case ShareType.user.rawValue:
image = NSImage(
systemSymbolName: "person.circle.fill",
Expand Down Expand Up @@ -85,6 +91,8 @@ extension NKShare {
}

switch shareType {
case ShareType.internalLink.rawValue:
return "Internal share (requires access to file)"
case ShareType.user.rawValue:
return "User share (\(shareWith))"
case ShareType.group.rawValue:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class ShareTableItemView: NSTableCellView {
}
typeImageView.image = share.typeImage
label.stringValue = share.displayString
copyLinkButton.isHidden = share.shareType != NKShare.ShareType.publicLink.rawValue
copyLinkButton.isHidden =
share.shareType != NKShare.ShareType.publicLink.rawValue &&
share.shareType != NKShare.ShareType.internalLink.rawValue
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class ShareTableViewDataSource: NSObject, NSTableViewDataSource, NSTableViewDele
}
}
var capabilities: Capabilities?
var itemMetadata: NKFile?

private(set) var itemURL: URL?
private(set) var itemServerRelativePath: String?
Expand Down Expand Up @@ -117,16 +116,20 @@ class ShareTableViewDataSource: NSObject, NSTableViewDataSource, NSTableViewDele
presentError("Account data is unavailable, cannot reload data!")
return
}
itemMetadata = await fetchItemMetadata(
guard let itemMetadata = await fetchItemMetadata(
itemRelativePath: serverPathString, account: account, kit: kit
)
guard itemMetadata?.permissions.contains("R") == true else {
) else {
presentError("Unable to retrieve file metadata...")
return
}
guard itemMetadata.permissions.contains("R") == true else {
presentError("This file cannot be shared.")
return
}
shares = await fetch(
itemIdentifier: itemIdentifier, itemRelativePath: serverPathString
)
shares.append(Self.generateInternalShare(for: itemMetadata))
} catch let error {
presentError("Could not reload data: \(error), will try again.")
reattempt()
Expand Down Expand Up @@ -164,6 +167,17 @@ class ShareTableViewDataSource: NSObject, NSTableViewDataSource, NSTableViewDele
}
}

private static func generateInternalShare(for file: NKFile) -> NKShare {
let internalShare = NKShare()
internalShare.shareType = NKShare.ShareType.internalLink.rawValue
internalShare.url = file.urlBase + "/index.php/f/" + file.fileId
internalShare.account = file.account
internalShare.displaynameOwner = file.ownerDisplayName
internalShare.displaynameFileOwner = file.ownerDisplayName
internalShare.path = file.path
return internalShare
}

private func fetchCapabilities() async -> Capabilities? {
guard let account else {
self.presentError("Could not fetch capabilities as account is invalid.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class ShareViewController: NSViewController, ShareViewDataSourceUIDelegate {
}

func showOptions(share: NKShare) {
guard let account = shareDataSource.account else { return }
guard let account = shareDataSource.account, share.canEdit || share.canDelete else { return }
optionsView.account = account
optionsView.controller = ShareController(
share: share, account: account, kit: shareDataSource.kit
Expand Down
Loading