From 7eadf46720c42a954c28f071d7d69daf4e7dc8f3 Mon Sep 17 00:00:00 2001 From: Arthur da Paz Date: Tue, 30 Apr 2019 12:42:27 -0300 Subject: [PATCH] Added Launch App on Simulator --- OpenSim.xcodeproj/project.pbxproj | 5 +++ OpenSim/ActionMenu.swift | 1 + OpenSim/Application.swift | 8 +++++ .../launch.imageset/Contents.json | 22 +++++++++++++ .../launch.imageset/launch.png | Bin 0 -> 2083 bytes .../launch.imageset/launch@2x.png | Bin 0 -> 2465 bytes OpenSim/Base.lproj/Localizable.strings | 1 + OpenSim/Constants.swift | 1 + OpenSim/LaunchAction.swift | 30 ++++++++++++++++++ OpenSim/SimulatorController.swift | 16 +++++++--- OpenSim/pt-BR.lproj/Localizable.strings | 1 + 11 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 OpenSim/Assets.xcassets/launch.imageset/Contents.json create mode 100644 OpenSim/Assets.xcassets/launch.imageset/launch.png create mode 100644 OpenSim/Assets.xcassets/launch.imageset/launch@2x.png create mode 100644 OpenSim/LaunchAction.swift diff --git a/OpenSim.xcodeproj/project.pbxproj b/OpenSim.xcodeproj/project.pbxproj index acdf0e0..7abf891 100644 --- a/OpenSim.xcodeproj/project.pbxproj +++ b/OpenSim.xcodeproj/project.pbxproj @@ -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 */; }; @@ -40,6 +41,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 256B782B2278A08500052809 /* LaunchAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LaunchAction.swift; sourceTree = ""; }; 312A27FC21A753E600699668 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; 31A79B14219B81660024DF7B /* Simulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Simulator.swift; sourceTree = ""; }; 31C4BF3121A8AC56008B97A1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = ""; }; @@ -155,6 +157,7 @@ B39B2B721EBF573C00CDD74C /* UninstallAction.swift */, B39B2B741EBF58EC00CDD74C /* OpenInItermAction.swift */, B39B2B781EBF614400CDD74C /* OpenRealmAction.swift */, + 256B782B2278A08500052809 /* LaunchAction.swift */, ); name = Actions; sourceTree = ""; @@ -229,6 +232,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, "pt-BR", @@ -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; diff --git a/OpenSim/ActionMenu.swift b/OpenSim/ActionMenu.swift index cc7924d..c21d3d6 100644 --- a/OpenSim/ActionMenu.swift +++ b/OpenSim/ActionMenu.swift @@ -16,6 +16,7 @@ final class ActionMenu: NSMenu { RevealInFinderAction.self, CopyToPasteboardAction.self, OpenInTerminalAction.self, + LaunchAction.self, UninstallAction.self ] diff --git a/OpenSim/Application.swift b/OpenSim/Application.swift index e8d4c00..3507540 100755 --- a/OpenSim/Application.swift +++ b/OpenSim/Application.swift @@ -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) diff --git a/OpenSim/Assets.xcassets/launch.imageset/Contents.json b/OpenSim/Assets.xcassets/launch.imageset/Contents.json new file mode 100644 index 0000000..18b91d6 --- /dev/null +++ b/OpenSim/Assets.xcassets/launch.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "launch.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "launch@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/OpenSim/Assets.xcassets/launch.imageset/launch.png b/OpenSim/Assets.xcassets/launch.imageset/launch.png new file mode 100644 index 0000000000000000000000000000000000000000..04460148851628260dba39b072b5be749794e74e GIT binary patch literal 2083 zcmbVNd2AF_7@wuI(86j(MFfO#ph9D3XJ+piSxCFvV=G(hvV~QG>Fmtx?%17!nb~$* zH03@_5NIl(Z4@HK7>Jv40>oK%B4oUf1ZIp96>(k&WHxpKuzDr7i(ULS_92gxfClzov8 z1ht@VA;n07iDsn`XG#b%Kts^H1qqpE>NpJ!aS>j0A%7kD3W0gng)Fi8aG&hvqI^Y@ z!Yyj53NTG|49Ox3=EL(66d({djfN9KOjN0a3rX@)V6AUs2%LmybuOe>R|p4v)v#Mq zIM`;gqYPoS!4A?y*ezC)EP~BA;lyw!Mp#h7PFZovY=%=00<{yMvx?l;bzQiMgam<8%2#yprSe}&EVlwM&V_Rmqb`+q(f3%b0NUe z5f=nGLo2GOFoA$!30lSo6Rx|I1hPy9C&!goQaQ_DT#OSqQBwhy$YABDq)BR2x(jvY z_zndiv_4-($EdalLPmwEmDU3{QUMtitp*xp4)b%W6jvCov>uo_OZP^m+zLl)k`j=l zSUOSFX_H~MTTc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p>q0JmE|W&Bnao%ha~R*Cj`Q)dH?_b literal 0 HcmV?d00001 diff --git a/OpenSim/Base.lproj/Localizable.strings b/OpenSim/Base.lproj/Localizable.strings index cfa724a..e8eac5b 100644 --- a/OpenSim/Base.lproj/Localizable.strings +++ b/OpenSim/Base.lproj/Localizable.strings @@ -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"; diff --git a/OpenSim/Constants.swift b/OpenSim/Constants.swift index 52db941..c1a6c59 100644 --- a/OpenSim/Constants.swift +++ b/OpenSim/Constants.swift @@ -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") diff --git a/OpenSim/LaunchAction.swift b/OpenSim/LaunchAction.swift new file mode 100644 index 0000000..4534d7b --- /dev/null +++ b/OpenSim/LaunchAction.swift @@ -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() + } +} diff --git a/OpenSim/SimulatorController.swift b/OpenSim/SimulatorController.swift index ca55cd0..9153422 100755 --- a/OpenSim/SimulatorController.swift +++ b/OpenSim/SimulatorController.swift @@ -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 { diff --git a/OpenSim/pt-BR.lproj/Localizable.strings b/OpenSim/pt-BR.lproj/Localizable.strings index d169da8..7beed60 100644 --- a/OpenSim/pt-BR.lproj/Localizable.strings +++ b/OpenSim/pt-BR.lproj/Localizable.strings @@ -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";