Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not showing simulator when boot in Xcode 13.4.1 or higher. #161

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 8 additions & 0 deletions ControlRoom/Controllers/SimCtl+SubCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ extension SimCtl {
private init(_ subcommand: String, arguments: [String]) {
self.arguments = ["simctl", subcommand] + arguments
}

private init(_ subcommand: String) {
self.arguments = ["open", subcommand]
}

/// Create a new device.
static func create(name: String, deviceTypeId: String, runtimeId: String? = nil) -> Command {
Expand Down Expand Up @@ -69,6 +73,10 @@ extension SimCtl {
static func boot(deviceId: String) -> Command {
Command("boot", arguments: [deviceId])
}

static func openSimulator(_ tool: DeveloperTool) -> Command {
Command("\(tool.path)/Contents/Developer/Applications/Simulator.app")
}

/// Shutdown a device.
static func shutdown(_ shutdown: ShutDown) -> Command {
Expand Down
6 changes: 4 additions & 2 deletions ControlRoom/Controllers/SimCtl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ enum SimCtl: CommandLineCommandExecuter {
executePropertyList(.listApps(deviceId: simulator, flags: [.json]))
}

static func boot(_ simulator: String) {
static func boot(_ simulator: String, tool: DeveloperTool) {
execute(.boot(deviceId: simulator))
execute(.openSimulator(tool))
}

static func shutdown(_ simulator: String) {
Expand All @@ -61,9 +62,10 @@ enum SimCtl: CommandLineCommandExecuter {
execute(.ui(deviceId: simulator, option: .contentSize(contentSize)))
}

static func reboot(_ simulator: String) {
static func reboot(_ simulator: String, tool: DeveloperTool) {
execute(.shutdown(.devices([simulator]))) { _ in
execute(.boot(deviceId: simulator))
execute(.openSimulator(tool))
}
}

Expand Down
3 changes: 3 additions & 0 deletions ControlRoom/Controllers/SimulatorsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class SimulatorsController: ObservableObject {
/// An array of all the applications installed on the selected simulator.
@Published var applications = [Application]()

var developerTool: DeveloperTool? = nil

/// An array of all simulators that were loaded from simctl.
private var allSimulators = [Simulator]()

Expand Down Expand Up @@ -72,6 +74,7 @@ class SimulatorsController: ObservableObject {
.sink { tool in
if tool != .empty {
self.loadSimulators()
self.developerTool = tool
} else {
self.loadingStatus = .invalidCommandLineTool
}
Expand Down
9 changes: 7 additions & 2 deletions ControlRoom/Simulator UI/ControlScreens/SystemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import SwiftUI

/// Controls system-wide settings such as time and appearance.
struct SystemView: View {
@ObservedObject var controller: SimulatorsController

let simulator: Simulator

@EnvironmentObject var preferences: Preferences
Expand Down Expand Up @@ -223,7 +225,9 @@ struct SystemView: View {
let plistPath = simulator.dataPath + "/Library/Preferences/.GlobalPreferences.plist"
_ = Process.execute("/usr/bin/xcrun", arguments: ["plutil", "-replace", "AppleLanguages", "-json", "[\"\(language)\" ]", plistPath])
_ = Process.execute("/usr/bin/xcrun", arguments: ["plutil", "-replace", "AppleLocale", "-string", locale, plistPath])
SimCtl.reboot(simulator.id)
if let tool = controller.developerTool {
SimCtl.reboot(simulator.id, tool: tool)
}
}

/// Starts an immediate iCloud sync.
Expand Down Expand Up @@ -320,7 +324,8 @@ struct SystemView: View {

struct SystemView_Previews: PreviewProvider {
static var previews: some View {
SystemView(simulator: .example)
SystemView(controller: .init(preferences: .init()),
simulator: .example)
.environmentObject(Preferences())
}
}
Expand Down
6 changes: 4 additions & 2 deletions ControlRoom/Simulator UI/ControlView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct ControlView: View {
.padding(.bottom, 10)

TabView {
SystemView(simulator: simulator)
SystemView(controller: controller, simulator: simulator)
AppView(simulator: simulator, applications: applications)
BatteryView(simulator: simulator)
LocationView(controller: controller, simulator: simulator)
Expand All @@ -62,7 +62,9 @@ struct ControlView: View {

/// Launches the current device.
func bootDevice() {
SimCtl.boot(simulator.udid)
if let tool = controller.developerTool {
SimCtl.boot(simulator.udid, tool: tool)
}
}

/// Terminates the current device.
Expand Down