Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Watcher / Auto-save issue #2

Open
fracturedpixel opened this issue Jul 25, 2016 · 3 comments
Open

File Watcher / Auto-save issue #2

fracturedpixel opened this issue Jul 25, 2016 · 3 comments

Comments

@fracturedpixel
Copy link

FileWatcher event closure is getting called in a few cases where I do not want it to be called for my use case. Monitoring a swift file in Xcode, if changes made, and switch to a different application without actually saving, the closure is called when the Auto-Save is fired off. Is there a way to look for actual saves only, and ignore the auto-saves?

@eonist
Copy link
Owner

eonist commented Jul 25, 2016

Wow. I'm impressed you got it working. This is how I use it:

let url:String = "~/Desktop/ElCapitan/advance/table/table.css"
StyleManager.addStylesByURL(url,true)
        fileWatcher = FileWatcher([url.tildePath])
        fileWatcher!.event = { event in
            //Swift.print(self)
            Swift.print(event.description)
            if(event.fileChange && event.path == url.tildePath) {
                StyleManager.addStylesByURL(url,true)
                ElementModifier.refreshSkin(self)
                ElementModifier.floatChildren(self)
            }
        }
        fileWatcher!.start()

What this code snippet does is that it watches an URL, and when you save the .css file and it has a change. Then the everything inside the closure is fired off. Now that being said, Maybe XCode Auto-Saves on app switch. In which case maybe you can assert if there actually was a change in the file, by comparing the file to a snapshot of the file you are monitoring.

Also, The file watching API apple provides is a bit tricky to use. Some things works, other things doesn't work. Well you can always get it working but it requires a bit of digging around to get working.

@eonist
Copy link
Owner

eonist commented Jul 25, 2016

Here is the transcript of a conversation I had with a fellow GitHubber when i Made FileWatcher: https://dl.dropboxusercontent.com/u/2559476/Event%20for%20file%20change%20%C2%B7%20Issue%20%231%20%C2%B7%20gurinderhans_SwiftFSWatcher.pdf Maybe it can yield more context in how my FileWatcher lib works.

@eonist
Copy link
Owner

eonist commented Jul 25, 2016

You can also turn of auto-saving in XCode: http://stackoverflow.com/questions/15468313/how-to-disable-auto-save-in-xcode-4-6

Maybe the content of the file is the same, but the modified date changes everytime you switch apps?, which in turn triggers the event.fileChange event type. There is also the event.modified event type, I can't Recall the difference between the fileChange and the modified flag.

If the modified flag works then I can add that as a note in the Code Documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants