(_ *mgr.WorkerCtx)
| 54 | var isFirstNotification = true |
| 55 | |
| 56 | func suggestUsingStaleCacheTask(_ *mgr.WorkerCtx) error { |
| 57 | scheduleNextCall := true |
| 58 | switch { |
| 59 | case useStaleCache() || useStaleCacheConfigOption.IsSetByUser() || isNotificationSuppressed(): |
| 60 | // If setting is already active, disable task repeating. |
| 61 | scheduleNextCall = false |
| 62 | |
| 63 | // Delete local reference, if used. |
| 64 | if suggestUsingStaleCacheNotification != nil { |
| 65 | suggestUsingStaleCacheNotification.Delete() |
| 66 | suggestUsingStaleCacheNotification = nil |
| 67 | } |
| 68 | |
| 69 | case suggestUsingStaleCacheNotification != nil: |
| 70 | // Check if notification is already active. |
| 71 | |
| 72 | suggestUsingStaleCacheNotification.Lock() |
| 73 | defer suggestUsingStaleCacheNotification.Unlock() |
| 74 | if suggestUsingStaleCacheNotification.Meta().IsDeleted() { |
| 75 | // Reset local reference if notification was deleted. |
| 76 | suggestUsingStaleCacheNotification = nil |
| 77 | } |
| 78 | |
| 79 | case getSlowQueriesSensorValue() > 100*time.Millisecond: |
| 80 | log.Warningf( |
| 81 | "resolver: suggesting user to use stale dns cache with avg query time of %s for config and system resolvers", |
| 82 | getSlowQueriesSensorValue().Round(time.Millisecond), |
| 83 | ) |
| 84 | |
| 85 | const actionSuppressID = "suppress" |
| 86 | |
| 87 | // Notify user. |
| 88 | suggestUsingStaleCacheNotification = ¬ifications.Notification{ |
| 89 | EventID: "resolver:suggest-using-stale-cache", |
| 90 | Type: notifications.Info, |
| 91 | Title: "Speed Up Website Loading", |
| 92 | Message: "Portmaster has detected that websites may load slower because DNS queries are currently slower than expected. You may want to switch your DNS provider or enable using expired DNS cache entries for better performance.", |
| 93 | ShowOnSystem: isFirstNotification && getSlowQueriesSensorValue() > 500*time.Millisecond, |
| 94 | Expires: time.Now().Add(10 * time.Minute).Unix(), |
| 95 | AvailableActions: []*notifications.Action{ |
| 96 | { |
| 97 | Text: "Open Setting", |
| 98 | Type: notifications.ActionTypeOpenSetting, |
| 99 | Payload: ¬ifications.ActionTypeOpenSettingPayload{ |
| 100 | Key: CfgOptionUseStaleCacheKey, |
| 101 | }, |
| 102 | Visibility: notifications.ActionVisibilityInAppOnly, |
| 103 | }, |
| 104 | { |
| 105 | ID: actionSuppressID, |
| 106 | Text: "Don't show again", |
| 107 | Visibility: notifications.ActionVisibilityDetailed, |
| 108 | }, |
| 109 | { |
| 110 | ID: "ack", |
| 111 | Text: "Got it!", |
| 112 | }, |
| 113 | }, |
nothing calls this directly
no test coverage detected