-
-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add in-app feedback form (closes #145)
- Loading branch information
louis.pontoise
committed
Feb 5, 2020
1 parent
8a9264e
commit a5b6db9
Showing
17 changed files
with
215 additions
and
88 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import Cocoa | ||
import Foundation | ||
|
||
class FeedbackWindow: NSWindow, NSTextViewDelegate { | ||
var body: TextArea! | ||
var email: TextArea! | ||
var sendButton: NSButton! | ||
|
||
override init(contentRect: NSRect, styleMask style: StyleMask, backing backingStoreType: BackingStoreType, defer flag: Bool) { | ||
super.init(contentRect: .zero, styleMask: style, backing: backingStoreType, defer: flag) | ||
setupWindow() | ||
setupView() | ||
} | ||
|
||
func show() { | ||
App.shared.activate(ignoringOtherApps: true) | ||
makeKeyAndOrderFront(nil) | ||
} | ||
|
||
private func setupWindow() { | ||
title = "Send feedback" | ||
hidesOnDeactivate = false | ||
isReleasedWhenClosed = false | ||
styleMask.insert([.miniaturizable, .closable]) | ||
} | ||
|
||
private func setupView() { | ||
let intro = NSStackView(views: [ | ||
NSTextField(labelWithString: "Share improvement ideas, or report bugs."), | ||
HyperlinkLabel("View existing tickets", "https://github.com/lwouis/alt-tab-macos/issues"), | ||
]) | ||
intro.spacing = 4 | ||
sendButton = NSButton(title: "Send", target: nil, action: #selector(sendCallback)) | ||
sendButton.keyEquivalent = "\r" | ||
sendButton.isEnabled = false | ||
let buttons = NSStackView(views: [ | ||
NSButton(title: "Cancel", target: nil, action: #selector(cancelCallback)), | ||
sendButton, | ||
]) | ||
buttons.spacing = GridView.interPadding | ||
body = TextArea(80, 20, "I think the app could be improved with…") | ||
body.delegate = self | ||
email = TextArea(80, 1.1, "Optional: email (if you want a reply)") | ||
let view = GridView.make([ | ||
[intro], | ||
[body], | ||
[email], | ||
[buttons], | ||
]) | ||
view.cell(atColumnIndex: 0, rowIndex: 3).xPlacement = .trailing | ||
view.fit() | ||
setContentSize(view.fittingSize) | ||
contentView = view | ||
} | ||
|
||
func textDidChange(_ notification: Notification) { | ||
sendButton.isEnabled = !body.string.isEmpty | ||
} | ||
|
||
@objc | ||
private func cancelCallback(senderControl: NSControl) { | ||
close() | ||
} | ||
|
||
@objc | ||
private func sendCallback(senderControl: NSControl) { | ||
var request = URLRequest(url: URL(string: "https://api.github.com/repos/lwouis/alt-tab-macos/issues")!) | ||
request.httpMethod = "POST" | ||
request.addValue("application/json", forHTTPHeaderField: "Content-Type") | ||
request.addValue("application/json", forHTTPHeaderField: "Accept") | ||
// access token of the alt-tab-macos-bot github account, with scope repo > public_repo | ||
request.addValue("token 6ab65e11bb51e47835fe1f64970b1d7df0341653", forHTTPHeaderField: "Authorization") | ||
let preamble = "_This issue was opened by a bot after a user submitted feedback through the in-app form. Here is what they wrote:_\n\n> " | ||
let emailNote = !email.string.isEmpty ? "\n\nAuthor's email: " + email.string : "" | ||
let parameters: [String: Any] = [ | ||
"title": "[In-app feedback]", | ||
"body": preamble + body.string.replacingOccurrences(of: "\n", with: "\n> ") + emailNote | ||
] | ||
request.httpBody = try! JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted) | ||
URLSession.shared.dataTask(with: request, completionHandler: { data, response, error in | ||
if error != nil || response == nil || (response as! HTTPURLResponse).statusCode != 201 { | ||
debugPrint("HTTP call failed:", response, error) | ||
} | ||
}).resume() | ||
close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Cocoa | ||
|
||
class BaseLabel: NSTextView { | ||
convenience init(_ text: String) { | ||
self.init(frame: .zero) | ||
textContainer!.size.width = 1000 | ||
string = text | ||
setup() | ||
} | ||
|
||
convenience init(_ frame: NSRect, _ container: NSTextContainer?) { | ||
self.init(frame: frame, textContainer: container) | ||
setup() | ||
} | ||
|
||
private func setup() { | ||
drawsBackground = true | ||
backgroundColor = NSColor.blue | ||
isSelectable = false | ||
isEditable = false | ||
enabledTextCheckingTypes = 0 | ||
layoutManager!.ensureLayout(for: textContainer!) | ||
frame = layoutManager!.usedRect(for: textContainer!) | ||
fit(frame.size.width, frame.size.height) | ||
} | ||
} |
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
alt-tab-macos/ui/labels/HyperlinkLabel.swift → ...eric-components/text/HyperlinkLabel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Cocoa | ||
import Foundation | ||
|
||
class TextArea: NSTextView { | ||
static let paddingX = CGFloat(5) | ||
static let paddingY = CGFloat(10) | ||
@objc var placeholderAttributedString: NSAttributedString? | ||
|
||
convenience init(_ width: CGFloat, _ height: CGFloat, _ placeholder: String) { | ||
self.init(frame: .zero) | ||
font = NSFont.systemFont(ofSize: NSFont.systemFontSize) | ||
textContainerInset = NSSize(width: TextArea.paddingX, height: TextArea.paddingY) | ||
fit(font!.xHeight * width + TextArea.paddingX * 2, NSFont.systemFontSize * height + TextArea.paddingY * 2) | ||
placeholderAttributedString = NSAttributedString(string: placeholder, attributes: [NSAttributedString.Key.foregroundColor: NSColor.gray]) | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
alt-tab-macos/ui/labels/TextField.swift → ...i/generic-components/text/TextField.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 4 additions & 33 deletions
37
alt-tab-macos/ui/labels/Labels.swift → ...main-window/CollectionViewItemTitle.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters