diff --git a/writeas.xcodeproj/project.pbxproj b/writeas.xcodeproj/project.pbxproj index c701ed4..560f5f0 100644 --- a/writeas.xcodeproj/project.pbxproj +++ b/writeas.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 330711A70F03BFB84FB889AB /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33071648B80C4188CAC44CA1 /* Constants.swift */; }; 33071D332D5799D36FBC1DDD /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3307150C0D2CA1C8A71C5E26 /* Preferences.swift */; }; C98EE9AC1F29532F002F646E /* writeas in Resources */ = {isa = PBXBuildFile; fileRef = C98EE9AB1F29532F002F646E /* writeas */; }; C9953E7D1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf in Resources */ = {isa = PBXBuildFile; fileRef = C9953E791F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf */; }; @@ -29,6 +30,7 @@ /* Begin PBXFileReference section */ 3307150C0D2CA1C8A71C5E26 /* Preferences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Preferences.swift; path = writeas/Preferences.swift; sourceTree = ""; }; + 33071648B80C4188CAC44CA1 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; C98EE9AB1F29532F002F646E /* writeas */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = writeas; sourceTree = ""; }; C9953E791F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf"; sourceTree = ""; }; C9953E7A1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf"; sourceTree = ""; }; @@ -107,6 +109,7 @@ C99B91101C33841F00A91990 /* Assets.xcassets */, C99B91121C33841F00A91990 /* Main.storyboard */, C99B91151C33841F00A91990 /* Info.plist */, + 33071648B80C4188CAC44CA1 /* Constants.swift */, ); path = writeas; sourceTree = ""; @@ -200,6 +203,7 @@ C99B910F1C33841E00A91990 /* ViewController.swift in Sources */, C99B910D1C33841E00A91990 /* AppDelegate.swift in Sources */, 33071D332D5799D36FBC1DDD /* Preferences.swift in Sources */, + 330711A70F03BFB84FB889AB /* Constants.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/writeas/AppDelegate.swift b/writeas/AppDelegate.swift index c983426..7b5129b 100644 --- a/writeas/AppDelegate.swift +++ b/writeas/AppDelegate.swift @@ -46,6 +46,16 @@ class AppDelegate: NSObject, NSApplicationDelegate { if vc == nil { vc = NSApplication.shared().mainWindow?.contentViewController as? ViewController } + + DispatchQueue.global(qos: .background).async { + if !FileManager.default.fileExists(atPath: Constants.draftDir, isDirectory: nil) { + do { + try FileManager.default.createDirectory(atPath: Constants.draftDir, withIntermediateDirectories: false, attributes: nil) + } catch let error as NSError { + print(error.localizedDescription); + } + } + } } @IBAction func toggleNightMode(_ sender: NSMenuItem) { diff --git a/writeas/Constants.swift b/writeas/Constants.swift new file mode 100644 index 0000000..4114327 --- /dev/null +++ b/writeas/Constants.swift @@ -0,0 +1,11 @@ +// +// Created by Matt Baer on 8/2/17. +// Copyright (c) 2017 A Bunch Tell. All rights reserved. +// + +import Foundation + +struct Constants { + static let draftDir = "\(NSHomeDirectory())/.writeas" + static let draftFile = "\(draftDir)/draft.txt" +} diff --git a/writeas/ViewController.swift b/writeas/ViewController.swift index 026e539..8598193 100644 --- a/writeas/ViewController.swift +++ b/writeas/ViewController.swift @@ -12,7 +12,6 @@ class ViewController: NSViewController, NSTextViewDelegate, NSUserNotificationCe @IBOutlet var writerText: NSTextView! - let draftFile = "\(NSHomeDirectory())/.writeas/draft.txt" override func viewDidLoad() { super.viewDidLoad() @@ -56,7 +55,7 @@ class ViewController: NSViewController, NSTextViewDelegate, NSUserNotificationCe } fileprivate func getDraftPath() -> URL? { - return URL(fileURLWithPath: draftFile) + return URL(fileURLWithPath: Constants.draftFile) } func saveDocument() {