Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cartfile

This file was deleted.

1 change: 0 additions & 1 deletion Cartfile.resolved

This file was deleted.

38 changes: 4 additions & 34 deletions iSimulator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,10 @@
29B227BA1FBD7B9F00BDE5BF /* PreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29B227B91FBD7B9F00BDE5BF /* PreferencesViewController.swift */; };
29B591981F581513006CDEC0 /* FileWatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29B591971F581513006CDEC0 /* FileWatch.swift */; };
315A809D22C90616005C2493 /* AppGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 315A809C22C90616005C2493 /* AppGroup.swift */; };
3198339421A7F5FF004ADEE3 /* ObjectMapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3198338821A7F5FE004ADEE3 /* ObjectMapper.framework */; };
3198339521A7F5FF004ADEE3 /* ObjectMapper.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3198338821A7F5FE004ADEE3 /* ObjectMapper.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
31CD6D0221B2817900E49DC0 /* RootLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31CD6D0121B2817900E49DC0 /* RootLink.swift */; };
31CD6D0421B2942300E49DC0 /* ApplicationCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31CD6D0321B2942300E49DC0 /* ApplicationCache.swift */; };
CFDB43E0264BCE6E0075BDDC /* Cartfile in Resources */ = {isa = PBXBuildFile; fileRef = CFDB43DF264BCE6E0075BDDC /* Cartfile */; };
CFDB43E4264BD5E50075BDDC /* Cartfile.resolved in Resources */ = {isa = PBXBuildFile; fileRef = CFDB43E3264BD5E50075BDDC /* Cartfile.resolved */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
3198338221A7F5D7004ADEE3 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
3198339521A7F5FF004ADEE3 /* ObjectMapper.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
291157AD1FB5501C000EE94F /* DevcieMenuItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DevcieMenuItem.swift; sourceTree = "<group>"; };
29157C541F4D56400069BDB6 /* Shell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -77,16 +59,13 @@
3198338821A7F5FE004ADEE3 /* ObjectMapper.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjectMapper.framework; path = Carthage/Build/Mac/ObjectMapper.framework; sourceTree = "<group>"; };
31CD6D0121B2817900E49DC0 /* RootLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootLink.swift; sourceTree = "<group>"; };
31CD6D0321B2942300E49DC0 /* ApplicationCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationCache.swift; sourceTree = "<group>"; };
CFDB43DF264BCE6E0075BDDC /* Cartfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Cartfile; sourceTree = SOURCE_ROOT; };
CFDB43E3264BD5E50075BDDC /* Cartfile.resolved */ = {isa = PBXFileReference; lastKnownFileType = text; path = Cartfile.resolved; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
292EAD9D1F458B3D009FC1ED /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3198339421A7F5FF004ADEE3 /* ObjectMapper.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -140,7 +119,6 @@
292EADA21F458B3D009FC1ED /* iSimulator */ = {
isa = PBXGroup;
children = (
CFDB43DE264BCE5D0075BDDC /* Support */,
29157C581F4D62940069BDB6 /* Models */,
29157C531F4D56310069BDB6 /* Tools */,
292EADB21F458C89009FC1ED /* UI */,
Expand Down Expand Up @@ -174,15 +152,6 @@
name = Frameworks;
sourceTree = "<group>";
};
CFDB43DE264BCE5D0075BDDC /* Support */ = {
isa = PBXGroup;
children = (
CFDB43DF264BCE6E0075BDDC /* Cartfile */,
CFDB43E3264BD5E50075BDDC /* Cartfile.resolved */,
);
name = Support;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand All @@ -193,13 +162,14 @@
292EAD9C1F458B3D009FC1ED /* Sources */,
292EAD9D1F458B3D009FC1ED /* Frameworks */,
292EAD9E1F458B3D009FC1ED /* Resources */,
3198338221A7F5D7004ADEE3 /* Embed Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = iSimulator;
packageProductDependencies = (
);
productName = iSimulator;
productReference = 292EADA01F458B3D009FC1ED /* iSimulator.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -234,6 +204,8 @@
Base,
);
mainGroup = 292EAD971F458B3D009FC1ED;
packageReferences = (
);
productRefGroup = 292EADA11F458B3D009FC1ED /* Products */;
projectDirPath = "";
projectRoot = "";
Expand All @@ -248,9 +220,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CFDB43E0264BCE6E0075BDDC /* Cartfile in Resources */,
292EADA81F458B3D009FC1ED /* Assets.xcassets in Resources */,
CFDB43E4264BD5E50075BDDC /* Cartfile.resolved in Resources */,
292EADAB1F458B3D009FC1ED /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
23 changes: 13 additions & 10 deletions iSimulator/Models/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
//

import Foundation
import ObjectMapper

class Device: Mappable {
enum State: String {
final class Device: Decodable {
enum State: String, Decodable {
case booted = "Booted"
case shutdown = "Shutdown"
}
Expand Down Expand Up @@ -47,15 +46,19 @@ class Device: Mappable {

}

required init?(map: Map) {

enum CodingKeys: CodingKey {
case state
case availability
case name
case udid
}

func mapping(map: Map) {
state <- (map["state"], EnumTransform())
availability <- (map["availability"], EnumTransform())
name <- map["name"]
udid <- map["udid"]
required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
state = try container.decode(Device.State.self, forKey: .state)
availability = try container.decodeIfPresent(Availability.self, forKey: .availability) ?? .unavailable
name = try container.decode(String.self, forKey: .name)
udid = try container.decode(String.self, forKey: .udid)
}

var dataReportDic: [String: String] {
Expand Down
19 changes: 11 additions & 8 deletions iSimulator/Models/DeviceType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
//

import Foundation
import ObjectMapper

class DeviceType: Mappable {
var name = ""
var identifier = ""
struct DeviceType: Decodable {
let name: String
let identifier: String

required init?(map: Map) { }
enum CodingKeys: CodingKey {
case name
case identifier
}

func mapping(map: Map) {
name <- map["name"]
identifier <- map["identifier"]
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
name = try container.decode(String.self, forKey: .name)
identifier = try container.decode(String.self, forKey: .identifier)
}

var dataReportDic: [String: String] {
Expand Down
24 changes: 13 additions & 11 deletions iSimulator/Models/Pair.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@
//

import Foundation
import ObjectMapper

class Pair: Mappable {
struct Pair: Decodable {

var watch: Device?
var phone: Device?
var state = ""
let watch: Device?
let phone: Device?
let state: String

required init?(map: Map) {

enum CodingKeys: CodingKey {
case watch
case phone
case state
}

func mapping(map: Map) {
watch <- map["watch"]
phone <- map["phone"]
state <- map["state"]
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
watch = try container.decodeIfPresent(Device.self, forKey: .watch)
phone = try container.decodeIfPresent(Device.self, forKey: .phone)
state = try container.decode(String.self, forKey: .state)
}

var dataReportDic: [String: String] {
Expand Down
68 changes: 44 additions & 24 deletions iSimulator/Models/Runtime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,68 @@
//

import Foundation
import ObjectMapper

enum Availability: String {
case available = "(available)"
case unavailable = "(unavailable, runtime profile not found)"
enum Availability: Decodable {
case available, unavailable

init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let rawValue = try container.decode(String.self)

switch rawValue {
case "(available)":
self = .available
case "(unavailable, runtime profile not found)", "(unavailable)":
self = .unavailable
default:
throw DecodingError.valueNotFound(String.self, .init(codingPath: decoder.codingPath, debugDescription: "Unknown Availability type \(rawValue)"))
}
}
}

class Runtime: Mappable {
final class Runtime: Decodable {

enum OSType: String {
case iOS, tvOS, watchOS, None
}

var buildversion = ""
var availability = Availability.unavailable
var name = ""
var identifier = ""
var version = ""
var devices: [Device] = []
var devicetypes: [DeviceType] = []
let buildversion: String
let availability: Availability
let name: String
let identifier: String
let version: String
var devices: [Device]
var devicetypes: [DeviceType]

var osType: OSType{
if name.contains("iOS"){
if name.contains("iOS") {
return .iOS
}else if name.contains("tvOS"){
} else if name.contains("tvOS") {
return .tvOS
}else if name.contains("watchOS"){
} else if name.contains("watchOS") {
return .watchOS
}else{
} else{
return .None
}
}

required init?(map: Map) {

enum CodingKeys: CodingKey {
case buildversion
case availability
case name
case identifier
case version
}

func mapping(map: Map) {
buildversion <- map["buildversion"]
availability <- (map["availability"], EnumTransform())
name <- map["name"]
identifier <- map["identifier"]
version <- map["version"]
required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
buildversion = try container.decode(String.self, forKey: .buildversion)
availability = try container.decodeIfPresent(Availability.self, forKey: .availability) ?? .unavailable
name = try container.decode(String.self, forKey: .name)
identifier = try container.decode(String.self, forKey: .identifier)
version = try container.decode(String.self, forKey: .version)
devices = []
devicetypes = []
}

var dataReportDic: [String: String] {
Expand Down
37 changes: 22 additions & 15 deletions iSimulator/Models/TotalModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
//

import AppKit
import ObjectMapper

class TotalModel: Mappable {
final class TotalModel: Decodable {

static let `default` = TotalModel()
static var `default` = TotalModel()
var isForceUpdate = true

private var lastXcodePath = ""
Expand Down Expand Up @@ -55,7 +54,14 @@ class TotalModel: Mappable {
}
}
let jsonStr = shell("/usr/bin/xcrun", arguments: "simctl", "list", "-j").outStr
_ = Mapper().map(JSONString: jsonStr, toObject: TotalModel.default)

if let jsonData = jsonStr.data(using: .utf8) {
do {
TotalModel.default = try JSONDecoder().decode(TotalModel.self, from: jsonData)
} catch {
print("Error decoding TotalModel: \(error)")
}
}
}

var runtimes: [Runtime] = []
Expand Down Expand Up @@ -83,19 +89,20 @@ class TotalModel: Mappable {

}

required init?(map: Map) {

enum CodingKeys: CodingKey {
case runtimes
case devicetypes
case devices
case pairs
}

func mapping(map: Map) {
runtimes.removeAll()
devicetypes.removeAll()
devices.removeAll()
pairs.removeAll()
runtimes <- map["runtimes"]
devicetypes <- map["devicetypes"]
devices <- map["devices"]
pairs <- map["pairs"]
required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
runtimes = try container.decode([Runtime].self, forKey: .runtimes)
devicetypes = try container.decode([DeviceType].self, forKey: .devicetypes)
devices = try container.decode([String: [Device]].self, forKey: .devices)
pairs = try container.decode([String: Pair].self, forKey: .pairs)

// 关联 runtime 和 device/devicetype
runtimes.forEach{ r in
r.devices = self.devices[r.name] ?? (self.devices[r.identifier] ?? [])
Expand Down