소스 검색

Show notification after post published

master
Matt Baer 6 년 전
부모
커밋
aa97cc04b7
1개의 변경된 파일29개의 추가작업 그리고 9개의 파일을 삭제
  1. +29
    -9
      writeas/ViewController.swift

+ 29
- 9
writeas/ViewController.swift 파일 보기

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


불러오는 중...
취소
저장