Show notification after post published
This commit is contained in:
parent
378d335549
commit
aa97cc04b7
@ -8,7 +8,7 @@
|
||||
|
||||
import Cocoa
|
||||
|
||||
class ViewController: NSViewController, NSTextViewDelegate {
|
||||
class ViewController: NSViewController, NSTextViewDelegate, NSUserNotificationCenterDelegate {
|
||||
|
||||
@IBOutlet var writerText: NSTextView!
|
||||
|
||||
@ -25,6 +25,8 @@ class ViewController: NSViewController, NSTextViewDelegate {
|
||||
writerText.isAutomaticQuoteSubstitutionEnabled = false
|
||||
writerText.isAutomaticDashSubstitutionEnabled = false
|
||||
|
||||
NSUserNotificationCenter.default.delegate = self
|
||||
|
||||
// Do any additional setup after loading the view.
|
||||
writerText.delegate = self
|
||||
}
|
||||
@ -90,14 +92,32 @@ class ViewController: NSViewController, NSTextViewDelegate {
|
||||
func publish() {
|
||||
saveDocument()
|
||||
|
||||
let task = Process()
|
||||
task.launchPath = Bundle.main.executablePath! + "/../../Resources/writeas"
|
||||
let pipe = Pipe()
|
||||
task.standardInput = pipe
|
||||
task.launch()
|
||||
let fh: FileHandle = pipe.fileHandleForWriting
|
||||
fh.write(writerText.textStorage!.string.data(using: .utf8)!)
|
||||
fh.closeFile()
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
let task = Process()
|
||||
task.launchPath = Bundle.main.executablePath! + "/../../Resources/writeas"
|
||||
let pipe = Pipe()
|
||||
task.standardInput = pipe
|
||||
task.launch()
|
||||
let fh: FileHandle = pipe.fileHandleForWriting
|
||||
fh.write(self.writerText.textStorage!.string.data(using: .utf8)!)
|
||||
fh.closeFile()
|
||||
task.waitUntilExit()
|
||||
|
||||
DispatchQueue.main.async {
|
||||
var notification = NSUserNotification()
|
||||
|
||||
// All these values are optional
|
||||
notification.title = "Published!"
|
||||
notification.informativeText = "The link is copied — press ⌘+V to share it."
|
||||
notification.soundName = NSUserNotificationDefaultSoundName
|
||||
|
||||
NSUserNotificationCenter.default.deliver(notification)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func userNotificationCenter(_ center: NSUserNotificationCenter, shouldPresent notification: NSUserNotification) -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func toggle(isNight: Bool) {
|
||||
|
Loading…
Reference in New Issue
Block a user