Sha256: 9153621ea569036a7b03546a0f82961623f0239ce049f4b620f65a94725ff176

Contents?: true

Size: 985 Bytes

Versions: 4

Compression:

Stored size: 985 Bytes

Contents

module SimCtl
  class Command
    module Launch
      XCODE_HOME = `xcode-select -p`.chomp
      SUPPORTED_SCALE = [1.0, 0.75, 0.5, 0.25]

      # Launches a Simulator instance with the given device
      #
      # @param device [SimCtl::Device] the device to launch
      # @return [void]
      def launch_device(device, scale=1.0, opts={})
        raise "unsupported scale '#{scale}' (supported: #{SUPPORTED_SCALE.join(', ')})" unless SUPPORTED_SCALE.include?(scale)
        # Launching the same device twice does not work.
        # Simulator.app would just hang. Solution: Kill first.
        kill_device(device)
        args = {
          '-ConnectHardwareKeyboard' => 1,
          '-CurrentDeviceUDID' => device.udid,
          "-SimulatorWindowLastScale-#{device.devicetype.identifier}" => scale,
        }.merge(opts).zip.flatten.join(' ')
        command = "open -Fgn #{XCODE_HOME}/Applications/Simulator.app --args #{args}"
        system command
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
simctl-1.4.1 lib/simctl/command/launch.rb
simctl-1.4.0 lib/simctl/command/launch.rb
simctl-1.3.1 lib/simctl/command/launch.rb
simctl-1.3.0 lib/simctl/command/launch.rb