Ver a proveniência

Show notification after post published

master
Matt Baer há 6 anos
ascendente
cometimento
aa97cc04b7
1 ficheiros alterados com 29 adições e 9 eliminações
  1. +29
    -9
      writeas/ViewController.swift

+ 29
- 9
writeas/ViewController.swift Ver ficheiro

@@ -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) {


Carregando…
Cancelar
Guardar