Skip to content

Commit

Permalink
Finished PR for Lifecycle (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion authored Aug 20, 2024
1 parent e2d1e7a commit 33b3d3c
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .periphery.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
retain_public: true
targets:
- SublimationBonjour
retain_files:
- '**/*+Protobuf.swift'
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// swift-tools-version: 6.0
// swiftlint:disable explicit_acl explicit_top_level_acl

import PackageDescription

let swiftSettings: [SwiftSetting] = [
Expand Down Expand Up @@ -61,4 +61,4 @@ let package = Package(
)
]
)
// swiftlint:enable explicit_acl explicit_top_level_acl

9 changes: 8 additions & 1 deletion Scripts/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ header_template="//

# Loop through each Swift file in the specified directory and subdirectories
find "$directory" -type f -name "*.swift" | while read -r file; do
# Check if the first line is the swift-format-ignore indicator
first_line=$(head -n 1 "$file")
if [[ "$first_line" == "// swift-format-ignore-file" ]]; then
echo "Skipping $file due to swift-format-ignore directive."
continue
fi

# Create the header with the current filename
filename=$(basename "$file")
header=$(printf "$header_template" "$filename" "$package" "$creator" "$year" "$company")
Expand All @@ -88,4 +95,4 @@ find "$directory" -type f -name "*.swift" | while read -r file; do
rm temp_file
done

echo "Headers added to all Swift files in the directory and subdirectories."
echo "Headers added or files skipped appropriately across all Swift files in the directory and subdirectories."
2 changes: 1 addition & 1 deletion Scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ $PACKAGE_DIR/scripts/header.sh -d $PACKAGE_DIR/Sources -c "Leo Dion" -o "Bright
$MINT_RUN swift-format lint --recursive --parallel $SWIFTFORMAT_OPTIONS $PACKAGE_DIR/Sources

pushd $PACKAGE_DIR
$MINT_RUN periphery scan $PERIPHERY_OPTIONS
$MINT_RUN periphery scan $PERIPHERY_OPTIONS --disable-update-check
popd
31 changes: 2 additions & 29 deletions Sources/SublimationBonjour/BindingConfiguration+Protobuf.swift
Original file line number Diff line number Diff line change
@@ -1,31 +1,4 @@
//
// BindingConfiguration+Protobuf.swift
// SublimationBonjour
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// swift-format-ignore-file

private import Foundation
public import SwiftProtobuf
Expand Down Expand Up @@ -84,7 +57,7 @@ public struct BindingConfiguration {
extension BindingConfiguration: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase,
SwiftProtobuf._ProtoNameProviding
{
public static let protoMessageName: String = "ServerConfiguration"
public static let protoMessageName: String = "BindingConfiguration"
public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
1: .standard(proto: "is_secure"), 2: .same(proto: "port"), 9: .same(proto: "hosts"),
]
Expand Down
8 changes: 4 additions & 4 deletions Sources/SublimationBonjour/BonjourSublimatory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@

listener.newConnectionHandler = { connection in
connection.stateUpdateHandler = { state in
switch state { case let .waiting(error):
switch state { case .waiting(let error):

print("Connection Waiting error: \(error)")

Expand All @@ -129,7 +129,7 @@
connection.cancel()
}
)
case let .failed(error): print("Connection Failure: \(error)")
case .failed(let error): print("Connection Failure: \(error)")

default: print("Connection state updated: \(state)")
}
Expand All @@ -141,12 +141,12 @@

return try await withCheckedThrowingContinuation { continuation in
listener.stateUpdateHandler = { state in
switch state { case let .waiting(error):
switch state { case .waiting(let error):

print("Listener Waiting error: \(error)")
continuation.resume(throwing: error)

case let .failed(error):
case .failed(let error):
print("Listener Failure: \(error)")
continuation.resume(throwing: error)
case .cancelled: continuation.resume()
Expand Down
18 changes: 9 additions & 9 deletions Sources/SublimationBonjour/Client/BonjourClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@
browser.browseResultsChangedHandler = { results, _ in self.parseResults(results) }
}

private static func descriptionFor(state: NWConnection.State) -> String {
switch state { case .setup: "setup" case .waiting: "waiting" case .preparing: "preparing"
case .ready: "ready"
case .failed: "failed"
case .cancelled: "cancelled"
default: "unknown"
}
}
// private static func descriptionFor(state: NWConnection.State) -> String {
// switch state { case .setup: "setup" case .waiting: "waiting" case .preparing: "preparing"
// case .ready: "ready"
// case .failed: "failed"
// case .cancelled: "cancelled"
// default: "unknown"
// }
// }

private func append(urls: [URL]) async { await self.streams.yield(urls, logger: self.logger) }

Expand Down Expand Up @@ -140,7 +140,7 @@
}
public func addResults(_ results: Set<NWBrowser.Result>) {
for result in results {
guard case let .bonjour(txtRecord) = result.metadata else {
guard case .bonjour(let txtRecord) = result.metadata else {
self.logger?.error("No TXT Record for \(result.endpoint.debugDescription)")
continue
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SublimationBonjour/NWListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@

extension NWListener.State: @retroactive CustomDebugStringConvertible {
public var debugDescription: String {
switch self { case .setup: "setup" case let .waiting(error):
switch self { case .setup: "setup" case .waiting(let error):
"waiting: \(error.debugDescription)"
case .ready: "ready"
case let .failed(error): "failed: \(error.debugDescription)"
case .failed(let error): "failed: \(error.debugDescription)"
case .cancelled: "cancelled"
@unknown default: "unknown state"
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/SublimationBonjour/Sublimation+Bonjour.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
/// Initializes a `Sublimation` instance with the provided parameters.
///
/// - Parameters:
/// - bindingConfiguration: A configuration with addresses, port and tls configuration.
/// - name: Service name.
/// - type: Service type.
/// - listenerParameters: The network parameters to use for the listener. Default is `.tcp`.
/// - serviceType: The Bonjour service type. Default is `BonjourSublimatory.httpTCPServiceType`.
/// - maximumCount: The maximum number of connections. Default is `nil`.
/// - addresses: A closure that asynchronously returns a list of addresses.
/// - addressFilter: A closure that filters the addresses. Default is `String.isIPv4NotLocalhost(_:)`.
///
public convenience init(
bindingConfiguration: BindingConfiguration,
name: String = BonjourSublimatory.defaultName,
Expand Down

0 comments on commit 33b3d3c

Please sign in to comment.