Skip to content

Commit

Permalink
Merge pull request #50 from arthurdapaz/master
Browse files Browse the repository at this point in the history
Added Launch App on Simulator
  • Loading branch information
luosheng authored May 8, 2019
2 parents bc7f767 + 7eadf46 commit 317da3e
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 4 deletions.
5 changes: 5 additions & 0 deletions OpenSim.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
256B782C2278A08500052809 /* LaunchAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 256B782B2278A08500052809 /* LaunchAction.swift */; };
312A27FD21A753E600699668 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 312A27FC21A753E600699668 /* Constants.swift */; };
31A79B15219B81660024DF7B /* Simulator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31A79B14219B81660024DF7B /* Simulator.swift */; };
31C4BF3221A8AC56008B97A1 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 31C4BF3021A8AC56008B97A1 /* Localizable.strings */; };
Expand Down Expand Up @@ -40,6 +41,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
256B782B2278A08500052809 /* LaunchAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LaunchAction.swift; sourceTree = "<group>"; };
312A27FC21A753E600699668 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
31A79B14219B81660024DF7B /* Simulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Simulator.swift; sourceTree = "<group>"; };
31C4BF3121A8AC56008B97A1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -155,6 +157,7 @@
B39B2B721EBF573C00CDD74C /* UninstallAction.swift */,
B39B2B741EBF58EC00CDD74C /* OpenInItermAction.swift */,
B39B2B781EBF614400CDD74C /* OpenRealmAction.swift */,
256B782B2278A08500052809 /* LaunchAction.swift */,
);
name = Actions;
sourceTree = "<group>";
Expand Down Expand Up @@ -229,6 +232,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
"pt-BR",
Expand Down Expand Up @@ -287,6 +291,7 @@
B39B2B731EBF573C00CDD74C /* UninstallAction.swift in Sources */,
B3054E1A1BF3958500F433C2 /* DirectoryWatcher.swift in Sources */,
B32480551EBEB705000633FC /* ActionMenu.swift in Sources */,
256B782C2278A08500052809 /* LaunchAction.swift in Sources */,
AF9D003A1D110E750065AFD0 /* Helper.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
1 change: 1 addition & 0 deletions OpenSim/ActionMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class ActionMenu: NSMenu {
RevealInFinderAction.self,
CopyToPasteboardAction.self,
OpenInTerminalAction.self,
LaunchAction.self,
UninstallAction.self
]

Expand Down
8 changes: 8 additions & 0 deletions OpenSim/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ final class Application {
}
}

func launch() {
if device.state != .booted {
SimulatorController.boot(self)
}
SimulatorController.run(self)
SimulatorController.launch(self)
}

func uninstall() {
if device.state != .booted {
SimulatorController.boot(self)
Expand Down
22 changes: 22 additions & 0 deletions OpenSim/Assets.xcassets/launch.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "launch.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions OpenSim/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"Action.RevealInFinder" = "Reveal Sandbox in Finder";
"Action.CopyPathPasteboard" = "Copy Sandbox Path to Pasteboard";
"Action.OpenInTerminal" = "Open Sandbox in Terminal";
"Action.Launch" = "Launch App";
"Action.Uninstall" = "Uninstall";
"Action.UninstallAlertConfirmButton" = "Uninstall";
"Action.UninstallAlertCancelButton" = "Cancel";
Expand Down
1 change: 1 addition & 0 deletions OpenSim/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct UIConstants {
static let actionRevealInFinder = NSLocalizedString("Action.RevealInFinder", comment: "Reveal in Finder label")
static let actionCopyPathPasteboard = NSLocalizedString("Action.CopyPathPasteboard", comment: "Copy Sandbox path to pasteboard label")
static let actionOpenInTerminal = NSLocalizedString("Action.OpenInTerminal", comment: "Open in Terminal label")
static let actionLaunch = NSLocalizedString("Action.Launch", comment: "Launch label")
static let actionUninstall = NSLocalizedString("Action.Uninstall", comment: "Uninstall label")
static let actionUninstallAlertConfirmButton = NSLocalizedString("Action.UninstallAlertConfirmButton", comment: "Uninstall confirm button")
static let actionUninstallAlertCancelButton = NSLocalizedString("Action.UninstallAlertCancelButton", comment: "Uninstall cancel button")
Expand Down
30 changes: 30 additions & 0 deletions OpenSim/LaunchAction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// LaunchAction.swift
// OpenSim
//
// Created by Arthur da Paz on 30/04/19.
// Copyright © 2019 Luo Sheng. All rights reserved.
//

import Cocoa

final class LaunchAction: ApplicationActionable {
var application: Application?

let title = UIConstants.strings.actionLaunch

let icon = templatize(#imageLiteral(resourceName: "launch"))

let isAvailable = true

init(application: Application) {
self.application = application
}

func perform() {
guard let application = application else {
return
}
application.launch()
}
}
16 changes: 12 additions & 4 deletions OpenSim/SimulatorController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@ import Cocoa

struct SimulatorController {

static func uninstall(_ application: Application) {
_ = shell("/usr/bin/xcrun", arguments: ["simctl", "uninstall", application.device.UDID, application.bundleID])
}

static func boot(_ application: Application) {
_ = shell("/usr/bin/xcrun", arguments: ["simctl", "boot", application.device.UDID])
}

static func run(_ application: Application) {
_ = shell("/usr/bin/open", arguments: ["-a", "Simulator"])
}

static func launch(_ application: Application) {
_ = shell("/usr/bin/xcrun", arguments: ["simctl", "launch", application.device.UDID, application.bundleID])
}

static func uninstall(_ application: Application) {
_ = shell("/usr/bin/xcrun", arguments: ["simctl", "uninstall", application.device.UDID, application.bundleID])
}

static func listDevices(callback: @escaping ([Runtime]) -> ()) {
getDevicesJson(currentAttempt: 0) { (jsonString) in
guard let data = jsonString.data(using: String.Encoding.utf8) else {
Expand Down
1 change: 1 addition & 0 deletions OpenSim/pt-BR.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"Action.RevealInFinder" = "Abrir Sandbox no Finder";
"Action.CopyPathPasteboard" = "Copiar caminho do Sandbox para o Pasteboard";
"Action.OpenInTerminal" = "Abrir Sandbox no Terminal";
"Action.Launch" = "Abrir App";
"Action.Uninstall" = "Desinstalar";
"Action.UninstallAlertConfirmButton" = "Desinstalar";
"Action.UninstallAlertCancelButton" = "Cancelar";
Expand Down

0 comments on commit 317da3e

Please sign in to comment.