Re-read plan file if the file has a newer modification date than last time we checked.
This commit is contained in:
parent
050d11362c
commit
eb907e8e36
@ -33,8 +33,6 @@ proc parseDailyPlan(filename: string): seq[PlanItem] =
|
||||
|
||||
result = @[]
|
||||
|
||||
if not existsFile(filename): return
|
||||
|
||||
var parseState = BeforeHeading
|
||||
let planItemRe = re"\s*(\d{4})\s+(.*)"
|
||||
const timeFmt = "HHmm"
|
||||
@ -103,19 +101,31 @@ proc mainLoop(args: Table[string, Value]): void =
|
||||
loadConfig(0)
|
||||
signal(SIGHUP, loadConfig)
|
||||
var curDay: TimeInfo = getLocalTime(fromSeconds(0))
|
||||
var todaysFile = "nofile"
|
||||
var lastModTime = fromSeconds(0)
|
||||
var todaysItems: seq[PlanItem] = @[]
|
||||
|
||||
while true:
|
||||
|
||||
# Check the date
|
||||
let now = getLocalTime(getTime())
|
||||
var today = startOfDay(now)
|
||||
let today = startOfDay(now)
|
||||
|
||||
# Load today's plan items
|
||||
if today != curDay or todaysItems.len == 0:
|
||||
# If we need to change day, look for a new file.
|
||||
if today != curDay:
|
||||
curDay = today
|
||||
let todaysPlanFile =
|
||||
cfg.planDir & "/" & today.format(cfg.dateFmt) & "-plan.md"
|
||||
todaysItems = parseDailyPlan(todaysPlanFile)
|
||||
todaysFile = cfg.planDir & "/" & today.format(cfg.dateFmt) & "-plan.md"
|
||||
todaysItems = @[]
|
||||
lastModTime = fromSeconds(0)
|
||||
|
||||
# Check for our plan file.
|
||||
if fileExists(todaysFile):
|
||||
let fileModTime = getLastModificationTime(todaysFile)
|
||||
|
||||
# Check if the file has been modified or we have no itmes
|
||||
if fileModTime > lastModTime or todaysItems.len == 0:
|
||||
lastModTime = fileModTime
|
||||
todaysItems = parseDailyPlan(todaysFile)
|
||||
|
||||
# Check to see if any items are happening soon.
|
||||
let cutoff = now + seconds(cfg.notificationSecs)
|
||||
|
Loading…
x
Reference in New Issue
Block a user