Skip to content

Commit

Permalink
Factor out client history & delete node buttons, and tidy up the avai…
Browse files Browse the repository at this point in the history
…lable actions in the list & detail screen
  • Loading branch information
72A12F4E committed Jul 9, 2024
1 parent 7a7a225 commit 4d68dc9
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 118 deletions.
8 changes: 8 additions & 0 deletions Meshtastic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
251926872C3BAE2200249DF5 /* NodeAlertsButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 251926862C3BAE2200249DF5 /* NodeAlertsButton.swift */; };
2519268A2C3BB1B200249DF5 /* ExchangePositionsButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 251926892C3BB1B200249DF5 /* ExchangePositionsButton.swift */; };
2519268C2C3BB52000249DF5 /* TraceRouteButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2519268B2C3BB52000249DF5 /* TraceRouteButton.swift */; };
251926902C3CB44900249DF5 /* ClientHistoryButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2519268F2C3CB44900249DF5 /* ClientHistoryButton.swift */; };
251926922C3CB52300249DF5 /* DeleteNodeButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 251926912C3CB52300249DF5 /* DeleteNodeButton.swift */; };
259792252C2F114500AD1659 /* ChannelEntityExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD58C5F12919AD3C00D5BEFB /* ChannelEntityExtension.swift */; };
259792262C2F114500AD1659 /* PositionEntityExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD5394FD276BA0EF00AD86B1 /* PositionEntityExtension.swift */; };
259792272C2F114500AD1659 /* TraceRouteEntityExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDE5B4052B227E3200FCDD05 /* TraceRouteEntityExtension.swift */; };
Expand Down Expand Up @@ -230,6 +232,8 @@
251926862C3BAE2200249DF5 /* NodeAlertsButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeAlertsButton.swift; sourceTree = "<group>"; };
251926892C3BB1B200249DF5 /* ExchangePositionsButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangePositionsButton.swift; sourceTree = "<group>"; };
2519268B2C3BB52000249DF5 /* TraceRouteButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TraceRouteButton.swift; sourceTree = "<group>"; };
2519268F2C3CB44900249DF5 /* ClientHistoryButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientHistoryButton.swift; sourceTree = "<group>"; };
251926912C3CB52300249DF5 /* DeleteNodeButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteNodeButton.swift; sourceTree = "<group>"; };
25AECD4E2C2F723200862C8E /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
6D825E612C34786C008DBEE4 /* CommonRegex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommonRegex.swift; sourceTree = "<group>"; };
6DA39D8D2A92DC52007E311C /* MeshtasticAppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeshtasticAppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -486,6 +490,8 @@
251926892C3BB1B200249DF5 /* ExchangePositionsButton.swift */,
251926862C3BAE2200249DF5 /* NodeAlertsButton.swift */,
2519268B2C3BB52000249DF5 /* TraceRouteButton.swift */,
2519268F2C3CB44900249DF5 /* ClientHistoryButton.swift */,
251926912C3CB52300249DF5 /* DeleteNodeButton.swift */,
);
path = Actions;
sourceTree = "<group>";
Expand Down Expand Up @@ -1132,6 +1138,7 @@
DD93800E2BA74D0C008BEC06 /* ChannelForm.swift in Sources */,
DD41A61529AB0035003C5A37 /* NodeWeatherForecast.swift in Sources */,
DDB6ABD628AE742000384BA1 /* BluetoothConfig.swift in Sources */,
251926902C3CB44900249DF5 /* ClientHistoryButton.swift in Sources */,
DDD5BB102C285FB3007E03CA /* AppLogFilter.swift in Sources */,
DD4640202AFF10F4002A5ECB /* WaypointForm.swift in Sources */,
DD769E0328D18BF1001A3F05 /* DeviceMetricsLog.swift in Sources */,
Expand Down Expand Up @@ -1236,6 +1243,7 @@
DDB75A212A12B954006ED576 /* LoRaSignalStrength.swift in Sources */,
DD6193752862F6E600E59241 /* ExternalNotificationConfig.swift in Sources */,
DD268D8E2BCC90E2008073AE /* RouteEnums.swift in Sources */,
251926922C3CB52300249DF5 /* DeleteNodeButton.swift in Sources */,
DDB6ABE428B13FFF00384BA1 /* DisplayEnums.swift in Sources */,
DD4975A52B147BA90026544E /* AmbientLightingConfig.swift in Sources */,
D93068D92B81509C0066FBC8 /* TapbackResponses.swift in Sources */,
Expand Down
33 changes: 33 additions & 0 deletions Meshtastic/Views/Nodes/Helpers/Actions/ClientHistoryButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import SwiftUI

struct ClientHistoryButton: View {
var bleManager: BLEManager

var connectedNode: NodeInfoEntity

var node: NodeInfoEntity

@State
private var isPresentingAlert = false

var body: some View {
Button {
isPresentingAlert = bleManager.requestStoreAndForwardClientHistory(
fromUser: connectedNode.user!,
toUser: node.user!
)
} label: {
Label(
"Client History",
systemImage: "envelope.arrow.triangle.branch"
)
}.alert(
"Client History Request Sent",
isPresented: $isPresentingAlert
) {
Button("OK") { }.keyboardShortcut(.defaultAction)
} message: {
Text("Any missed messages will be delivered again.")
}
}
}
51 changes: 51 additions & 0 deletions Meshtastic/Views/Nodes/Helpers/Actions/DeleteNodeButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import CoreData
import OSLog
import SwiftUI

struct DeleteNodeButton: View {
var bleManager: BLEManager

var context: NSManagedObjectContext

var connectedNode: NodeInfoEntity

var node: NodeInfoEntity

@State
private var isPresentingAlert = false

var body: some View {
Button(role: .destructive) {
isPresentingAlert = true
} label: {
Label {
Text("Delete Node")
} icon: {
Image(systemName: "trash")
.symbolRenderingMode(.multicolor)
}
}
.confirmationDialog(
"are.you.sure",
isPresented: $isPresentingAlert,
titleVisibility: .visible
) {
Button("Delete Node", role: .destructive) {
guard let deleteNode = getNodeInfo(
id: node.num,
context: context
) else {
Logger.data.error("Unable to find node info to delete node \(node.num)")
return
}
let success = bleManager.removeNode(
node: deleteNode,
connectedNodeNum: connectedNode.num
)
if !success {
Logger.data.error("Failed to delete node \(deleteNode.user?.longName ?? "unknown".localized)")
}
}
}
}
}
25 changes: 24 additions & 1 deletion Meshtastic/Views/Nodes/Helpers/NodeDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ struct NodeDetail: View {
@State private var showingShutdownConfirm: Bool = false
@State private var showingRebootConfirm: Bool = false

@ObservedObject var node: NodeInfoEntity
// The node the device is currently connected to
var connectedNode: NodeInfoEntity?

// The node information being displayed on the detail screen
@ObservedObject
var node: NodeInfoEntity

var columnVisibility = NavigationSplitViewVisibility.all

var favoriteNodeAction: some View {
Expand Down Expand Up @@ -242,6 +248,23 @@ struct NodeDetail: View {
bleManager: bleManager,
node: node
)

if let connectedNode {
if node.isStoreForwardRouter {
ClientHistoryButton(
bleManager: bleManager,
connectedNode: connectedNode,
node: node
)
}

DeleteNodeButton(
bleManager: bleManager,
context: context,
connectedNode: connectedNode,
node: node
)
}
}
}

Expand Down
Loading

0 comments on commit 4d68dc9

Please sign in to comment.