Skip to content

Commit

Permalink
Aligning with develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
timbms committed Sep 12, 2024
2 parents ec0fc85 + fc036ee commit f4e672f
Show file tree
Hide file tree
Showing 37 changed files with 742 additions and 749 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
type: choice
description: 'Select version bump type:'
options:
- none
- patch
- minor
- major
Expand Down
47 changes: 20 additions & 27 deletions NotificationService/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,35 +165,28 @@ class NotificationService: UNNotificationServiceExtension {
return
}
if let state = item.state {
do {
// Extract MIME type and base64 string
let pattern = "^data:(.*?);base64,(.*)$"
let regex = try NSRegularExpression(pattern: pattern, options: [])
if let match = regex.firstMatch(in: state, options: [], range: NSRange(location: 0, length: state.utf16.count)) {
let mimeTypeRange = Range(match.range(at: 1), in: state)
let base64Range = Range(match.range(at: 2), in: state)
if let mimeTypeRange, let base64Range {
let mimeType = String(state[mimeTypeRange])
let base64String = String(state[base64Range])
if let imageData = Data(base64Encoded: base64String) {
// Create a temporary file URL
let tempDirectory = FileManager.default.temporaryDirectory
let tempFileURL = tempDirectory.appendingPathComponent(UUID().uuidString)
do {
try imageData.write(to: tempFileURL)
os_log("Image saved to temporary file: %{PUBLIC}@", log: .default, type: .info, tempFileURL.absoluteString)
self.attachFile(localURL: tempFileURL, mimeType: mimeType, completion: completion)
return
} catch {
os_log("Failed to write image data to file: %{PUBLIC}@", log: .default, type: .error, error.localizedDescription)
}
} else {
os_log("Failed to decode base64 string to Data", log: .default, type: .error)
}
// Extract MIME type and base64 string
let pattern = /^data:(.*?);base64,(.*)$/
if let firstMatch = state.firstMatch(of: pattern) {
let mimeType = String(firstMatch.1)
let base64String = String(firstMatch.2)
if let imageData = Data(base64Encoded: base64String) {
// Create a temporary file URL
let tempDirectory = FileManager.default.temporaryDirectory
let tempFileURL = tempDirectory.appendingPathComponent(UUID().uuidString)
do {
try imageData.write(to: tempFileURL)
os_log("Image saved to temporary file: %{PUBLIC}@", log: .default, type: .info, tempFileURL.absoluteString)
self.attachFile(localURL: tempFileURL, mimeType: mimeType, completion: completion)
return
} catch {
os_log("Failed to write image data to file: %{PUBLIC}@", log: .default, type: .error, error.localizedDescription)
}
} else {
os_log("Failed to decode base64 string to Data", log: .default, type: .error)
}
} catch {
os_log("Failed to parse data: %{PUBLIC}@", log: .default, type: .error, error.localizedDescription)
} else {
os_log("Failed to parse data: %{PUBLIC}@", log: .default, type: .error, error?.localizedDescription ?? "")
}
}
completion(nil)
Expand Down
6 changes: 4 additions & 2 deletions OpenHABCore/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ let package = Package(
.product(name: "Kingfisher", package: "Kingfisher", condition: .when(platforms: [.iOS, .watchOS])),
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession")
]
],
swiftSettings: [.enableUpcomingFeature("BareSlashRegexLiterals")]
),
.testTarget(
name: "OpenHABCoreTests",
dependencies: ["OpenHABCore"],
resources: [
.process("Resources")
]
],
swiftSettings: [.enableUpcomingFeature("BareSlashRegexLiterals")]
)
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foundation

