Skip to content

Commit d943185

Browse files
committed
initial swift conversion
Signed-off-by: Joseph Mattello <[email protected]>
1 parent 0143ec2 commit d943185

20 files changed

+576
-92
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
6+
<true/>
7+
</dict>
8+
</plist>

CMakeLists.txt

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
cmake_minimum_required(VERSION 3.15.1)
22

3-
project(AltKit LANGUAGES C Swift)
3+
project(SideKit LANGUAGES C Swift)
44

5-
add_library(CAltKit
6-
Sources/CAltKit/NSError+ALTServerError.h
7-
Sources/CAltKit/NSError+ALTServerError.m
5+
add_library(CSideKit
6+
Sources/CSideKit/NSError+ALTServerError.h
7+
Sources/CSideKit/NSError+ALTServerError.m
88
)
99

10-
add_library(AltKit
11-
Sources/AltKit/Extensions/ALTServerError+Conveniences.swift
12-
Sources/AltKit/Extensions/Result+Conveniences.swift
10+
add_library(SideKit
11+
Sources/SideKit/Extensions/ALTServerError+Conveniences.swift
12+
Sources/SideKit/Extensions/Result+Conveniences.swift
1313

14-
Sources/AltKit/Server/Connection.swift
15-
Sources/AltKit/Server/NetworkConnection.swift
16-
Sources/AltKit/Server/Server.swift
17-
Sources/AltKit/Server/ServerConnection.swift
18-
Sources/AltKit/Server/ServerManager.swift
19-
Sources/AltKit/Server/ServerProtocol.swift
14+
Sources/SideKit/Server/Connection.swift
15+
Sources/SideKit/Server/NetworkConnection.swift
16+
Sources/SideKit/Server/Server.swift
17+
Sources/SideKit/Server/ServerConnection.swift
18+
Sources/SideKit/Server/ServerManager.swift
19+
Sources/SideKit/Server/ServerProtocol.swift
2020

21-
Sources/AltKit/Types/CodableServerError.swift
21+
Sources/SideKit/Types/CodableServerError.swift
2222
)
2323

24-
target_link_libraries(AltKit PRIVATE CAltKit)
24+
target_link_libraries(SideKit PRIVATE CSideKit)
2525

26-
set_property(TARGET AltKit PROPERTY XCODE_ATTRIBUTE_SWIFT_VERSION "5.0")
26+
set_property(TARGET SideKit PROPERTY XCODE_ATTRIBUTE_SWIFT_VERSION "5.0")
2727

28-
# Make CAltKit's modulemap available to AltKit
29-
set_property(TARGET AltKit PROPERTY XCODE_ATTRIBUTE_SWIFT_INCLUDE_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/Sources/CAltKit")
28+
# Make CSideKit's modulemap available to SideKit
29+
set_property(TARGET SideKit PROPERTY XCODE_ATTRIBUTE_SWIFT_INCLUDE_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/Sources/CSideKit")
3030

31-
# Add binary dir to interface include path to make Swift header accessible to targets using AltKit
32-
target_include_directories(AltKit INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
31+
# Add binary dir to interface include path to make Swift header accessible to targets using SideKit
32+
target_include_directories(SideKit INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
3333

3434
# Copy generated Swift header to binary dir
35-
add_custom_command(TARGET AltKit
35+
add_custom_command(TARGET SideKit
3636
POST_BUILD
37-
COMMAND cp $DERIVED_SOURCES_DIR/AltKit-Swift.h ${CMAKE_CURRENT_BINARY_DIR}
37+
COMMAND cp $DERIVED_SOURCES_DIR/SideKit-Swift.h ${CMAKE_CURRENT_BINARY_DIR}
3838
)

Package.swift

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,38 @@
44
import PackageDescription
55

66
let package = Package(
7-
name: "AltKit",
7+
name: "SideKit",
88
platforms: [
99
.iOS(.v11),
1010
.tvOS(.v11)
1111
],
1212
products: [
13-
// Products define the executables and libraries a package produces, and make them visible to other packages.
1413
.library(
15-
name: "AltKit",
16-
targets: ["AltKit"]),
14+
name: "SideKit",
15+
targets: ["SideKit"]),
16+
.library(
17+
name: "SideKit-Static",
18+
type: .static,
19+
targets: ["SideKit"]),
20+
.library(
21+
name: "SideKit-Dynamic",
22+
type: .dynamic,
23+
targets: ["SideKit"]),
1724
],
1825
dependencies: [
19-
// Dependencies declare other packages that this package depends on.
20-
// .package(url: /* package url */, from: "1.0.0"),
2126
],
2227
targets: [
23-
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
24-
// Targets can depend on other targets in this package, and on products in packages this package depends on.
25-
.target(
26-
name: "CAltKit",
27-
dependencies: []),
2828
.target(
29-
name: "AltKit",
30-
dependencies: ["CAltKit"],
29+
name: "SideKit",
30+
dependencies: [],
3131
linkerSettings: [
32-
.linkedFramework("UIKit")
32+
.linkedFramework("UIKit"),
33+
.linkedFramework("Network")
3334
]
34-
)
35+
),
36+
.testTarget(
37+
name: "SideKitTests",
38+
dependencies: ["SideKit"]
39+
)
3540
]
3641
)

Sources/AltKit/Extensions/ALTServerError+Conveniences.swift

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
#import <Foundation/Foundation.h>
1010

11-
extern NSErrorDomain const AltServerErrorDomain;
12-
extern NSErrorDomain const AltServerInstallationErrorDomain;
13-
extern NSErrorDomain const AltServerConnectionErrorDomain;
11+
NSErrorDomain const AltServerErrorDomain = @"com.rileytestut.AltServer";
12+
NSErrorDomain const AltServerInstallationErrorDomain = @"com.rileytestut.AltServer.Installation";
13+
NSErrorDomain const AltServerConnectionErrorDomain = @"com.rileytestut.AltServer.Connection";
1414

15-
extern NSErrorUserInfoKey const ALTUnderlyingErrorDomainErrorKey;
16-
extern NSErrorUserInfoKey const ALTUnderlyingErrorCodeErrorKey;
17-
extern NSErrorUserInfoKey const ALTProvisioningProfileBundleIDErrorKey;
18-
extern NSErrorUserInfoKey const ALTAppNameErrorKey;
19-
extern NSErrorUserInfoKey const ALTDeviceNameErrorKey;
15+
NSErrorUserInfoKey const ALTUnderlyingErrorDomainErrorKey = @"underlyingErrorDomain";
16+
NSErrorUserInfoKey const ALTUnderlyingErrorCodeErrorKey = @"underlyingErrorCode";
17+
NSErrorUserInfoKey const ALTProvisioningProfileBundleIDErrorKey = @"bundleIdentifier";
18+
NSErrorUserInfoKey const ALTAppNameErrorKey = @"appName";
19+
NSErrorUserInfoKey const ALTDeviceNameErrorKey = @"deviceName";
2020

2121
typedef NS_ERROR_ENUM(AltServerErrorDomain, ALTServerError)
2222
{
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module CAltKit {
1+
module CSideKit {
22
umbrella "./include"
33
export *
44
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
//
2+
// ALTServerConnectionError.swift
3+
//
4+
//
5+
// Created by Joseph Mattiello on 2/24/23.
6+
//
7+
8+
import Foundation
9+
10+
public enum ALTServerConnectionError: Int, LocalizedError {
11+
case unknown
12+
case deviceLocked
13+
case invalidRequest
14+
case invalidResponse
15+
case usbmuxd
16+
case ssl
17+
case timedOut
18+
19+
public static var errorDomain: String { return "com.rileytestut.AltServer.Connection" }
20+
}
21+
22+
public extension ALTServerConnectionError {
23+
var errorDescription: String? {
24+
switch self {
25+
case .unknown:
26+
return NSLocalizedString("Unknown connection error", comment: "ALTServerConnectionError")
27+
case .deviceLocked:
28+
return NSLocalizedString("Device locked", comment: "ALTServerConnectionError")
29+
case .invalidRequest:
30+
return NSLocalizedString("Invalid request", comment: "ALTServerConnectionError")
31+
case .invalidResponse:
32+
return NSLocalizedString("Invalid response", comment: "ALTServerConnectionError")
33+
case .usbmuxd:
34+
return NSLocalizedString("USBMuxd error", comment: "ALTServerConnectionError")
35+
case .ssl:
36+
return NSLocalizedString("SSL error", comment: "ALTServerConnectionError")
37+
case .timedOut:
38+
return NSLocalizedString("Timed out", comment: "ALTServerConnectionError")
39+
}
40+
}
41+
}
42+
43+
public extension ALTServerConnectionError {
44+
var recoverySuggestion: String? {
45+
switch self {
46+
case .deviceLocked:
47+
return NSLocalizedString("Unlock your device and try again.", comment: "ALTServerConnectionError recovery suggestion")
48+
case .invalidRequest:
49+
return NSLocalizedString("Make sure AltServer is running and try again.", comment: "ALTServerConnectionError recovery suggestion")
50+
case .invalidResponse:
51+
return NSLocalizedString("Make sure AltServer is running and try again.", comment: "ALTServerConnectionError recovery suggestion")
52+
case .usbmuxd:
53+
return NSLocalizedString("Make sure iTunes is not running, and no other software is using the device over USB.", comment: "ALTServerConnectionError recovery suggestion")
54+
case .ssl:
55+
return NSLocalizedString("Make sure your computer's time and date are correct, and try again.", comment: "ALTServerConnectionError recovery suggestion")
56+
case .timedOut:
57+
return NSLocalizedString("Make sure your device is unlocked and try again.", comment: "ALTServerConnectionError recovery suggestion")
58+
default:
59+
return nil
60+
}
61+
}
62+
}
63+
64+
public extension ALTServerConnectionError {
65+
var failureReason: String? {
66+
switch self {
67+
case .deviceLocked:
68+
return NSLocalizedString("Your device is locked. Unlock your device and try again.", comment: "ALTServerConnectionError failure reason")
69+
case .invalidRequest:
70+
return NSLocalizedString("The request sent to AltServer is invalid.", comment: "ALTServerConnectionError failure reason")
71+
case .invalidResponse:
72+
return NSLocalizedString("The response from AltServer is invalid.", comment: "ALTServerConnectionError failure reason")
73+
case .usbmuxd:
74+
return NSLocalizedString("AltServer cannot communicate with your device over USB. Make sure iTunes is not running, and no other software is using the device over USB.", comment: "ALTServerConnectionError failure reason")
75+
case .ssl:
76+
return NSLocalizedString("There is a problem with the SSL connection to AltServer. Make sure your computer's time and date are correct, and try again.", comment: "ALTServerConnectionError failure reason")
77+
case .timedOut:
78+
return NSLocalizedString("The connection to AltServer timed out. Make sure your device is unlocked and try again.", comment: "ALTServerConnectionError failure reason")
79+
case .unknown:
80+
return NSLocalizedString("An unknown error occurred with AltServer.", comment: "ALTServerConnectionError failure reason")
81+
}
82+
}
83+
}
84+
85+
public extension ALTServerConnectionError {
86+
var code: Int {
87+
return self.rawValue
88+
}
89+
}
90+
91+
92+
extension ALTServerConnectionError: Codable {
93+
enum CodingKeys: String, CodingKey {
94+
case deviceLocked
95+
case invalidRequest
96+
case invalidResponse
97+
case usbmuxd
98+
case ssl
99+
case timedOut
100+
case unknown
101+
}
102+
103+
public init(from decoder: Decoder) throws {
104+
let values = try decoder.container(keyedBy: CodingKeys.self)
105+
106+
if let _ = try? values.decode(Bool.self, forKey: .deviceLocked) {
107+
self = .deviceLocked
108+
return
109+
}
110+
if let _ = try? values.decode(Bool.self, forKey: .invalidRequest) {
111+
self = .invalidRequest
112+
return
113+
}
114+
if let _ = try? values.decode(Bool.self, forKey: .invalidResponse) {
115+
self = .invalidResponse
116+
return
117+
}
118+
if let _ = try? values.decode(Bool.self, forKey: .usbmuxd) {
119+
self = .usbmuxd
120+
return
121+
}
122+
if let _ = try? values.decode(Bool.self, forKey: .ssl) {
123+
self = .ssl
124+
return
125+
}
126+
if let _ = try? values.decode(Bool.self, forKey: .timedOut) {
127+
self = .timedOut
128+
return
129+
}
130+
131+
self = .unknown
132+
}
133+
134+
public func encode(to encoder: Encoder) throws {
135+
var container = encoder.container(keyedBy: CodingKeys.self)
136+
137+
switch self {
138+
case .deviceLocked:
139+
try container.encode(true, forKey: .deviceLocked)
140+
case .invalidRequest:
141+
try container.encode(true, forKey: .invalidRequest)
142+
case .invalidResponse:
143+
try container.encode(true, forKey: .invalidResponse)
144+
case .usbmuxd:
145+
try container.encode(true, forKey: .usbmuxd)
146+
case .ssl:
147+
try container.encode(true, forKey: .ssl)
148+
case .timedOut:
149+
try container.encode(true, forKey: .timedOut)
150+
case .unknown:
151+
break
152+
}
153+
}
154+
}

0 commit comments

Comments
 (0)