diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index bbbd598..3a088d3 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -36,7 +36,7 @@ struct ContentView: View { }, label: { Image(systemName: "square.and.pencil") }) .help("Create a new local draft.") } - .frame(idealWidth: 200) + .frame(width: 200) #else CollectionListView() .withErrorHandling() @@ -46,7 +46,7 @@ struct ContentView: View { ZStack { PostListView(selectedCollection: model.selectedCollection, showAllPosts: model.showAllPosts) .withErrorHandling() - .frame(idealWidth: 300) + .frame(width: 300) if model.isProcessingRequest { ZStack { Color(NSColor.controlBackgroundColor).opacity(0.75) @@ -59,8 +59,14 @@ struct ContentView: View { .withErrorHandling() #endif + #if os(macOS) Text("Select a post, or create a new local draft.") .foregroundColor(.secondary) + .frame(width: 500, height: 500) + #else + Text("Select a post, or create a new local draft.") + .foregroundColor(.secondary) + #endif } .environmentObject(model) .onChange(of: model.hasError) { value in diff --git a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj index fed886e..7177fb9 100644 --- a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj +++ b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj @@ -1278,7 +1278,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 690; + CURRENT_PROJECT_VERSION = 704; DEVELOPMENT_TEAM = TPPAB4YBA6; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; @@ -1287,8 +1287,8 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 0.7.0; + MACOSX_DEPLOYMENT_TARGET = 12.0; + MARKETING_VERSION = 1.0.0; PRODUCT_BUNDLE_IDENTIFIER = "com.abunchtell.WriteFreely-MultiPlatform"; PRODUCT_NAME = "WriteFreely for Mac"; SDKROOT = macosx; @@ -1305,7 +1305,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 690; + CURRENT_PROJECT_VERSION = 704; DEVELOPMENT_TEAM = TPPAB4YBA6; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; @@ -1314,8 +1314,8 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 0.7.0; + MACOSX_DEPLOYMENT_TARGET = 12.0; + MARKETING_VERSION = 1.0.0; PRODUCT_BUNDLE_IDENTIFIER = "com.abunchtell.WriteFreely-MultiPlatform"; PRODUCT_NAME = "WriteFreely for Mac"; SDKROOT = macosx; @@ -1374,6 +1374,7 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 702; DEVELOPMENT_TEAM = TPPAB4YBA6; INFOPLIST_FILE = "Tests macOS/Info.plist"; LD_RUNPATH_SEARCH_PATHS = ( @@ -1396,6 +1397,7 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 702; DEVELOPMENT_TEAM = TPPAB4YBA6; INFOPLIST_FILE = "Tests macOS/Info.plist"; LD_RUNPATH_SEARCH_PATHS = ( diff --git a/macOS/Navigation/ActivePostToolbarView.swift b/macOS/Navigation/ActivePostToolbarView.swift index 15955f2..530199b 100644 --- a/macOS/Navigation/ActivePostToolbarView.swift +++ b/macOS/Navigation/ActivePostToolbarView.swift @@ -76,13 +76,12 @@ struct ActivePostToolbarView: View { ) .disabled(activePost.status == PostStatus.local.rawValue) .help("Copy the post's URL to your Mac's pasteboard.") - .popover(isPresented: $isPresentingSharingServicePicker) { + .background( PostEditorSharingPicker( isPresented: $isPresentingSharingServicePicker, sharingItems: createPostUrl() ) - .frame(width: .zero, height: .zero) - } + ) Button(action: { publishPost(activePost) }, label: { Image(systemName: "paperplane") }) .disabled(activePost.body.isEmpty || activePost.status == PostStatus.published.rawValue) .help("Publish the post to the web.\(model.account.isLoggedIn ? "" : " You must be logged in to do this.")") // swiftlint:disable:this line_length @@ -104,7 +103,7 @@ struct ActivePostToolbarView: View { }) } - private func createPostUrl() -> [Any] { + private func createPostUrl() -> [NSURL] { guard let postId = model.selectedPost?.postId else { return [] } var urlString: String @@ -116,7 +115,7 @@ struct ActivePostToolbarView: View { let baseURL = urls.first?.url ?? "\(model.account.server)/\(postCollectionAlias)/" urlString = "\(baseURL)\(postSlug)" } else { - // This is a draft post, sho share the URL as server/postID + // This is a draft post, so share the URL as server/postID urlString = "\(model.account.server)/\(postId)" } diff --git a/macOS/PostEditor/PostEditorSharingPicker.swift b/macOS/PostEditor/PostEditorSharingPicker.swift index 02f7c96..b75a65a 100644 --- a/macOS/PostEditor/PostEditorSharingPicker.swift +++ b/macOS/PostEditor/PostEditorSharingPicker.swift @@ -2,20 +2,22 @@ import SwiftUI struct PostEditorSharingPicker: NSViewRepresentable { @Binding var isPresented: Bool - var sharingItems: [Any] = [] + var sharingItems: [NSURL] = [] func makeNSView(context: Context) -> some NSView { let view = NSView() - let picker = NSSharingServicePicker(items: sharingItems) - picker.delegate = context.coordinator - - DispatchQueue.main.async { - picker.show(relativeTo: .zero, of: view, preferredEdge: .minY) - } return view } func updateNSView(_ nsView: NSViewType, context: Context) { + if isPresented { + let picker = NSSharingServicePicker(items: sharingItems) + picker.delegate = context.coordinator + + DispatchQueue.main.async { + picker.show(relativeTo: .zero, of: nsView, preferredEdge: .minY) + } + } } func makeCoordinator() -> Coordinator { @@ -24,10 +26,38 @@ struct PostEditorSharingPicker: NSViewRepresentable { class Coordinator: NSObject, NSSharingServicePickerDelegate { let owner: PostEditorSharingPicker + init(owner: PostEditorSharingPicker) { self.owner = owner } + func sharingServicePicker( + _ sharingServicePicker: NSSharingServicePicker, + sharingServicesForItems items: [Any], + proposedSharingServices proposedServices: [NSSharingService] + ) -> [NSSharingService] { + guard let copyIcon = NSImage(systemSymbolName: "doc.on.doc", accessibilityDescription: "Copy URL") else { + return proposedServices + } + + var share = proposedServices + let copyService = NSSharingService( + title: "Copy URL", + image: copyIcon, + alternateImage: copyIcon, + handler: { + if let url = items.first as? NSURL, let urlString = url.absoluteString { + let clipboard = NSPasteboard.general + clipboard.clearContents() + clipboard.setString(urlString, forType: .string) + } + } + ) + share.insert(copyService, at: 0) + share.insert(NSSharingService(named: .addToSafariReadingList)!, at: 1) + return share + } + func sharingServicePicker( _ sharingServicePicker: NSSharingServicePicker, didChoose service: NSSharingService? @@ -35,5 +65,6 @@ struct PostEditorSharingPicker: NSViewRepresentable { sharingServicePicker.delegate = nil self.owner.isPresented = false } + } }