Added New Node Notification setting and notification

This commit is contained in:
benjaminfaershtein 2024-04-09 16:59:34 -07:00
parent f0109c9638
commit 102bbf521e
11 changed files with 39 additions and 0 deletions

View file

@ -66,6 +66,7 @@ extension UserDefaults {
case enableDetectionNotifications
case detectionSensorRole
case enableSmartPosition
case newNodeNotifications
case modemPreset
case firmwareVersion
case testIntEnum
@ -143,6 +144,9 @@ extension UserDefaults {
@UserDefault(.enableSmartPosition, defaultValue: false)
static var enableSmartPosition: Bool
@UserDefault(.newNodeNotifications, defaultValue: false)
static var newNodeNotifications: Bool
@UserDefault(.modemPreset, defaultValue: 0)
static var modemPreset: Int

View file

@ -177,6 +177,22 @@ func upsertNodeInfoPacket (packet: MeshPacket, context: NSManagedObjectContext)
newUser.role = Int32(newUserMessage.role.rawValue)
newUser.hwModel = String(describing: newUserMessage.hwModel).uppercased()
newNode.user = newUser
if (UserDefaults.newNodeNotifications){
let manager = LocalNotificationManager()
manager.notifications = [
Notification(
id: (UUID().uuidString),
title: "New Node",
subtitle: "\(newUser.longName ?? "unknown".localized)",
content: "New Node has been discovered",
target: "nodeInfo",
path: "meshtastic://nodeInfo"
)
]
manager.schedule()
}
}
} else {
let newUser = UserEntity(context: context)

View file

@ -12,6 +12,7 @@ struct AppSettings: View {
@StateObject var locationHelper = LocationHelper()
@State var provideLocation: Bool = UserDefaults.provideLocation
@State var enableSmartPosition: Bool = UserDefaults.enableSmartPosition
@State var newNodeNotifications: Bool = UserDefaults.newNodeNotifications
@State var useLegacyMap: Bool = UserDefaults.mapUseLegacy
@State var provideLocationInterval: Int = UserDefaults.provideLocationInterval
@State private var isPresentingCoreDataResetConfirm = false
@ -52,6 +53,12 @@ struct AppSettings: View {
}
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
}
Section(header: Text("Notifications")){
Toggle(isOn: $newNodeNotifications){
Label("appsettings.newNodeNotifications", systemImage: "bell.fill")
}
}
Section(header: Text("phone.gps")) {
if #available(iOS 17.0, macOS 14.0, *) {
GPSStatus()
@ -156,6 +163,10 @@ struct AppSettings: View {
self.bleManager.sendWantConfig()
}
}
.onChange(of: newNodeNotifications){ newNewNodeNotifications in
UserDefaults.newNodeNotifications = newNewNodeNotifications
}
.onChange(of: enableSmartPosition) { newEnableSmartPosition in
UserDefaults.enableSmartPosition = newEnableSmartPosition
}

View file

@ -339,3 +339,4 @@
"user.details"="Benutzer Details";
"voltage"="Voltage";
"waiting"="Warte...";
"appsettings.newNodeNotifications"="New Node Notifications";

View file

@ -354,3 +354,4 @@
"user.details"="User Details";
"voltage"="Voltage";
"waiting"="Waiting. . .";
"appsettings.newNodeNotifications"="New Node Notifications";

View file

@ -319,3 +319,4 @@
"user.details"="Détails de l'utilisateur";
"voltage"="Tension";
"waiting"="En attente . . .";
"appsettings.newNodeNotifications"="New Node Notifications";

View file

@ -343,3 +343,4 @@
"user.details"="פרטי משתמש";
"voltage"="וולטז'";
"waiting"="ממתין. . .";
"appsettings.newNodeNotifications"="New Node Notifications";

View file

@ -340,3 +340,4 @@
"user.details"="Szczegóły użytkownika";
"voltage"="Napięcie";
"waiting"="Czekam. . .";
"appsettings.newNodeNotifications"="New Node Notifications";

View file

@ -354,3 +354,4 @@
"user.details"="Användaruppgifter";
"voltage"="Spänning";
"waiting"="Väntar...";
"appsettings.newNodeNotifications"="New Node Notifications";

View file

@ -339,3 +339,4 @@
"user.details"="用户信息";
"voltage"="电压";
"waiting"="等待中...";
"appsettings.newNodeNotifications"="New Node Notifications";

View file

@ -338,3 +338,4 @@
"user.details"="使用者資料";
"voltage"="電壓";
"waiting"="等待中...";
"appsettings.newNodeNotifications"="New Node Notifications";