public class OpenHABCommandOptions: Decodable {
public var command = ""
public var label = ""
public var label: String? = ""

public init(command: String = "", label: String = "") {
self.command = command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class OpenHABStateDescription {

public var numberPattern: String?

public init(minimum: Double?, maximum: Double?, step: Double?, readOnly: Bool?, options: [OpenHABOptions]?, pattern: String?) {
public init(minimum: Double?, maximum: Double?, step: Double?, readOnly: Bool?, options: [OpenHABOptions]?, pattern tobeSearched: String?) {
self.minimum = minimum ?? 0.0
self.maximum = maximum ?? 100.0
self.step = step ?? 1.0
Expand All @@ -30,16 +30,12 @@ public class OpenHABStateDescription {

// Remove transformation instructions (e.g. for 'MAP(foo.map):%s' keep only '%s')

let regexPattern = #"^[A-Z]+(\(.*\))?:(.*)$"#
let regex = try? NSRegularExpression(pattern: regexPattern, options: .caseInsensitive)
if let pattern {
let nsrange = NSRange(pattern.startIndex ..< pattern.endIndex, in: pattern)
if let match = regex?.firstMatch(in: pattern, options: [], range: nsrange) {
if let range = Range(match.range(at: 2), in: pattern) {
numberPattern = String(pattern[range])
}
let regexPattern = /^[A-Z]+(\(.*\))?:(.*)$/.ignoresCase()
if let tobeSearched {
if let firstMatch = tobeSearched.firstMatch(of: regexPattern) {
numberPattern = String(firstMatch.2)
} else {
numberPattern = pattern
numberPattern = tobeSearched
}
} else {
numberPattern = nil
Expand Down
10 changes: 4 additions & 6 deletions OpenHABCore/Sources/OpenHABCore/Model/OpenHABWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,9 @@ public class OpenHABWidget: NSObject, MKAnnotation, Identifiable {

// Text between square brackets
public var labelValue: String? {
// Swift 5 raw strings
let regex = try? NSRegularExpression(pattern: #"\[(.*?)\]"#, options: [.dotMatchesLineSeparators])
guard let match = regex?.firstMatch(in: label, options: [], range: NSRange(location: 0, length: (label as NSString).length)) else { return nil }
guard let range = Range(match.range(at: 1), in: label) else { return nil }
return String(label[range])
let pattern = /\[(.*?)\]/.dotMatchesNewlines()
guard let firstMatch = label.firstMatch(of: pattern) else { return nil }
return String(firstMatch.1)
}

public var coordinate: CLLocationCoordinate2D {
Expand All @@ -120,7 +118,7 @@ public class OpenHABWidget: NSObject, MKAnnotation, Identifiable {

public var mappingsOrItemOptions: [OpenHABWidgetMapping] {
if mappings.isEmpty, let commandOptions = item?.commandDescription?.commandOptions {
commandOptions.map { OpenHABWidgetMapping(command: $0.command, label: $0.label) }
commandOptions.map { OpenHABWidgetMapping(command: $0.command, label: $0.label ?? "") }
} else if mappings.isEmpty, let stateOptions = item?.stateDescription?.options {
stateOptions.map { OpenHABWidgetMapping(command: $0.value, label: $0.label) }
} else {
Expand Down
3 changes: 2 additions & 1 deletion OpenHABCore/Sources/OpenHABCore/Util/APIActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,14 @@ public class OpenHABSitemapWidgetEvent {

convenience init?(_ event: Components.Schemas.SitemapWidgetEvent?) {
guard let event else { return nil }
// swiftlint:disable:next line_length
self.init(sitemapName: event.sitemapName, pageId: event.pageId, widgetId: event.widgetId, label: event.label, labelSource: event.labelSource, icon: event.icon, reloadIcon: event.reloadIcon, labelcolor: event.labelcolor, valuecolor: event.valuecolor, iconcolor: event.iconcolor, visibility: event.visibility, state: event.state, enrichedItem: OpenHABItem(event.item), descriptionChanged: event.descriptionChanged)
}
}

extension OpenHABSitemapWidgetEvent: CustomStringConvertible {
public var description: String {
"\(widgetId) \(label) \(enrichedItem?.state)"
"\(widgetId ?? "") \(label ?? "") \(enrichedItem?.state ?? "")"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,13 @@ public class ClientCertificateManager {

let chainSize = SecTrustGetCertificateCount(trust)

if trustResult == .recoverableTrustFailure, chainSize > 1 {
trustResult = SecTrustResultType.proceed
let rootCA = SecTrustGetCertificateAtIndex(trust, chainSize - 1)
if trustResult == .recoverableTrustFailure, chainSize > 1,
let certificates = SecTrustCopyCertificateChain(trust) as? [SecCertificate] {
let rootCA = certificates[chainSize - 1]
let anchors = [rootCA]
os_log("Setting anchor for trust evaluation to %s", log: .default, type: .info, rootCA.debugDescription)
os_log("Setting anchor for trust evaluation to %s", log: .default, type: .info, SecCertificateCopySubjectSummary(rootCA)! as String)
SecTrustSetAnchorCertificates(trust, anchors as CFArray)
trustResult = SecTrustResultType.proceed
if #available(iOS 12.0, *) {
var trustError: CFError?
if SecTrustEvaluateWithError(trust, &trustError) != true {
Expand All @@ -316,13 +317,7 @@ public class ClientCertificateManager {
return nil
}

var certChain: [SecCertificate] = []
for ix in 0 ... chainSize - 1 {
guard let ct = SecTrustGetCertificateAtIndex(trust, ix) else { return nil }
if ct != cert {
certChain.append(ct)
}
}
return certChain
let certificates = SecTrustCopyCertificateChain(trust) as? [SecCertificate]
return certificates?.filter { $0 != cert }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,11 @@ public class ServerCertificateManager: ServerTrustManager, ServerTrustEvaluating
func getLeafCertificate(trust: SecTrust?) -> SecCertificate? {
// Returns the leaf certificate from a SecTrust object (that is always the
// certificate at index 0).
var result: SecCertificate?

if let trust {
if SecTrustGetCertificateCount(trust) > 0 {
result = SecTrustGetCertificateAtIndex(trust, 0)
return result
} else {
return nil
}
if let trust, SecTrustGetCertificateCount(trust) > 0, let certificates = SecTrustCopyCertificateChain(trust) as? [SecCertificate] {
certificates[0]
} else {
return nil
nil
}
}

Expand Down
4 changes: 0 additions & 4 deletions OpenHABCore/Sources/OpenHABCore/Util/UIColorExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ public extension UIColor {
return .white
}

class var ohHightlightStrokeColor: UIColor {
OHInterfaceStyle.current == .light ? .black : .white
}

// standard colors
class var ohMaroon: UIColor {
OHInterfaceStyle.current == .light ? UIColor(hex: "#800000") : UIColor(hex: "#800000")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ final class OpenHABCoreGeneralTests: XCTestCase {
XCTAssertEqual(urlc, URL(string: "http://192.169.2.1/icon/switch?state=OFF&format=SVG"), "Check endpoint creation")
}

func testLabelVale() {
func testLabelValue() {
let widget = OpenHABWidget()
widget.label = "llldl [llsl]"
XCTAssertEqual(widget.labelValue, "llsl")
widget.label = "llllsl[kkks] llls"
XCTAssertEqual(widget.labelValue, "kkks")
}

func testOpenHABStateDescription() {
let openHABStateDescription = OpenHABStateDescription(minimum: 0.0, maximum: 1.0, step: 0.2, readOnly: true, options: nil, pattern: "MAP(foo.map):%s")
XCTAssertEqual(openHABStateDescription.numberPattern, "%s")
}
}
2 changes: 1 addition & 1 deletion fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ platform :ios do

type = options[:bump]

if !options[:isfeaturebuild]
if !options[:isfeaturebuild] && type != 'none'
increment_version_number_in_xcodeproj(
bump_type: type,
xcodeproj: 'openHAB.xcodeproj',
Expand Down
Binary file added openHAB.xcodeproj/.project.pbxproj.swp
Binary file not shown.
Loading

0 comments on commit f4e672f

Please sign in to comment.