diff options
Diffstat (limited to 'Map')
| -rw-r--r-- | Map/MapApp.swift | 2 | ||||
| -rw-r--r-- | Map/Presentation/Base Components/CollaborationButton.swift | 51 | ||||
| -rw-r--r-- | Map/Presentation/MapEditor.swift | 29 |
3 files changed, 81 insertions, 1 deletions
diff --git a/Map/MapApp.swift b/Map/MapApp.swift index 989349c..38ff408 100644 --- a/Map/MapApp.swift +++ b/Map/MapApp.swift @@ -36,7 +36,7 @@ struct MapApp: App { .focusedSceneValue(\.document, file.$document) .focusedSceneValue(\.fileURL, file.fileURL) } - .windowToolbarStyle(.unifiedCompact) + .windowToolbarStyle(.unified) .commands { MapCommands() UpdateCommands(updaterController: updaterController) diff --git a/Map/Presentation/Base Components/CollaborationButton.swift b/Map/Presentation/Base Components/CollaborationButton.swift new file mode 100644 index 0000000..49dd2c5 --- /dev/null +++ b/Map/Presentation/Base Components/CollaborationButton.swift @@ -0,0 +1,51 @@ +import SharedWithYou +import SwiftUI + +struct CollaborationButton: NSViewRepresentable { + let fileURL: URL + + func makeNSView(context: Context) -> SWCollaborationView { + let itemProvider = NSItemProvider(contentsOf: fileURL)! + let view = SWCollaborationView(itemProvider: itemProvider) + + view.activeParticipantCount = 0 + view.cloudSharingDelegate = context.coordinator + + return view + } + + func updateNSView(_ nsView: SWCollaborationView, context: Context) { + // Update participant count as needed + } + + func makeCoordinator() -> Coordinator { + Coordinator(fileURL: fileURL) + } + + class Coordinator: NSObject, NSCloudSharingServiceDelegate { + let fileURL: URL + + init(fileURL: URL) { + self.fileURL = fileURL + } + + func sharingService( + _ sharingService: NSSharingService, + didFailToShareItems items: [Any], + error: Error + ) { + print("Failed to share: \(error)") + } + + func sharingService( + _ sharingService: NSSharingService, + didCompleteForItems items: [Any] + ) { + print("Sharing completed") + } + + func options(for: NSSharingService, share: NSItemProvider) -> NSSharingService.CloudKitOptions { + return [.allowPublic, .allowPrivate, .allowReadWrite] + } + } +} diff --git a/Map/Presentation/MapEditor.swift b/Map/Presentation/MapEditor.swift index c323882..fcf465e 100644 --- a/Map/Presentation/MapEditor.swift +++ b/Map/Presentation/MapEditor.swift @@ -12,13 +12,19 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see https://map.tranquil.systems. +import SharedWithYou import SwiftUI import WmapParser struct MapEditor: View { + @Binding var document: MapDocument + @FocusedValue(\.fileURL) var fileURL: URL? + @State var selectedEvolution: StageType = .behavior @State var isSearching: Bool = false + @State var isPresentingSharingSheet: Bool = false + var parsedMap: WmapParser.Map { document.parsed } @@ -209,6 +215,17 @@ struct MapEditor: View { } } .toolbar { + + if let fileURL { + if fileIsShared { + ToolbarItem(placement: .primaryAction) { + CollaborationButton(fileURL: fileURL) + } + } + ToolbarItem(placement: .primaryAction) { + ShareLink(item: fileURL) + } + } if #unavailable(macOS 26) { ToolbarItem(placement: .primaryAction) { EvolutionPicker(selectedEvolution: $selectedEvolution) @@ -219,6 +236,18 @@ struct MapEditor: View { .focusedSceneValue(\.selectedEvolution, $selectedEvolution) } + private var fileIsShared: Bool { + do { + if let fileURL { + let resourceValues = try fileURL.resourceValues(forKeys: [.ubiquitousItemIsSharedKey]) + return resourceValues.ubiquitousItemIsShared ?? false + } + return false + } catch { + return false + } + } + @ViewBuilder func adaptiveStack<Content: View>(@ViewBuilder content: () -> Content) -> some View { if viewStyle == .horizontal { |