Browse Source

Create .writeas dir on start if non-existent

master
Matt Baer 4 years ago
parent
commit
35133ae7c4
4 changed files with 26 additions and 2 deletions
  1. +4
    -0
      writeas.xcodeproj/project.pbxproj
  2. +10
    -0
      writeas/AppDelegate.swift
  3. +11
    -0
      writeas/Constants.swift
  4. +1
    -2
      writeas/ViewController.swift

+ 4
- 0
writeas.xcodeproj/project.pbxproj View File

@@ -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 = "<group>"; };
33071648B80C4188CAC44CA1 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
C98EE9AB1F29532F002F646E /* writeas */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = writeas; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
@@ -107,6 +109,7 @@
C99B91101C33841F00A91990 /* Assets.xcassets */,
C99B91121C33841F00A91990 /* Main.storyboard */,
C99B91151C33841F00A91990 /* Info.plist */,
33071648B80C4188CAC44CA1 /* Constants.swift */,
);
path = writeas;
sourceTree = "<group>";
@@ -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;
};


+ 10
- 0
writeas/AppDelegate.swift View File

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


+ 11
- 0
writeas/Constants.swift View File

@@ -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"
}

+ 1
- 2
writeas/ViewController.swift View File

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


Loading…
Cancel
Save