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 0000000..0446014 Binary files /dev/null and b/OpenSim/Assets.xcassets/launch.imageset/launch.png differ diff --git a/OpenSim/Assets.xcassets/launch.imageset/launch@2x.png b/OpenSim/Assets.xcassets/launch.imageset/launch@2x.png new file mode 100644 index 0000000..6893939 Binary files /dev/null and b/OpenSim/Assets.xcassets/launch.imageset/launch@2x.png differ 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";