Skip to content

Commit

Permalink
Compare file info list every 3 seconds.
Browse files Browse the repository at this point in the history
  • Loading branch information
luosheng committed Nov 11, 2015
1 parent ba78f0c commit 1601b7c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions OpenSim/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,27 @@ class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!

var statusItem: NSStatusItem!
var fileInfoList: [FileInfo?]!

func applicationDidFinishLaunching(aNotification: NSNotification) {
fileInfoList = buildFileInfoList()
let timer = NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: "checkFileInfoList:", userInfo: nil, repeats: true)
NSRunLoop.currentRunLoop().addTimer(timer, forMode: NSRunLoopCommonModes)
buildMenu()
}

private func buildFileInfoList() -> [FileInfo?] {
return try! NSFileManager.defaultManager().contentsOfDirectoryAtURL(URLHelper.deviceURL, includingPropertiesForKeys: FileInfo.prefetchedProperties, options: .SkipsSubdirectoryDescendants).map { FileInfo(URL: $0) }
}

func checkFileInfoList(timer: NSTimer) {
let newFileInfoList = buildFileInfoList()
if fileInfoList != newFileInfoList {
print("yes")
}
fileInfoList = newFileInfoList
}

func buildMenu() {
statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(NSVariableStatusItemLength)
statusItem.image = NSImage(named: "menubar")
Expand Down

0 comments on commit 1601b7c

Please sign in to comment.