Merge pull request #173 from safing/feature/minor-improvements

Add file-picker display hint and options for stopping task scheduling
This commit is contained in:
Daniel 2022-07-29 15:43:30 +02:00 committed by GitHub
commit edbe072412
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View file

@ -158,11 +158,14 @@ const (
// only sense together with the PossibleValues property // only sense together with the PossibleValues property
// of Option. // of Option.
DisplayHintOneOf = "one-of" DisplayHintOneOf = "one-of"
// DisplayHintOrdered Used to mark a list option as ordered. // DisplayHintOrdered is used to mark a list option as ordered.
// That is, the order of items is important and a user interface // That is, the order of items is important and a user interface
// is encouraged to provide the user with re-ordering support // is encouraged to provide the user with re-ordering support
// (like drag'n'drop). // (like drag'n'drop).
DisplayHintOrdered = "ordered" DisplayHintOrdered = "ordered"
// DisplayHintFilePicker is used to mark the option as being a file, which
// should give the option to use a file picker to select a local file from disk.
DisplayHintFilePicker = "file-picker"
) )
// Option describes a configuration option. // Option describes a configuration option.

View file

@ -201,26 +201,37 @@ func (t *Task) MaxDelay(maxDelay time.Duration) *Task {
return t return t
} }
// Schedule schedules the task for execution at the given time. // Schedule schedules the task for execution at the given time. A zero time will remove cancel the scheduled execution.
func (t *Task) Schedule(executeAt time.Time) *Task { func (t *Task) Schedule(executeAt time.Time) *Task {
t.lock.Lock() t.lock.Lock()
defer t.lock.Unlock() defer t.lock.Unlock()
t.executeAt = executeAt t.executeAt = executeAt
t.addToSchedule(false)
if executeAt.IsZero() {
t.removeFromQueues()
} else {
t.addToSchedule(false)
}
return t return t
} }
// Repeat sets the task to be executed in endless repeat at the specified interval. First execution will be after interval. Minimum repeat interval is one minute. // Repeat sets the task to be executed in endless repeat at the specified interval. First execution will be after interval. Minimum repeat interval is one minute. An interval of zero will disable repeating, but won't change the current schedule.
func (t *Task) Repeat(interval time.Duration) *Task { func (t *Task) Repeat(interval time.Duration) *Task {
// check minimum interval duration // check minimum interval duration
if interval < minRepeatDuration { if interval != 0 && interval < minRepeatDuration {
interval = minRepeatDuration interval = minRepeatDuration
} }
t.lock.Lock() t.lock.Lock()
defer t.lock.Unlock() defer t.lock.Unlock()
// Check if repeating should be disabled.
if interval == 0 {
t.repeat = 0
return t
}
t.repeat = interval t.repeat = interval
t.executeAt = time.Now().Add(t.repeat) t.executeAt = time.Now().Add(t.repeat)
t.addToSchedule(false) t.addToSchedule(false)