From 05851fb728741251a2318a48dcd55e5a4044bbde Mon Sep 17 00:00:00 2001 From: lwouis Date: Thu, 21 Nov 2024 10:12:53 +0100 Subject: [PATCH] feat: in-app feedback form now requires a title --- src/ui/FeedbackWindow.swift | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ui/FeedbackWindow.swift b/src/ui/FeedbackWindow.swift index ba5041f2..9b35c83c 100644 --- a/src/ui/FeedbackWindow.swift +++ b/src/ui/FeedbackWindow.swift @@ -7,6 +7,7 @@ class FeedbackWindow: NSWindow { let base64Token = Bundle.main.object(forInfoDictionaryKey: "FeedbackToken") as! String return String(data: Data(base64Encoded: base64Token)!, encoding: .utf8)! }() + var issueTitle: TextArea! var body: TextArea! var email: TextArea! var sendButton: NSButton! @@ -44,15 +45,15 @@ class FeedbackWindow: NSWindow { sendButton, ]) buttons.spacing = GridView.interPadding - body = TextArea(80, 12, NSLocalizedString("I think the app could be improved with…", comment: ""), { () -> Void in - self.sendButton.isEnabled = !self.body.stringValue.isEmpty - }) + issueTitle = TextArea(80, 1, NSLocalizedString("Title", comment: ""), checkEmptyFields) + body = TextArea(80, 12, NSLocalizedString("I think the app could be improved with…", comment: ""), checkEmptyFields) email = TextArea(80, 1, NSLocalizedString("Optional: email (if you want a reply)", comment: "")) debugProfile = NSButton(checkboxWithTitle: NSLocalizedString("Send debug profile (CPU, memory, etc)", comment: ""), target: nil, action: nil) debugProfile.state = .on let warning = BoldLabel(NSLocalizedString("All data from this form will be made public, as a ticket on github.com", comment: "")) let view = GridView([ [header], + [issueTitle], [body], [email], [debugProfile], @@ -65,6 +66,10 @@ class FeedbackWindow: NSWindow { contentView = view } + func checkEmptyFields() { + sendButton.isEnabled = !body.stringValue.isEmpty && !issueTitle.stringValue.isEmpty + } + // allow to close with the escape key @objc func cancel(_ sender: Any?) { close() @@ -104,8 +109,8 @@ class FeedbackWindow: NSWindow { // access token of the alt-tab-macos-bot github account, with scope repo > public_repo request.addValue("token " + FeedbackWindow.token, forHTTPHeaderField: "Authorization") request.httpBody = try! JSONSerialization.data(withJSONObject: [ - "title": "[In-app feedback]", - "body": assembleBody() + "title": issueTitle.stringValue, + "body": assembleBody(), ]) return request }