-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge current status of develop with first step of migration to SwiftUI
- Loading branch information
Showing
29 changed files
with
1,183 additions
and
2,137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2010-2024 Contributors to the openHAB project | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0 | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 | ||
|
||
import SwiftUI | ||
|
||
struct ClientCertificatesView: View { | ||
@StateObject private var viewModel = ClientCertificatesViewModel() | ||
|
||
var body: some View { | ||
List { | ||
ForEach(viewModel.clientCertificates.indices, id: \.self) { index in | ||
Text(viewModel.getIdentityName(for: index)) | ||
} | ||
.onDelete { indices in | ||
indices.forEach { viewModel.deleteCertificate(at: $0) } | ||
} | ||
} | ||
.navigationTitle(Text(LocalizedStringKey("client_certificates"))) | ||
.onAppear { | ||
viewModel.loadCertificates() | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
ClientCertificatesView() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2010-2024 Contributors to the openHAB project | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0 | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 | ||
|
||
import OpenHABCore | ||
import os.log | ||
import SwiftUI | ||
|
||
class ClientCertificatesViewModel: ObservableObject { | ||
@Published var clientCertificates: [SecIdentity] = [] | ||
|
||
init() { | ||
loadCertificates() | ||
} | ||
|
||
func loadCertificates() { | ||
clientCertificates = NetworkConnection.shared.clientCertificateManager.clientIdentities | ||
} | ||
|
||
func deleteCertificate(at index: Int) { | ||
let status = NetworkConnection.shared.clientCertificateManager.deleteFromKeychain(index: index) | ||
if status == noErr { | ||
clientCertificates.remove(at: index) | ||
} | ||
} | ||
|
||
func getIdentityName(for index: Int) -> String { | ||
NetworkConnection.shared.clientCertificateManager.getIdentityName(index: index) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (c) 2010-2024 Contributors to the openHAB project | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0 | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 | ||
|
||
import Combine | ||
import OpenHABCore | ||
import os | ||
import SwiftUI | ||
|
||
struct ColorPickerView: View { | ||
@State private var selectedColor: Color = .white | ||
@State private var hue: Double = 0.0 | ||
@State private var saturation: Double = 0.0 | ||
@State private var brightness: Double = 0.0 | ||
|
||
@ObservedObject var throttler = Throttler(maxInterval: 0.3) | ||
|
||
var widget: OpenHABWidget? // OpenHAB widget for sending commands | ||
|
||
private let logger = Logger(subsystem: "org.openhab.app", category: "ColorPickerView") | ||
|
||
var body: some View { | ||
VStack { | ||
// SwiftUI Color Picker | ||
ColorPicker("Pick a Color", selection: $selectedColor) | ||
.onChange(of: selectedColor) { newColor in | ||
throttler.throttle { | ||
updateHSB(from: newColor) | ||
sendColorUpdate() | ||
} | ||
} | ||
.padding() | ||
|
||
// Displaying HSB values | ||
Text("Hue: \(hue, specifier: "%.2f")") | ||
Text("Saturation: \(saturation, specifier: "%.2f")") | ||
Text("Brightness: \(brightness, specifier: "%.2f")") | ||
} | ||
.onAppear { | ||
// Set initial color from widget if available | ||
if let initialColor = widget?.item?.stateAsUIColor() { | ||
selectedColor = Color(initialColor) | ||
} | ||
} | ||
.background(Color(UIColor.systemBackground)) | ||
} | ||
|
||
// Update hue, saturation, brightness from Color | ||
func updateHSB(from color: Color) { | ||
let uiColor = UIColor(color) | ||
// swiftlint:disable:next large_tuple | ||
var (hue, saturation, brightness, alpha): (CGFloat, CGFloat, CGFloat, CGFloat) = (0.0, 0.0, 0.0, 0.0) | ||
uiColor.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha) | ||
|
||
self.hue = Double(hue * 360) // Convert to degrees | ||
self.saturation = Double(saturation * 100) | ||
self.brightness = Double(brightness * 100) | ||
} | ||
|
||
// Send the color update to the widget | ||
func sendColorUpdate() { | ||
let command = "\(hue),\(saturation),\(brightness)" | ||
logger.debug("Sending command: \(command)") | ||
widget?.sendCommand(command) | ||
} | ||
} | ||
|
||
#Preview { | ||
ColorPickerView() | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.