mirror of
https://github.com/safing/portmaster
synced 2025-09-02 10:39:22 +00:00
Merge pull request #25 from safing/feature/trigger-updates
Trigger updates from other modules
This commit is contained in:
commit
a43a2fc3fe
1 changed files with 56 additions and 10 deletions
|
@ -39,8 +39,11 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
module *modules.Module
|
module *modules.Module
|
||||||
registry *updater.ResourceRegistry
|
registry *updater.ResourceRegistry
|
||||||
|
updateTask *modules.Task
|
||||||
|
updateASAP bool
|
||||||
|
disableTaskSchedule bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -106,19 +109,62 @@ func start() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// start updater task
|
// start updater task
|
||||||
module.NewTask("updater", func(ctx context.Context, task *modules.Task) error {
|
updateTask = module.NewTask("updater", func(ctx context.Context, task *modules.Task) error {
|
||||||
err := registry.DownloadUpdates(ctx)
|
return checkForUpdates(ctx)
|
||||||
if err != nil {
|
})
|
||||||
return fmt.Errorf("updates: failed to update: %s", err)
|
|
||||||
}
|
if !disableTaskSchedule {
|
||||||
module.TriggerEvent(ResourceUpdateEvent, nil)
|
updateTask.
|
||||||
return nil
|
Repeat(24 * time.Hour).
|
||||||
}).Repeat(24 * time.Hour).MaxDelay(1 * time.Hour).Schedule(time.Now().Add(10 * time.Second))
|
MaxDelay(1 * time.Hour).
|
||||||
|
Schedule(time.Now().Add(10 * time.Second))
|
||||||
|
}
|
||||||
|
|
||||||
|
if updateASAP {
|
||||||
|
updateTask.StartASAP()
|
||||||
|
}
|
||||||
|
|
||||||
// react to upgrades
|
// react to upgrades
|
||||||
return initUpgrader()
|
return initUpgrader()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TriggerUpdate queues the update task to execute ASAP.
|
||||||
|
func TriggerUpdate() error {
|
||||||
|
if !module.Online() {
|
||||||
|
if !module.OnlineSoon() {
|
||||||
|
return fmt.Errorf("module not enabled")
|
||||||
|
}
|
||||||
|
|
||||||
|
updateASAP = true
|
||||||
|
} else {
|
||||||
|
updateTask.StartASAP()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DisableUpdateSchedule disables the update schedule.
|
||||||
|
// If called, updates are only checked when TriggerUpdate()
|
||||||
|
// is called.
|
||||||
|
func DisableUpdateSchedule() error {
|
||||||
|
if module.OnlineSoon() {
|
||||||
|
return fmt.Errorf("module already online")
|
||||||
|
}
|
||||||
|
|
||||||
|
disableTaskSchedule = true
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkForUpdates(ctx context.Context) error {
|
||||||
|
err := registry.DownloadUpdates(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("updates: failed to update: %s", err)
|
||||||
|
}
|
||||||
|
module.TriggerEvent(ResourceUpdateEvent, nil)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func stop() error {
|
func stop() error {
|
||||||
if registry != nil {
|
if registry != nil {
|
||||||
return registry.Cleanup()
|
return registry.Cleanup()
|
||||||
|
|
Loading…
Add table
Reference in a new issue