Class: RunLoop::SimKeyboardSettings
- Inherits:
-
Object
- Object
- RunLoop::SimKeyboardSettings
- Defined in:
- lib/run_loop/sim_keyboard_settings.rb
Instance Attribute Summary collapse
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#pbuddy ⇒ Object
readonly
Returns the value of attribute pbuddy.
-
#plist ⇒ String
readonly
Get plist path or use existing one.
Instance Method Summary collapse
-
#autocapitalization_enabled? ⇒ Boolean
Checks if plist value that responds for autocapitalization is set to true.
-
#autocorrection_enabled? ⇒ Boolean
Checks if plist value that responds for autocorrection is set to true.
-
#caps_lock_enabled? ⇒ Boolean
Checks if plist value that responds for caps lock is set to true.
-
#enable_autocapitalization(condition) ⇒ Object
Enable/disable keyboard autocapitalization.
-
#enable_autocorrection(condition) ⇒ Object
Enable/disable keyboard autocorrection.
-
#enable_caps_lock(condition) ⇒ Object
Enable/disable keyboard caps lock.
- #ensure_keyboard_tutorial_disabled ⇒ Object
-
#ensure_soft_keyboard_will_show ⇒ Object
Add properties needed for soft keyboard to show into preferences plist.
-
#initialize(device) ⇒ SimKeyboardSettings
constructor
A new instance of SimKeyboardSettings.
-
#preferences_plist_path ⇒ Object
Get preferences plist path.
-
#soft_keyboard_will_show? ⇒ Bool
Check if all the properties needed for the soft keyboard to appear are set Approach to negate ‘true’ and ‘false’ was chosen in order to do not reboot sim too often, as this will cover the cases when the properties are not set which means that keyboard will be shown anyways.
Constructor Details
#initialize(device) ⇒ SimKeyboardSettings
Returns a new instance of SimKeyboardSettings.
5 6 7 8 |
# File 'lib/run_loop/sim_keyboard_settings.rb', line 5 def initialize(device) @device = device @pbuddy = RunLoop::PlistBuddy.new end |
Instance Attribute Details
#device ⇒ Object (readonly)
Returns the value of attribute device.
3 4 5 |
# File 'lib/run_loop/sim_keyboard_settings.rb', line 3 def device @device end |
#pbuddy ⇒ Object (readonly)
Returns the value of attribute pbuddy.
3 4 5 |
# File 'lib/run_loop/sim_keyboard_settings.rb', line 3 def pbuddy @pbuddy end |
#plist ⇒ String (readonly)
Get plist path or use existing one
83 84 85 |
# File 'lib/run_loop/sim_keyboard_settings.rb', line 83 def plist @plist end |
Instance Method Details
#autocapitalization_enabled? ⇒ Boolean
Checks if plist value that responds for autocapitalization is set to true
76 77 78 |
# File 'lib/run_loop/sim_keyboard_settings.rb', line 76 def autocapitalization_enabled? pbuddy.plist_read('KeyboardAutocapitalization', plist) == 'true' end |
#autocorrection_enabled? ⇒ Boolean
Checks if plist value that responds for autocorrection is set to true
62 63 64 |
# File 'lib/run_loop/sim_keyboard_settings.rb', line 62 def autocorrection_enabled? pbuddy.plist_read('KeyboardAutocorrection', plist) == 'true' end |
#caps_lock_enabled? ⇒ Boolean
Checks if plist value that responds for caps lock is set to true
69 70 71 |
# File 'lib/run_loop/sim_keyboard_settings.rb', line 69 def caps_lock_enabled? pbuddy.plist_read('KeyboardCapsLock', plist) == 'true' end |
#enable_autocapitalization(condition) ⇒ Object
Enable/disable keyboard autocapitalization
default: nil(false)
55 56 57 |
# File 'lib/run_loop/sim_keyboard_settings.rb', line 55 def enable_autocapitalization(condition) pbuddy.plist_set('KeyboardAutocapitalization', 'bool', condition, plist) end |
#enable_autocorrection(condition) ⇒ Object
Enable/disable keyboard autocorrection
default: nil(false)
39 40 41 |
# File 'lib/run_loop/sim_keyboard_settings.rb', line 39 def enable_autocorrection(condition) pbuddy.plist_set('KeyboardAutocorrection', 'bool', condition, plist) end |
#enable_caps_lock(condition) ⇒ Object
Enable/disable keyboard caps lock
default: nil(false)
47 48 49 |
# File 'lib/run_loop/sim_keyboard_settings.rb', line 47 def enable_caps_lock(condition) pbuddy.plist_set('KeyboardCapsLock', 'bool', condition, plist) end |
#ensure_keyboard_tutorial_disabled ⇒ Object
31 32 33 |
# File 'lib/run_loop/sim_keyboard_settings.rb', line 31 def ensure_keyboard_tutorial_disabled pbuddy.plist_set('DidShowContinuousPathIntroduction', 'bool', true, plist) end |
#ensure_soft_keyboard_will_show ⇒ Object
Add properties needed for soft keyboard to show into preferences plist
25 26 27 28 29 |
# File 'lib/run_loop/sim_keyboard_settings.rb', line 25 def ensure_soft_keyboard_will_show pbuddy.plist_set('HardwareKeyboardLastSeen', 'bool', false, plist) pbuddy.plist_set('SoftwareKeyboardShownByTouch', 'bool', true, plist) pbuddy.plist_set('AutomaticMinimizationEnabled', 'bool', false, plist) end |
#preferences_plist_path ⇒ Object
Get preferences plist path
91 92 93 94 95 96 |
# File 'lib/run_loop/sim_keyboard_settings.rb', line 91 def preferences_plist_path return nil if device.physical_device? directory = File.join(device.simulator_root_dir, 'data', 'Library', 'Preferences') pbuddy.ensure_plist(directory, 'com.apple.Preferences.plist') end |
#soft_keyboard_will_show? ⇒ Bool
Check if all the properties needed for the soft keyboard to appear are set Approach to negate ‘true’ and ‘false’ was chosen in order to do not reboot sim too often, as this will cover the cases when the properties are not set which means that keyboard will be shown anyways
16 17 18 19 20 21 22 |
# File 'lib/run_loop/sim_keyboard_settings.rb', line 16 def soft_keyboard_will_show? hw_keyboard_disabled = pbuddy.plist_read('HardwareKeyboardLastSeen', plist) != 'true' soft_keyboard_enabled = pbuddy.plist_read('SoftwareKeyboardShownByTouch', plist) != 'false' minimization_disabled = pbuddy.plist_read('AutomaticMinimizationEnabled', plist) != 'true' hw_keyboard_disabled && minimization_disabled && soft_keyboard_enabled end |