Skip to content

Commit

Permalink
Merge pull request #51 from benoitjadinon/master
Browse files Browse the repository at this point in the history
added menu item to start simulator without selecting an app
  • Loading branch information
luosheng authored May 24, 2019
2 parents 317da3e + c86c3aa commit 63d4a0b
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions OpenSim.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -74,6 +75,7 @@
B3D188E81BF436480064E851 /* Runtime.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Runtime.swift; sourceTree = "<group>"; };
B3E67B5D1CA412BD00744B38 /* MenuManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuManager.swift; sourceTree = "<group>"; };
B3F493A51BF0822800C64FF0 /* Application.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Application.swift; sourceTree = "<group>"; };
B537A3F2228D2D1400E6E51E /* SimulatorMenuItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulatorMenuItem.swift; sourceTree = "<group>"; };
D17669C01D1883AE00816D61 /* SimulatorController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimulatorController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -144,6 +146,7 @@
B32480541EBEB705000633FC /* ActionMenu.swift */,
B39B2B621EBEFFB700CDD74C /* AppInfoView.swift */,
312A27FC21A753E600699668 /* Constants.swift */,
B537A3F2228D2D1400E6E51E /* SimulatorMenuItem.swift */,
);
name = UI;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
1 change: 1 addition & 0 deletions OpenSim/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions OpenSim/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions OpenSim/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ extension Device {
return false
}).first
}

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

extension Device: Decodable {
Expand Down
5 changes: 5 additions & 0 deletions OpenSim/MenuManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions OpenSim/SimulatorController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
}
Expand Down
37 changes: 37 additions & 0 deletions OpenSim/SimulatorMenuItem.swift
Original file line number Diff line number Diff line change
@@ -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()
}
}
1 change: 1 addition & 0 deletions OpenSim/pt-BR.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 63d4a0b

Please sign in to comment.