mirror of
https://github.com/seemoo-lab/openhaystack.git
synced 2026-02-14 17:49:54 +00:00
Instead of showing a mail button a small circle is shown next to the reload button.
The circle is orange if the mail plug-in is disabled
This commit is contained in:
@@ -21,7 +21,6 @@ struct ManageAccessoriesView: View {
|
||||
@Binding var focusedAccessory: Accessory?
|
||||
@Binding var accessoryToDeploy: Accessory?
|
||||
@Binding var showESP32DeploySheet: Bool
|
||||
var mailPluginIsActive: Bool
|
||||
|
||||
@State var showMailPopup = false
|
||||
|
||||
@@ -41,31 +40,7 @@ struct ManageAccessoriesView: View {
|
||||
}
|
||||
}
|
||||
.toolbar(content: {
|
||||
Spacer()
|
||||
|
||||
Button(action: {self.showMailPopup.toggle()}, label: {
|
||||
Label("Plugin state", systemImage: "envelope")
|
||||
.foregroundColor(self.mailPluginIsActive ? nil : .red)
|
||||
})
|
||||
.help(self.mailPluginIsActive ? "Mail plug-in is active" : "Cannot connect to Mail plug-in")
|
||||
.popover(isPresented: self.$showMailPopup) {
|
||||
self.mailStatePopup
|
||||
}
|
||||
|
||||
Button(action: self.importAccessories, label: {
|
||||
Label("Import accessories", systemImage: "square.and.arrow.down")
|
||||
})
|
||||
.help("Import accessories from a file")
|
||||
|
||||
Button(action: self.exportAccessories, label: {
|
||||
Label("Export accessories", systemImage: "square.and.arrow.up")
|
||||
})
|
||||
.help("Export all accessories to a file")
|
||||
|
||||
Button(action: self.addAccessory) {
|
||||
Label("Add accessory", systemImage: "plus")
|
||||
}
|
||||
.help("Add a new accessory")
|
||||
self.toolbarView
|
||||
})
|
||||
.sheet(
|
||||
isPresented: self.$showESP32DeploySheet,
|
||||
@@ -100,21 +75,27 @@ struct ManageAccessoriesView: View {
|
||||
|
||||
}
|
||||
|
||||
var mailStatePopup: some View {
|
||||
HStack {
|
||||
Image(systemName: "envelope")
|
||||
.foregroundColor(self.mailPluginIsActive ? .green : .red)
|
||||
|
||||
/// All toolbar buttons shown
|
||||
var toolbarView: some View {
|
||||
Group {
|
||||
Spacer()
|
||||
|
||||
if self.mailPluginIsActive {
|
||||
Text("The mail plug-in is up and running")
|
||||
}else {
|
||||
Text("Cannot connect to the mail plug-in. Open Apple Mail and make sure the plug-in is enabled")
|
||||
.lineLimit(10)
|
||||
.multilineTextAlignment(.leading)
|
||||
Button(action: self.importAccessories, label: {
|
||||
Label("Import accessories", systemImage: "square.and.arrow.down")
|
||||
})
|
||||
.help("Import accessories from a file")
|
||||
|
||||
Button(action: self.exportAccessories, label: {
|
||||
Label("Export accessories", systemImage: "square.and.arrow.up")
|
||||
})
|
||||
.help("Export all accessories to a file")
|
||||
|
||||
Button(action: self.addAccessory) {
|
||||
Label("Add accessory", systemImage: "plus")
|
||||
}
|
||||
.help("Add a new accessory")
|
||||
}
|
||||
.frame(maxWidth: 250)
|
||||
.padding()
|
||||
}
|
||||
|
||||
/// Delete an accessory from the list of accessories.
|
||||
@@ -167,6 +148,6 @@ struct ManageAccessoriesView_Previews: PreviewProvider {
|
||||
@State static var showESPSheet: Bool = true
|
||||
|
||||
static var previews: some View {
|
||||
ManageAccessoriesView(alertType: self.$alertType, focusedAccessory: self.$focussed, accessoryToDeploy: self.$deploy, showESP32DeploySheet: self.$showESPSheet, mailPluginIsActive: true)
|
||||
ManageAccessoriesView(alertType: self.$alertType, focusedAccessory: self.$focussed, accessoryToDeploy: self.$deploy, showESP32DeploySheet: self.$showESPSheet)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ struct OpenHaystackMainView: View {
|
||||
@State var isLoading = false
|
||||
@State var focusedAccessory: Accessory?
|
||||
@State var accessoryToDeploy: Accessory?
|
||||
@State var showMailPlugInPopover = false
|
||||
|
||||
@State var mailPluginIsActive = false
|
||||
|
||||
@@ -42,10 +43,9 @@ struct OpenHaystackMainView: View {
|
||||
alertType: self.$alertType,
|
||||
focusedAccessory: self.$focusedAccessory,
|
||||
accessoryToDeploy: self.$accessoryToDeploy,
|
||||
showESP32DeploySheet: self.$showESP32DeploySheet,
|
||||
mailPluginIsActive: self.mailPluginIsActive
|
||||
showESP32DeploySheet: self.$showESP32DeploySheet
|
||||
)
|
||||
.frame(minWidth: 280, idealWidth: 280, maxWidth: .infinity, minHeight: 300, idealHeight: 400, maxHeight: .infinity, alignment: .center)
|
||||
.frame(minWidth: 250, idealWidth: 280, maxWidth: .infinity, minHeight: 300, idealHeight: 400, maxHeight: .infinity, alignment: .center)
|
||||
|
||||
ZStack {
|
||||
AccessoryMapView(accessoryController: self.accessoryController, mapType: self.$mapType, focusedAccessory: self.focusedAccessory)
|
||||
@@ -61,15 +61,7 @@ struct OpenHaystackMainView: View {
|
||||
}
|
||||
.frame(minWidth: 500, idealWidth: 500, maxWidth: .infinity, minHeight: 300, idealHeight: 400, maxHeight: .infinity, alignment: .center)
|
||||
.toolbar(content: {
|
||||
Picker("", selection: self.$mapType) {
|
||||
Text("Satellite").tag(MKMapType.hybrid)
|
||||
Text("Standard").tag(MKMapType.standard)
|
||||
}
|
||||
.pickerStyle(SegmentedPickerStyle())
|
||||
Button(action: self.downloadLocationReports) {
|
||||
Label("Reload", systemImage: "arrow.clockwise")
|
||||
}
|
||||
.disabled(self.accessories.isEmpty)
|
||||
self.toolbarView
|
||||
})
|
||||
.alert(
|
||||
item: self.$alertType,
|
||||
@@ -112,6 +104,41 @@ struct OpenHaystackMainView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// All toolbar items shown
|
||||
var toolbarView: some View {
|
||||
Group {
|
||||
|
||||
Picker("", selection: self.$mapType) {
|
||||
Text("Satellite").tag(MKMapType.hybrid)
|
||||
Text("Standard").tag(MKMapType.standard)
|
||||
}
|
||||
.pickerStyle(SegmentedPickerStyle())
|
||||
|
||||
|
||||
Button(action: {
|
||||
if !self.mailPluginIsActive {
|
||||
self.showMailPlugInPopover.toggle()
|
||||
}else {
|
||||
self.downloadLocationReports()
|
||||
}
|
||||
|
||||
},label: {
|
||||
HStack {
|
||||
Circle()
|
||||
.fill(self.mailPluginIsActive ? Color.green : Color.orange)
|
||||
.frame(width: 8, height: 8)
|
||||
Label("Reload", systemImage: "arrow.clockwise")
|
||||
.disabled(!self.mailPluginIsActive)
|
||||
}
|
||||
|
||||
})
|
||||
.disabled(self.accessories.isEmpty)
|
||||
.popover(isPresented: $showMailPlugInPopover, content: {
|
||||
self.mailStatePopover
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func onAppear() {
|
||||
|
||||
@@ -137,7 +164,9 @@ struct OpenHaystackMainView: View {
|
||||
|
||||
/// Download the location reports for all current accessories. Shows an error if something fails, like plug-in is missing
|
||||
func downloadLocationReports() {
|
||||
self.isLoading = true
|
||||
self.accessoryController.downloadLocationReports { result in
|
||||
self.isLoading = false
|
||||
switch result {
|
||||
case .failure(let alert):
|
||||
if alert == .noReportsFound {
|
||||
@@ -150,6 +179,23 @@ struct OpenHaystackMainView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var mailStatePopover: some View {
|
||||
HStack {
|
||||
Image(systemName: "envelope")
|
||||
.foregroundColor(self.mailPluginIsActive ? .green : .red)
|
||||
|
||||
if self.mailPluginIsActive {
|
||||
Text("The mail plug-in is up and running")
|
||||
}else {
|
||||
Text("Cannot connect to the mail plug-in. Open Apple Mail and make sure the plug-in is enabled")
|
||||
.lineLimit(10)
|
||||
.multilineTextAlignment(.leading)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: 250)
|
||||
.padding()
|
||||
}
|
||||
|
||||
func deploy(accessory: Accessory) {
|
||||
self.accessoryToDeploy = accessory
|
||||
@@ -204,6 +250,7 @@ struct OpenHaystackMainView: View {
|
||||
}
|
||||
}
|
||||
self.mailPluginIsActive = true
|
||||
self.showMailPlugInPopover = false
|
||||
completion?(true)
|
||||
case .failure(let error):
|
||||
if let error = error as? AnisetteDataError, silent == false {
|
||||
|
||||
Reference in New Issue
Block a user