diff --git a/OpenSim.xcodeproj/project.pbxproj b/OpenSim.xcodeproj/project.pbxproj index 7abf891..b4ecbef 100644 --- a/OpenSim.xcodeproj/project.pbxproj +++ b/OpenSim.xcodeproj/project.pbxproj @@ -37,6 +37,7 @@ B3D188E91BF436480064E851 /* Runtime.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D188E81BF436480064E851 /* Runtime.swift */; }; B3E67B5E1CA412BD00744B38 /* MenuManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3E67B5D1CA412BD00744B38 /* MenuManager.swift */; }; B3F493A61BF0822800C64FF0 /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3F493A51BF0822800C64FF0 /* Application.swift */; }; + B537A3F3228D2D1400E6E51E /* SimulatorMenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B537A3F2228D2D1400E6E51E /* SimulatorMenuItem.swift */; }; D17669C11D1883AE00816D61 /* SimulatorController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D17669C01D1883AE00816D61 /* SimulatorController.swift */; }; /* End PBXBuildFile section */ @@ -74,6 +75,7 @@ B3D188E81BF436480064E851 /* Runtime.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Runtime.swift; sourceTree = ""; }; B3E67B5D1CA412BD00744B38 /* MenuManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuManager.swift; sourceTree = ""; }; B3F493A51BF0822800C64FF0 /* Application.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Application.swift; sourceTree = ""; }; + B537A3F2228D2D1400E6E51E /* SimulatorMenuItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulatorMenuItem.swift; sourceTree = ""; }; D17669C01D1883AE00816D61 /* SimulatorController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimulatorController.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -144,6 +146,7 @@ B32480541EBEB705000633FC /* ActionMenu.swift */, B39B2B621EBEFFB700CDD74C /* AppInfoView.swift */, 312A27FC21A753E600699668 /* Constants.swift */, + B537A3F2228D2D1400E6E51E /* SimulatorMenuItem.swift */, ); name = UI; sourceTree = ""; @@ -275,6 +278,7 @@ B310B99B1D1AA08500D880CA /* ImageExtension.swift in Sources */, B3054E1C1BF3988300F433C2 /* CancelBlocks.swift in Sources */, B3A1E3341BF0709A0090EC58 /* URLHelper.swift in Sources */, + B537A3F3228D2D1400E6E51E /* SimulatorMenuItem.swift in Sources */, B3D188E91BF436480064E851 /* Runtime.swift in Sources */, B39B2B791EBF614400CDD74C /* OpenRealmAction.swift in Sources */, B39B2B771EBF5F4200CDD74C /* ExtraApplicationActionable.swift in Sources */, diff --git a/OpenSim/Base.lproj/Localizable.strings b/OpenSim/Base.lproj/Localizable.strings index e8eac5b..9620133 100644 --- a/OpenSim/Base.lproj/Localizable.strings +++ b/OpenSim/Base.lproj/Localizable.strings @@ -2,6 +2,7 @@ "Menu.LaunchAtLogin" = "Launch at Login"; "Menu.Refresh" = "Refresh"; "Menu.Version" = "Version"; +"Menu.Launch" = "Launch"; "Action.RevealInFinder" = "Reveal Sandbox in Finder"; "Action.CopyPathPasteboard" = "Copy Sandbox Path to Pasteboard"; "Action.OpenInTerminal" = "Open Sandbox in Terminal"; diff --git a/OpenSim/Constants.swift b/OpenSim/Constants.swift index c1a6c59..6767ca5 100644 --- a/OpenSim/Constants.swift +++ b/OpenSim/Constants.swift @@ -8,6 +8,7 @@ struct UIConstants { static let menuLaunchAtLoginButton = NSLocalizedString("Menu.LaunchAtLogin", comment: "Launch at login menu button") static let menuRefreshButton = NSLocalizedString("Menu.Refresh", comment: "Refresh menu button") static let menuVersionLabel = NSLocalizedString("Menu.Version", comment: "Version label") + static let menuLaunchSimulatorButton = NSLocalizedString("Menu.Launch", comment: "Launch") 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") diff --git a/OpenSim/Device.swift b/OpenSim/Device.swift index 1f59151..b2d2d3a 100644 --- a/OpenSim/Device.swift +++ b/OpenSim/Device.swift @@ -75,6 +75,13 @@ extension Device { return false }).first } + + func launch() { + if state != .booted { + SimulatorController.boot(self) + } + SimulatorController.open() + } } extension Device: Decodable { diff --git a/OpenSim/MenuManager.swift b/OpenSim/MenuManager.swift index 5b77958..ff4fdb2 100644 --- a/OpenSim/MenuManager.swift +++ b/OpenSim/MenuManager.swift @@ -73,6 +73,11 @@ protocol MenuManagerDelegate { let submenu = NSMenu() submenu.delegate = self + + // Launch Simulator + let simulatorItem = SimulatorMenuItem(runtime:runtime, device:device) + submenu.addItem(simulatorItem) + submenu.addItem(NSMenuItem.separator()) // Sort applications by name let sortApplications = device.applications?.sorted(by: { (app1, app2) -> Bool in diff --git a/OpenSim/SimulatorController.swift b/OpenSim/SimulatorController.swift index 9153422..ed92627 100755 --- a/OpenSim/SimulatorController.swift +++ b/OpenSim/SimulatorController.swift @@ -15,6 +15,14 @@ struct SimulatorController { _ = shell("/usr/bin/xcrun", arguments: ["simctl", "boot", application.device.UDID]) } + static func boot(_ device: Device) { + _ = shell("/usr/bin/xcrun", arguments: ["simctl", "boot", device.UDID]) + } + + static func open() { + _ = shell("/usr/bin/env", arguments: ["open", "/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/"]) + } + static func run(_ application: Application) { _ = shell("/usr/bin/open", arguments: ["-a", "Simulator"]) } diff --git a/OpenSim/SimulatorMenuItem.swift b/OpenSim/SimulatorMenuItem.swift new file mode 100644 index 0000000..315bee1 --- /dev/null +++ b/OpenSim/SimulatorMenuItem.swift @@ -0,0 +1,37 @@ +// +// SimulatorMenuItem.swift +// OpenSim +// +// Created by Benoit Jadinon on 16/05/2019. +// Copyright © 2019 Luo Sheng. All rights reserved. +// + +import Cocoa + +class SimulatorMenuItem: NSMenuItem { + + var runtime: Runtime! + var device: Device! + + init(runtime: Runtime, device:Device) { + self.runtime = runtime + self.device = device + + let title = "\(UIConstants.strings.menuLaunchSimulatorButton) \(device.name) (\(runtime))" + + super.init(title: title, action: #selector(self.openSimulator(_:)), keyEquivalent: "") + + target = self + + // Default image + //self.image = #imageLiteral(resourceName: "DefaultAppIcon").appIcon() + } + + required init(coder decoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + @objc func openSimulator(_ sender: AnyObject) { + self.device.launch() + } +} diff --git a/OpenSim/pt-BR.lproj/Localizable.strings b/OpenSim/pt-BR.lproj/Localizable.strings index 7beed60..319ee38 100644 --- a/OpenSim/pt-BR.lproj/Localizable.strings +++ b/OpenSim/pt-BR.lproj/Localizable.strings @@ -2,6 +2,7 @@ "Menu.LaunchAtLogin" = "Iniciar junto com sistema"; "Menu.Refresh" = "Atualizar"; "Menu.Version" = "Versão"; +"Menu.Launch" = "Inicie o"; "Action.RevealInFinder" = "Abrir Sandbox no Finder"; "Action.CopyPathPasteboard" = "Copiar caminho do Sandbox para o Pasteboard"; "Action.OpenInTerminal" = "Abrir Sandbox no Terminal";