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