From 579db0c8891c2bd14322a31d9b1cc86dfa47077f Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Mon, 17 Apr 2023 10:27:01 -0400 Subject: [PATCH] Add "Create Log Post" command to Post menu (#243) --- Shared/WriteFreely_MultiPlatformApp.swift | 10 +---- .../project.pbxproj | 8 +++- macOS/Navigation/HelpCommands.swift | 47 ++++++++++++++++++++++ 3 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 macOS/Navigation/HelpCommands.swift diff --git a/Shared/WriteFreely_MultiPlatformApp.swift b/Shared/WriteFreely_MultiPlatformApp.swift index bb6974a..b121314 100644 --- a/Shared/WriteFreely_MultiPlatformApp.swift +++ b/Shared/WriteFreely_MultiPlatformApp.swift @@ -105,16 +105,8 @@ struct WriteFreely_MultiPlatformApp: App { SidebarCommands() #if os(macOS) PostCommands(model: model) + HelpCommands(model: model) #endif - CommandGroup(after: .help) { - Button("Visit Support Forum") { - #if os(macOS) - NSWorkspace().open(model.helpURL) - #else - UIApplication.shared.open(model.helpURL) - #endif - } - } ToolbarCommands() TextEditingCommands() } diff --git a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj index cba8823..2b127fa 100644 --- a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj +++ b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj @@ -137,6 +137,7 @@ 17DFDE8C251D309400A25F31 /* OpenSans-License.txt in Resources */ = {isa = PBXBuildFile; fileRef = 17DFDE86251D309400A25F31 /* OpenSans-License.txt */; }; 17E5DF8A2543610700DCDC9B /* PostTextEditingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17E5DF892543610700DCDC9B /* PostTextEditingView.swift */; }; 375A67E828FC555C007A1AC0 /* MultilineTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 375A67E728FC555C007A1AC0 /* MultilineTextView.swift */; }; + 3779389729EC0C880032D6C1 /* HelpCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3779389629EC0C880032D6C1 /* HelpCommands.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -268,6 +269,7 @@ 17DFDE86251D309400A25F31 /* OpenSans-License.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "OpenSans-License.txt"; sourceTree = ""; }; 17E5DF892543610700DCDC9B /* PostTextEditingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostTextEditingView.swift; sourceTree = ""; }; 375A67E728FC555C007A1AC0 /* MultilineTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultilineTextView.swift; sourceTree = ""; }; + 3779389629EC0C880032D6C1 /* HelpCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelpCommands.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -455,6 +457,7 @@ children = ( 17BC617825715068003363CA /* ActivePostToolbarView.swift */, 1780F6EE25895EDB00FE45FF /* PostCommands.swift */, + 3779389629EC0C880032D6C1 /* HelpCommands.swift */, ); path = Navigation; sourceTree = ""; @@ -970,6 +973,7 @@ 1727526728099802003D0A6A /* ErrorConstants.swift in Sources */, 17479F152583D8E40072B7FB /* PostEditorSharingPicker.swift in Sources */, 17480CA6251272EE00EB7765 /* Bundle+AppVersion.swift in Sources */, + 3779389729EC0C880032D6C1 /* HelpCommands.swift in Sources */, 17C42E662509237800072984 /* PostListFilteredView.swift in Sources */, 17120DAD24E1B99F002B9F6C /* AccountLoginView.swift in Sources */, 17D4926727947D780035BD7E /* MacUpdatesViewModel.swift in Sources */, @@ -1278,7 +1282,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 707; + CURRENT_PROJECT_VERSION = 708; DEVELOPMENT_TEAM = TPPAB4YBA6; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; @@ -1305,7 +1309,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 707; + CURRENT_PROJECT_VERSION = 708; DEVELOPMENT_TEAM = TPPAB4YBA6; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; diff --git a/macOS/Navigation/HelpCommands.swift b/macOS/Navigation/HelpCommands.swift new file mode 100644 index 0000000..c465aeb --- /dev/null +++ b/macOS/Navigation/HelpCommands.swift @@ -0,0 +1,47 @@ +import SwiftUI + +struct HelpCommands: Commands { + @ObservedObject var model: WriteFreelyModel + + private let logger = Logging(for: String(describing: PostCommands.self)) + + var body: some Commands { + CommandGroup(replacing: .help) { + Button("Visit Support Forum") { + NSWorkspace().open(model.helpURL) + } + Button(action: createLogsPost, label: { Text("Generate Log for Support") }) + } + } + + private func createLogsPost() { + logger.log("Generating local log post...") + + // Show the spinner going in the post list + model.isProcessingRequest = true + + DispatchQueue.main.asyncAfter(deadline: .now()) { + // Unset selected post and collection and navigate to local drafts. + self.model.selectedPost = nil + self.model.selectedCollection = nil + self.model.showAllPosts = false + + // Create the new log post. + let newLogPost = model.editor.generateNewLocalPost(withFont: 2) + newLogPost.title = "Logs For Support" + var postBody: [String] = [ + "WriteFreely-Multiplatform v\(Bundle.main.appMarketingVersion) (\(Bundle.main.appBuildVersion))", + "Generated \(Date())", + "" + ] + postBody.append(contentsOf: logger.fetchLogs()) + newLogPost.body = postBody.joined(separator: "\n") + + // Hide the spinner in the post list and set the log post as active + self.model.isProcessingRequest = false + self.model.selectedPost = newLogPost + + logger.log("Generated local log post.") + } + } +}