run_loop 3.0.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 817a12d7f14f96e66f30aa4546bda3ea259bfb48e657a56050fa48e1d17c46ad
4
- data.tar.gz: 70a9d1bb177ef17ffa1b9af759ed3a6615d5aaa33d9e8206ef3b4b8bfa3cf131
3
+ metadata.gz: 773e38132d69d69b39507b5df09c9474e4f6ede3d1dc8be2fcb4059a4daf4756
4
+ data.tar.gz: abd675b715e3984defb47b0797853643b1db82a4b7055a3ac8910ed1efdc518e
5
5
  SHA512:
6
- metadata.gz: e5effff4b758df308400477dfeb8c2d9b21e11bb64fb4f4b9221c7571e81bc4fde57ce2ceff0542ebd9fe01ebc303ed6beffa77d83f04a40a41af6db9280d43e
7
- data.tar.gz: 55ca8aeaa8b7951e816d824b720b7d46d983680140a9a7d055d2995ac0d30398df72475c2b5f9a579ce9fff6ae9836494b1139abde0271ba23017503a188ab4b
6
+ metadata.gz: f40b4a0e2fc0efd7293086396f70cb23a4a97f135b248cf35863d0bcaf5563dbee7927cfc2cd35c0eb88da5c6e0fe5db6762f8806b743a142f0fc4bb62431f5a
7
+ data.tar.gz: 7dbbf670bcad98456db942bc6ef8a0ae1bc0c05144112f7cbc2b8a5b1562e4a42ade9bbb4d1e621d3aaf2934dcb5ff07403001a5031c6e82e6c72509f7a7c9ef
@@ -40,6 +40,7 @@ require 'run_loop/lipo'
40
40
  require "run_loop/otool"
41
41
  require "run_loop/strings"
42
42
  require 'run_loop/cache'
43
+ require "run_loop/sim_keyboard_settings"
43
44
  require 'run_loop/patches/awesome_print'
44
45
  require 'run_loop/core_simulator'
45
46
  require "run_loop/simctl"
@@ -45,6 +45,9 @@ class RunLoop::CoreSimulator
45
45
  # @!visibility private
46
46
  attr_reader :xcrun
47
47
 
48
+ # @!visibility private
49
+ attr_reader :sim_keyboard
50
+
48
51
  # @!visibility private
49
52
  METADATA_PLIST = '.com.apple.mobile_container_manager.metadata.plist'
50
53
 
@@ -400,6 +403,11 @@ class RunLoop::CoreSimulator
400
403
  @xcrun ||= RunLoop::Xcrun.new
401
404
  end
402
405
 
406
+ # @!visibility private
407
+ def sim_keyboard
408
+ @sim_keyboard ||= RunLoop::SimKeyboardSettings.new(device)
409
+ end
410
+
403
411
  # @!visibility private
404
412
  def simctl
405
413
  @simctl ||= RunLoop::Simctl.new
@@ -424,7 +432,7 @@ class RunLoop::CoreSimulator
424
432
 
425
433
  RunLoop::CoreSimulator.quit_simulator
426
434
  RunLoop::CoreSimulator.ensure_hardware_keyboard_connected(pbuddy)
427
- device.simulator_ensure_software_keyboard_will_show
435
+ sim_keyboard.ensure_soft_keyboard_will_show
428
436
 
