drawthingsai / draw-things-community

The community repository for the Draw Things app.
https://drawthings.ai
GNU General Public License v3.0
41 stars 5 forks source link

proposed change for monitoring Scripts Folder #4

Open S1D1T1 opened 2 months ago

S1D1T1 commented 2 months ago

Attached code for dynamically updating list of scripts, and demo app. not a PR - I don't have a specific change for DT's startup -that code isn't in the repo.

ScriptsFolderMonitor.swift: source file with new class, ScriptsFolderMonitor. Add to project, or append it to Scripts.swift. ScriptsFolderMonitor class watches for changes in Scripts folder and triggers refresh of Scripts.availableScripts when they occur

DTTestbed.swift: demo use of ScriptsFolderMonitor class - creates the object at startup, ScriptsFolderMonitor.zip

S1D1T1 commented 2 months ago

piggybacking with issue of .DS_Store being shown- more robust directory listing to ignore the file would be Scripts.swift#L22-L28

    var scripts = ((try? FileManager.default.contentsOfDirectory(at: scriptsUrl,
                                                                 includingPropertiesForKeys:[],
                                                                 options:.skipsHiddenFiles)) ?? [])

this causes a downstream format change, requiring a few other code changes.

the 1-line fix is to keep existing code, and filter filenames beginning with '.'

liuliu commented 2 months ago

Hi, thanks. I am not sure FSEventStream sandbox policy, do you know a bit more details about this?

S1D1T1 commented 2 months ago

my sample app is signed, sandboxed, no entitlements set, it was able to monitor the folder. OS didn't prompt for user permission, since it only looked in the sandbox. I can't completely test with DT's environment, but it should be parallel. the sample app monitors the folder, ~/Library/Containers/DTTestbed/Data/Documents/Scripts.