Reorganize project, remove some dead code
This commit is contained in:
69
Soyuz/Views/PrinterConfigView.swift
Normal file
69
Soyuz/Views/PrinterConfigView.swift
Normal file
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// PrinterConfigView.swift
|
||||
// KlipperMon
|
||||
//
|
||||
// Created by maddiefuzz on 2/8/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Network
|
||||
|
||||
struct PrinterConfigView: View {
|
||||
@ObservedObject var printerManager: PrinterRequestManager
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
if(printerManager.isConnected) {
|
||||
HStack {
|
||||
Image(systemName: "network")
|
||||
Text(printerManager.connection.endpoint.toFriendlyString())
|
||||
Text("\(printerManager.socketHost):\(printerManager.socketPort)")
|
||||
Button {
|
||||
printerManager.socket?.disconnect()
|
||||
} label: {
|
||||
Text("Disconnect")
|
||||
}
|
||||
}
|
||||
.frame(width: 500, height: 80)
|
||||
} else {
|
||||
VStack {
|
||||
Text("Auto-detected Printers")
|
||||
.font(.title)
|
||||
ForEach(printerManager.nwBrowserDiscoveredItems, id: \.hashValue) { result in
|
||||
HStack {
|
||||
Text(result.endpoint.toFriendlyString())
|
||||
Button {
|
||||
printerManager.resolveBonjourHost(result.endpoint)
|
||||
} label: {
|
||||
Text("Connect")
|
||||
.foregroundColor(.white)
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(width: 500, height: 100)
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
NSApplication.shared.activate(ignoringOtherApps: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct PrinterConfigView_Previews: PreviewProvider {
|
||||
@State static var printerManager = PrinterRequestManager()
|
||||
|
||||
static var previews: some View {
|
||||
PrinterConfigView(printerManager: printerManager)
|
||||
}
|
||||
}
|
||||
|
||||
extension NWEndpoint {
|
||||
func toFriendlyString() -> String {
|
||||
let regex = /\.(.+)/
|
||||
let match = self.debugDescription.firstMatch(of: regex)
|
||||
return self.debugDescription.replacingOccurrences(of: match!.0, with: "")
|
||||
}
|
||||
}
|
||||
|
109
Soyuz/Views/SoyuzMenuBarExtraView.swift
Normal file
109
Soyuz/Views/SoyuzMenuBarExtraView.swift
Normal file
@@ -0,0 +1,109 @@
|
||||
//
|
||||
// KlipperMonMenuBarExtraView.swift
|
||||
// KlipperMon
|
||||
//
|
||||
// Created by maddiefuzz on 2/7/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
import Network
|
||||
|
||||
struct SoyuzMenuBarExtraView: View {
|
||||
// The threshhold considered a burn-risk, at which point certain UI elements turn red.
|
||||
let DANGERTEMP = 40.0
|
||||
|
||||
@Environment(\.openWindow) var openWindow
|
||||
|
||||
@ObservedObject var printerManager: PrinterRequestManager
|
||||
|
||||
@State var printPercentage: Double = 0
|
||||
|
||||
@Binding var currentMenuBarIcon: String
|
||||
|
||||
@State var hotendHotTemp: Bool = false
|
||||
@State var bedHotTemp: Bool = false
|
||||
|
||||
// TODO: Use @published API data instead of instance state variable
|
||||
var body: some View {
|
||||
VStack {
|
||||
// Printer Readouts
|
||||
//if let printerStats = printerManager.printerStats {
|
||||
if(printerManager.isConnected) {
|
||||
VStack {
|
||||
Text(printerManager.state.capitalized)
|
||||
.font(.title)
|
||||
.padding(4)
|
||||
// Print information
|
||||
HStack {
|
||||
Image(systemName: "pencil.tip")
|
||||
.rotationEffect(Angle(degrees: 180))
|
||||
.offset(x: 5.5, y: 4)
|
||||
.font(.system(size: 24))
|
||||
ProgressView(value: printerManager.progress, total: 1.0)
|
||||
.progressViewStyle(.linear)
|
||||
.offset(x: 10)
|
||||
Text("\(Int(printerManager.progress * 100))%")
|
||||
.padding(2)
|
||||
.padding([.leading], 8)
|
||||
}
|
||||
// Temperatures
|
||||
HStack {
|
||||
// Hot-end temperature
|
||||
HStack {
|
||||
Image(systemName: "flame")
|
||||
.foregroundColor( printerManager.extruderTemperature > DANGERTEMP ? .red : .white )
|
||||
.opacity( printerManager.extruderTemperature > DANGERTEMP ? 1.0 : 0.3 )
|
||||
Text("Hotend")
|
||||
.font(.headline)
|
||||
Spacer()
|
||||
Text("\(Int(printerManager.extruderTemperature))°C")
|
||||
}
|
||||
// Bed temperature
|
||||
HStack {
|
||||
Image(systemName: "flame")
|
||||
.foregroundColor( printerManager.bedTemperature > DANGERTEMP ? .red : .white )
|
||||
.opacity( printerManager.bedTemperature > DANGERTEMP ? 1.0 : 0.3 )
|
||||
Text("Plate")
|
||||
.font(.headline)
|
||||
Spacer()
|
||||
Text("\(Int(printerManager.bedTemperature))°C")
|
||||
}
|
||||
}
|
||||
Divider()
|
||||
}
|
||||
}
|
||||
}
|
||||
//.frame(minWidth: 220, minHeight: 100)
|
||||
// Footer information
|
||||
HStack {
|
||||
Button {
|
||||
print("Button pressed")
|
||||
openWindow(id: "soyuz_cfg")
|
||||
} label: {
|
||||
Text("Printers")
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
Spacer()
|
||||
if(printerManager.isConnected) {
|
||||
Image(systemName: "network")
|
||||
Text("Online")
|
||||
} else {
|
||||
Image(systemName: "exclamationmark.triangle")
|
||||
Text("Offline")
|
||||
}
|
||||
}
|
||||
.padding(2)
|
||||
.frame(minWidth: 220, maxWidth: 375)
|
||||
}
|
||||
}
|
||||
|
||||
struct KlipperMonMenuBarExtraView_Previews: PreviewProvider {
|
||||
@State static var currentMenuBarIcon = "move.3d"
|
||||
@State static var printerManager = PrinterRequestManager()
|
||||
|
||||
static var previews: some View {
|
||||
SoyuzMenuBarExtraView(printerManager: printerManager, currentMenuBarIcon: $currentMenuBarIcon)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user