Skip to content

Commit

Permalink
feat: get commands command
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Aug 15, 2023
1 parent ba911ae commit 2948554
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
14 changes: 8 additions & 6 deletions MiniSim/AppleScript Commands/GetCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,31 @@ class GetCommands: NSScriptCommand {
let argument = self.property(forKey: "platform") as? String,
let platform = Platform(rawValue: argument)
else {
return "Error: Unexpected argument passed"
scriptErrorNumber = NSRequiredArgumentsMissingScriptError;
return nil;
}

do {
var commands: [Command] = []
switch platform {
case .android:
commands = AndroidSubMenuItem.allCases.map { item in
commands = AndroidSubMenuItem.allCases.compactMap { item in
item.CommandItem
}
case .ios:
commands = IOSSubMenuItem.allCases.map { item in
commands = IOSSubMenuItem.allCases.compactMap { item in
item.CommandItem
}
}

let customCommands = DeviceService.getCustomCommands(platform: platform)
commands.append(contentsOf: customCommands)
// let customCommands = DeviceService.getCustomCommands(platform: platform)
// commands.append(contentsOf: customCommands)

return try self.encode(commands)

} catch {
return "Error: failed to get commands"
scriptErrorNumber = NSInternalScriptError;
return nil
}

}
Expand Down
8 changes: 4 additions & 4 deletions MiniSim/AppleScript Commands/LaunchDeviceCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ class LaunchDeviceCommand: NSScriptCommand {
}

if device.booted {
DispatchQueue.global().async {
DispatchQueue.global(qos: .userInitiated).async {
DeviceService.focusDevice(device)
}
return true
return "OK"
}

DispatchQueue.global().async {
DispatchQueue.global(qos: .userInitiated).async {
if device.platform == .android {
try? DeviceService.launchDevice(name: device.name, additionalArguments: [])
} else {
try? DeviceService.launchDevice(uuid: device.ID ?? "")
}
}
return true
return "OK"
} catch {
scriptErrorNumber = NSInternalScriptError;
return nil
Expand Down
9 changes: 9 additions & 0 deletions MiniSim/AppleScript Commands/MiniSim.sdef
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,14 @@
</parameter>
<result type="text" description="Response code"/>
</command>

<command name="getCommands" code="MinSGetc">
<cocoa class="MiniSim.GetCommands"/>
<access-group identifier="*"/>
<parameter code="plat" name="platform" description="Platform to get. Can be either android | ios." type="text">
<cocoa key="platform"/>
</parameter>
<result type="text" description="Response code"/>
</command>
</suite>
</dictionary>
5 changes: 4 additions & 1 deletion MiniSim/MenuItems/AndroidSubMenuItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ enum AndroidSubMenuItem: Int, CaseIterable {
}
}

var CommandItem: Command {
var CommandItem: Command? {
if self == .separator || self == .customCommand {
return nil
}
return Command(name: self.title, command: "", icon: "", platform: Platform.android, needBootedDevice: needBootedDevice)
}
}
5 changes: 4 additions & 1 deletion MiniSim/MenuItems/IOSSubMenuItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ enum IOSSubMenuItem: Int, CaseIterable {
}
}

var CommandItem: Command {
var CommandItem: Command? {
if self == .separator || self == .customCommand {
return nil
}
return Command(name: self.title, command: "", icon: "", platform: Platform.ios, needBootedDevice: false)
}
}

0 comments on commit 2948554

Please sign in to comment.