429
437
  args = ['open', '-g', '-a', sim_app_path, '--args',
430
438
  '-CurrentDeviceUDID', device.udid,
@@ -446,11 +454,6 @@ class RunLoop::CoreSimulator
446
454
  options = { :timeout => 5, :raise_on_timeout => true }
447
455
  RunLoop::ProcessWaiter.new(sim_name, options).wait_for_any
448
456
 
449
- # open -g no longer launches application in the background. We want the
450
- # Simulator to open in the background because when it is opened in the
451
- # foreground, it steals (key application) focus which is disruptive.
452
- send_simulator_to_background
453
-
454
457
  if merged_options[:wait_for_stable]
455
458
  device.simulator_wait_for_stable_state
456
459
  end
@@ -678,23 +681,6 @@ Command had no output.
678
681
  hash
679
682
  end
680
683
 
681
- # @!visibility private
682
- def send_simulator_to_background
683
- script = "tell application \"System Events\" to tell process \"#{sim_name}\" to set visible to false"
684
- begin
685
- system("osascript", "-e", script)
686
- rescue => _
687
- RunLoop.log_debug("Could not put simulator into the background")
688
- end
689
-
690
- script = "tell application \"System Events\" to tell process \"#{sim_name}\" to set visible to true"
691
- begin
692
- system("osascript", "-e", script)
693
- rescue => _
694
- RunLoop.log_debug("Could not put simulator into the foreground")
695
- end
696
- end
697
-
698
684
  # @!visibility private
699
685
  def uninstall_app_with_simctl
700
686
  launch_simulator
@@ -824,7 +810,7 @@ Command had no output.
824
810
  return true
825
811
  end
826
812
 
827
- if !device.simulator_software_keyboard_will_show?
813
+ if !sim_keyboard.soft_keyboard_will_show?
828
814
  RunLoop.log_debug("Simulator relaunch required: software keyboard is minimized")
829
815
  return true
830
816
  end
@@ -40,7 +40,6 @@ module RunLoop
40
40
  attr_reader :state
41
41
  attr_reader :simulator_root_dir
42
42
  attr_reader :simulator_accessibility_plist_path
43
- attr_reader :simulator_preferences_plist_path
44
43
  attr_reader :simulator_log_file_path
45
44
 
46
45
  # Create a new device.
@@ -325,14 +324,6 @@ version: #{version}
325
324
  pbuddy.ensure_plist(directory, "com.apple.Accessibility.plist")
326
325
  end
327
326
 
328
- # @!visibility private
329
- def simulator_preferences_plist_path
330
- return nil if physical_device?
331
-
332
- directory = File.join(simulator_root_dir, "data", "Library", "Preferences")
333
- pbuddy.ensure_plist(directory, "com.apple.Preferences.plist")
334
- end
335
-
336
327
  # @!visibility private
337
328
  def simulator_log_file_path
338
329
  return nil if physical_device?
@@ -536,16 +527,6 @@ Could not update the Simulator languages.
536
527
  running_apps
537
528
  end
538
529
 
539
- def simulator_software_keyboard_will_show?
540
- plist = simulator_preferences_plist_path
541
- pbuddy.plist_read("AutomaticMinimizationEnabled", plist).to_i == 0
542
- end
543
-
544
- def simulator_ensure_software_keyboard_will_show
545
- plist = simulator_preferences_plist_path
546
- pbuddy.plist_set("AutomaticMinimizationEnabled", "integer", 0, plist)
547
- end
548
-
549
530
  =begin
550
531
  PRIVATE METHODS
551
532
  =end
@@ -111,6 +111,14 @@ module RunLoop
111
111
  if device.simulator? && app
112
112
  RunLoop::Core.expect_simulator_compatible_arch(device, app)
113
113
 
114
+ # Enable or disable keyboard autocorrection, caps lock and
115
+ # autocapitalization when running on simulator, disables these value by default
116
+ # unless user don't pass true values for these keys
117
+ sim_keyboard = RunLoop::SimKeyboardSettings.new(device)
118
+ sim_keyboard.enable_autocorrection(options[:autocorrection_enabled])
119
+ sim_keyboard.enable_caps_lock(options[:capslock_enabled])
120
+ sim_keyboard.enable_autocapitalization(options[:autocapitalization_enabled])
121
+
114
122
  if merged_options[:relaunch_simulator]
115
123
  RunLoop.log_debug("Detected :relaunch_simulator option; will force simulator to restart")
116
124
  RunLoop::CoreSimulator.quit_simulator
@@ -378,7 +386,13 @@ INSTANCE METHODS
378
386
  response = client.post(request)
379
387
  hash = expect_300_response(response)
380
388
  result = hash["result"]
381
- result.count != 0
389
+
390
+ return false if result.count == 0
391
+ return false if result[0].count == 0
392
+
393
+ element = result[0]
394
+ hit_point = element["hit_point"]
395
+ hit_point["x"] != -1 && hit_point["y"] != -1
382
396
  end
383
397
 
384
398
  # @!visibility private
@@ -233,7 +233,9 @@ in plist:
233
233
  raise(ArgumentError, "expected '#{value_type}' to be one of '#{allowed_value_types}'")
234
234
  end
235
235
  value = args_hash[:value]
236
- unless value
236
+ if value_type == 'bool'
237
+ value = !!value
238
+ elsif !value
237
239
  raise(ArgumentError, ':value is a required key for :add command')
238
240
  end
239
241
  key = args_hash[:key]
@@ -249,8 +251,10 @@ in plist:
249
251
  cmd_part = "Print :#{key}"
250
252
  when :set
251
253
  value = args_hash[:value]
252
- unless value
253
- raise(ArgumentError, ':value is a required key for :set command')
254
+ if args_hash[:type] == 'bool'
255
+ value = !!value
256
+ elsif !value
257
+ raise(ArgumentError, ':value is a required key for :add command')
254
258
  end
255
259
  key = args_hash[:key]
256
260
  unless key
@@ -0,0 +1,94 @@
1
+ module RunLoop
2
+ class SimKeyboardSettings
3
+ attr_reader :pbuddy, :device, :plist
4
+
5
+ def initialize(device)
6
+ @device = device
7
+ @pbuddy = RunLoop::PlistBuddy.new
8
+ end
9
+
10
+ # Check if all the properties needed for the soft keyboard to appear are set
11
+ # Approach to negate 'true' and 'false' was chosen in order to do not
12
+ # reboot sim too often, as this will cover the cases when the properties
13
+ # are not set which means that keyboard will be shown anyways
14
+ #
15
+ # @return [Bool]
16
+ def soft_keyboard_will_show?
17
+ hw_keyboard_disabled = pbuddy.plist_read('HardwareKeyboardLastSeen', plist) != 'true'
18
+ soft_keyboard_enabled = pbuddy.plist_read('SoftwareKeyboardShownByTouch', plist) != 'false'
19
+ minimization_disabled = pbuddy.plist_read('AutomaticMinimizationEnabled', plist) != 'true'
20
+
21
+ hw_keyboard_disabled && minimization_disabled && soft_keyboard_enabled
22
+ end
23
+
24
+ # Add properties needed for soft keyboard to show into preferences plist
25
+ def ensure_soft_keyboard_will_show
26
+ pbuddy.plist_set('HardwareKeyboardLastSeen', 'bool', false, plist)
27
+ pbuddy.plist_set('SoftwareKeyboardShownByTouch', 'bool', true, plist)
28
+ pbuddy.plist_set('AutomaticMinimizationEnabled', 'bool', false, plist)
29
+ end
30
+
31
+ # Enable/disable keyboard autocorrection
32
+ #
33
+ # @param [Boolean] condition, option passed by the user in launch arguments
34
+ # default: nil(false)
35
+ def enable_autocorrection(condition)
36
+ pbuddy.plist_set('KeyboardAutocorrection', 'bool', condition, plist)
37
+ end
38
+
39
+ # Enable/disable keyboard caps lock
40
+ #
41
+ # @param [Boolean] condition, option passed by the user in launch arguments
42
+ # default: nil(false)
43
+ def enable_caps_lock(condition)
44
+ pbuddy.plist_set('KeyboardCapsLock', 'bool', condition, plist)
45
+ end
46
+
47
+ # Enable/disable keyboard autocapitalization
48
+ #
49
+ # @param [Boolean] condition, option passed by the user in launch arguments
50
+ # default: nil(false)
51
+ def enable_autocapitalization(condition)
52
+ pbuddy.plist_set('KeyboardAutocapitalization', 'bool', condition, plist)
53
+ end
54
+
55
+ # Checks if plist value that responds for autocorrection is set to true
56
+ #
57
+ # @return [Boolean]
58
+ def autocorrection_enabled?
59
+ pbuddy.plist_read('KeyboardAutocorrection', plist) == 'true'
60
+ end
61
+
62
+ # Checks if plist value that responds for caps lock is set to true
63
+ #
64
+ # @return [Boolean]
65
+ def caps_lock_enabled?
66
+ pbuddy.plist_read('KeyboardCapsLock', plist) == 'true'
67
+ end
68
+
69
+ # Checks if plist value that responds for autocapitalization is set to true
70
+ #
71
+ # @return [Boolean]
72
+ def autocapitalization_enabled?
73
+ pbuddy.plist_read('KeyboardAutocapitalization', plist) == 'true'
74
+ end
75
+
76
+ # Get plist path or use existing one
77
+ #
78
+ # @return [String] plist path
79
+ def plist
80
+ @plist ||= preferences_plist_path
81
+ end
82
+
83
+ # Get preferences plist path
84
+ #
85
+ # @return nil if doesn't run against simulator
86
+ # @return [String] with path to the plist
87
+ def preferences_plist_path
88
+ return nil if device.physical_device?
89
+
90
+ directory = File.join(device.simulator_root_dir, 'data', 'Library', 'Preferences')
91
+ pbuddy.ensure_plist(directory, 'com.apple.Preferences.plist')
92
+ end
93
+ end
94
+ end
@@ -596,7 +596,7 @@ while trying to list devices.
596
596
 
597
597
  # @!visibility private
598
598
  def device_available?(record)
599
- record["availability"] == "(available)"
599
+ record["isAvailable"] == "YES" || record["availability"] == "(available)"
600
600
  end
601
601
 
602
602
  # @!visibility private
@@ -1,5 +1,5 @@
1
1
  module RunLoop
2
- VERSION = "3.0.1"
2
+ VERSION = "4.0.0"
3
3
 
4
4
  # A model of a software release version that can be used to compare two versions.
5
5
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: run_loop
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Krukow
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-18 00:00:00.000000000 Z
12
+ date: 2018-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '1.8'
20
+ version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '1.8'
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: awesome_print
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -391,6 +391,7 @@ files:
391
391
  - lib/run_loop/process_waiter.rb
392
392
  - lib/run_loop/regex.rb
393
393
  - lib/run_loop/shell.rb
394
+ - lib/run_loop/sim_keyboard_settings.rb
394
395
  - lib/run_loop/simctl.rb
395
396
  - lib/run_loop/strings.rb
396
397
  - lib/run_loop/template.rb