mirror of
https://github.com/safing/portmaster
synced 2025-09-02 18:49:14 +00:00
Wait with first update cycle until online
This commit is contained in:
parent
9daa76717f
commit
5d15ec8cc7
7 changed files with 28 additions and 26 deletions
|
@ -52,7 +52,7 @@ func prep() error {
|
|||
}
|
||||
|
||||
if err := module.RegisterEventHook(
|
||||
"netenv",
|
||||
netenv.ModuleName,
|
||||
netenv.OnlineStatusChangedEvent,
|
||||
"Check for blocklist updates",
|
||||
func(ctx context.Context, _ interface{}) error {
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
// Event Names
|
||||
const (
|
||||
ModuleName = "netenv"
|
||||
NetworkChangedEvent = "network changed"
|
||||
OnlineStatusChangedEvent = "online status changed"
|
||||
)
|
||||
|
@ -15,7 +16,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
module = modules.Register("netenv", prep, start, nil)
|
||||
module = modules.Register(ModuleName, prep, start, nil)
|
||||
module.RegisterEvent(NetworkChangedEvent, true)
|
||||
module.RegisterEvent(OnlineStatusChangedEvent, true)
|
||||
}
|
||||
|
|
|
@ -10,12 +10,12 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/safing/portbase/notifications"
|
||||
"github.com/tevino/abool"
|
||||
|
||||
"github.com/safing/portbase/log"
|
||||
"github.com/safing/portbase/notifications"
|
||||
"github.com/safing/portmaster/network/netutils"
|
||||
|
||||
"github.com/tevino/abool"
|
||||
"github.com/safing/portmaster/updates"
|
||||
)
|
||||
|
||||
// OnlineStatus represent a state of connectivity to the Internet.
|
||||
|
@ -200,13 +200,18 @@ func updateOnlineStatus(status OnlineStatus, portalURL *url.URL, comment string)
|
|||
|
||||
// trigger event
|
||||
if changed {
|
||||
module.TriggerEvent(OnlineStatusChangedEvent, nil)
|
||||
module.TriggerEvent(OnlineStatusChangedEvent, status)
|
||||
if status == StatusPortal {
|
||||
log.Infof(`netenv: setting online status to %s at "%s" (%s)`, status, portalURL, comment)
|
||||
} else {
|
||||
log.Infof("netenv: setting online status to %s (%s)", status, comment)
|
||||
}
|
||||
triggerNetworkChangeCheck()
|
||||
|
||||
// Trigger update check when coming (semi) online.
|
||||
if Online() {
|
||||
_ = updates.TriggerUpdate(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ func start() error {
|
|||
triggerAutopilot()
|
||||
|
||||
err := module.RegisterEventHook(
|
||||
"netenv",
|
||||
netenv.ModuleName,
|
||||
netenv.OnlineStatusChangedEvent,
|
||||
"update online status in system status",
|
||||
func(_ context.Context, _ interface{}) error {
|
||||
|
|
|
@ -14,8 +14,7 @@ func registerAPIEndpoints() error {
|
|||
Write: api.PermitUser,
|
||||
BelongsTo: module,
|
||||
ActionFunc: func(_ *api.Request) (msg string, err error) {
|
||||
forceUpdate.Set()
|
||||
if err := TriggerUpdate(); err != nil {
|
||||
if err := TriggerUpdate(true); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return "triggered update check", nil
|
||||
|
|
|
@ -98,14 +98,14 @@ func registerConfig() error {
|
|||
}
|
||||
|
||||
func initConfig() {
|
||||
releaseChannel = config.GetAsString(helper.ReleaseChannelKey, helper.ReleaseChannelStable)
|
||||
releaseChannel = config.Concurrent.GetAsString(helper.ReleaseChannelKey, helper.ReleaseChannelStable)
|
||||
initialReleaseChannel = releaseChannel()
|
||||
previousReleaseChannel = releaseChannel()
|
||||
|
||||
enableUpdates = config.GetAsBool(enableUpdatesKey, true)
|
||||
enableUpdates = config.Concurrent.GetAsBool(enableUpdatesKey, true)
|
||||
updatesCurrentlyEnabled = enableUpdates()
|
||||
|
||||
devMode = config.GetAsBool(cfgDevModeKey, false)
|
||||
devMode = config.Concurrent.GetAsBool(cfgDevModeKey, false)
|
||||
previousDevMode = devMode()
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ func updateRegistryConfig(_ context.Context, _ interface{}) error {
|
|||
|
||||
if updatesCurrentlyEnabled {
|
||||
module.Resolve("")
|
||||
if err := TriggerUpdate(); err != nil {
|
||||
if err := TriggerUpdate(false); err != nil {
|
||||
log.Warningf("updates: failed to trigger update: %s", err)
|
||||
}
|
||||
log.Infof("updates: automatic updates are now enabled")
|
||||
|
|
|
@ -7,13 +7,12 @@ import (
|
|||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/safing/portmaster/updates/helper"
|
||||
|
||||
"github.com/safing/portbase/dataroot"
|
||||
"github.com/safing/portbase/log"
|
||||
"github.com/safing/portbase/modules"
|
||||
"github.com/safing/portbase/notifications"
|
||||
"github.com/safing/portbase/updater"
|
||||
"github.com/safing/portmaster/updates/helper"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -148,8 +147,7 @@ func start() error {
|
|||
if !disableTaskSchedule {
|
||||
updateTask.
|
||||
Repeat(1 * time.Hour).
|
||||
MaxDelay(30 * time.Minute).
|
||||
Schedule(time.Now().Add(10 * time.Second))
|
||||
MaxDelay(30 * time.Minute)
|
||||
}
|
||||
|
||||
if updateASAP {
|
||||
|
@ -167,18 +165,19 @@ func start() error {
|
|||
}
|
||||
|
||||
// TriggerUpdate queues the update task to execute ASAP.
|
||||
func TriggerUpdate() error {
|
||||
func TriggerUpdate(force bool) error {
|
||||
switch {
|
||||
case !module.OnlineSoon():
|
||||
return fmt.Errorf("updates module is disabled")
|
||||
|
||||
case !force && !enableUpdates():
|
||||
return fmt.Errorf("automatic updating is disabled")
|
||||
|
||||
case !module.Online():
|
||||
updateASAP = true
|
||||
|
||||
case forceUpdate.IsNotSet() && !enableUpdates():
|
||||
return fmt.Errorf("automatic updating is disabled")
|
||||
|
||||
default:
|
||||
forceUpdate.Set()
|
||||
updateTask.StartASAP()
|
||||
}
|
||||
|
||||
|
@ -200,16 +199,14 @@ func DisableUpdateSchedule() error {
|
|||
}
|
||||
|
||||
func checkForUpdates(ctx context.Context) (err error) {
|
||||
if !updatesCurrentlyEnabled && !forceUpdate.IsSet() {
|
||||
log.Debugf("updates: automatic updates are disabled")
|
||||
if !forceUpdate.SetToIf(true, false) && !enableUpdates() {
|
||||
log.Warningf("updates: automatic updates are disabled")
|
||||
return nil
|
||||
}
|
||||
forceUpdate.UnSet()
|
||||
|
||||
defer log.Debugf("updates: finished checking for updates")
|
||||
|
||||
defer func() {
|
||||
if err == nil {
|
||||
log.Infof("updates: successfully checked for updates")
|
||||
module.Resolve(updateFailed)
|
||||
notifications.Notify(¬ifications.Notification{
|
||||
EventID: updateSuccess,
|
||||
|
|
Loading…
Add table
Reference in a new issue