proc newWatchout*(
pattern: string,
onChange: WatchCallback,
onFound: WatchCallback,
onDelete: WatchCallback = nil,
delay: range[100..5000] = 350,
recursive = false,
browserSync: WatchoutBrowserSync = nil
): Watchout =
result = Watchout(
pattern: pattern,
delay: delay,
onChange: onChange,
onFound: onFound,
onDelete: onDelete,
recursive: recursive,
browserSync: browserSync
)
initLock(result.L) # 🔒 Ensure the lock is initialized on Windows
proc newWatchout*(
dirs: seq[string],
onChange: WatchCallback,
onFound: WatchCallback,
onDelete: WatchCallback = nil,
delay: range[100..5000] = 350,
recursive = false,
ext: seq[string] = @[],
browserSync: WatchoutBrowserSync = nil
): Watchout =
result = Watchout(
dirs: dirs,
delay: delay,
onChange: onChange,
onFound: onFound,
onDelete: onDelete,
recursive: recursive,
ext: ext,
browserSync: browserSync
)
initLock(result.L) # 🔒 Fix for Windows uninitialized lock crash
proc start*(w: Watchout) =
var thr: Thread[Watchout]
createThread(thr, startThread, w)
while true:
sleep(1000) # keeps main thread alive