mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added ip change counter to the ip change notification that prevents notification when ip disappears for 3 reads
This commit is contained in:
@@ -35,6 +35,11 @@ class Notifications: NotificationsWrapper {
|
||||
private var publicIP: String?
|
||||
private var wifi: String?
|
||||
|
||||
private var localIPCount: Int = 0
|
||||
private var localIPThreshold: Int = 3
|
||||
private var publicIPCount: Int = 0
|
||||
private var publicIPThreshold: Int = 3
|
||||
|
||||
private var connectionInit: Bool = false
|
||||
private var interfaceInit: Bool = false
|
||||
private var localIPInit: Bool = false
|
||||
@@ -119,6 +124,8 @@ class Notifications: NotificationsWrapper {
|
||||
if self.localIPState {
|
||||
let addr = value.laddr.v4 ?? value.laddr.v6
|
||||
if addr != self.localIP {
|
||||
self.localIPCount += 1
|
||||
if self.localIPCount >= self.localIPThreshold {
|
||||
var subtitle = ""
|
||||
if let prev = self.localIP {
|
||||
subtitle = localizedString("Previous IP", prev)
|
||||
@@ -130,13 +137,19 @@ class Notifications: NotificationsWrapper {
|
||||
subtitle += localizedString("New IP", new)
|
||||
}
|
||||
self.newNotification(id: self.localID, title: localizedString("Local IP changed"), subtitle: subtitle)
|
||||
}
|
||||
self.localIP = addr
|
||||
self.localIPCount = 0
|
||||
}
|
||||
} else {
|
||||
self.localIPCount = 0
|
||||
}
|
||||
}
|
||||
|
||||
if self.publicIPState {
|
||||
let addr = value.raddr.v4 ?? value.raddr.v6
|
||||
if addr != self.publicIP {
|
||||
self.publicIPCount += 1
|
||||
if self.publicIPCount >= self.publicIPThreshold {
|
||||
var subtitle = ""
|
||||
if let prev = self.publicIP {
|
||||
subtitle = localizedString("Previous IP", prev)
|
||||
@@ -148,8 +161,12 @@ class Notifications: NotificationsWrapper {
|
||||
subtitle += localizedString("New IP", new)
|
||||
}
|
||||
self.newNotification(id: self.publicID, title: localizedString("Public IP changed"), subtitle: subtitle)
|
||||
}
|
||||
self.publicIP = addr
|
||||
self.publicIPCount = 0
|
||||
}
|
||||
} else {
|
||||
self.publicIPCount = 0
|
||||
}
|
||||
}
|
||||
|
||||
if self.wifiState {
|
||||
|
||||
Reference in New Issue
Block a user