|
| 1 | + |
1 | 2 | module RunLoop |
2 | 3 | # @!visibility private |
3 | 4 | module DetectAUT |
4 | 5 | # @!visibility private |
5 | 6 | module Xcode |
| 7 | + require "etc" |
6 | 8 |
|
7 | 9 | # @!visibility private |
8 | 10 | def xcode_project? |
@@ -38,6 +40,19 @@ def find_xcodeproj |
38 | 40 | xcode_projects |
39 | 41 | end |
40 | 42 |
|
| 43 | + # @!visibility private |
| 44 | + def self.find_user_state_file |
| 45 | + username = RunLoop::Environment.username |
| 46 | + xcworkspace = RunLoop::Environment.xcodeproj |
| 47 | + unless xcworkspace.nil? |
| 48 | + xcworkspace = xcworkspace.gsub("xcodeproj", "xcworkspace") |
| 49 | + file = Dir.glob("#{xcworkspace}/xcuserdata/#{username}.xcuserdatad/UserInterfaceState.xcuserstate") |
| 50 | + if !file.nil? && file.is_a?(Array) |
| 51 | + return file[0] |
| 52 | + end |
| 53 | + end |
| 54 | + end |
| 55 | + |
41 | 56 | # @!visibility private |
42 | 57 | def ignore_xcodeproj?(path) |
43 | 58 | path[/CordovaLib/, 0] || |
@@ -151,6 +166,40 @@ def xcode_preferences_plist |
151 | 166 | def pbuddy |
152 | 167 | @pbuddy ||= RunLoop::PlistBuddy.new |
153 | 168 | end |
| 169 | + |
| 170 | + # @!visibility private |
| 171 | + # @param [String] file the plist to read |
| 172 | + # @return [String] the UDID of device |
| 173 | + def self.plist_find_device(file) |
| 174 | + #TODO unfortunately i can use ony this solution |
| 175 | + file_content = `/usr/libexec/PlistBuddy -c Print "#{file}"` |
| 176 | + .encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') |
| 177 | + if !file_content.nil? && !file_content.empty? |
| 178 | + lines = file_content.split("\n") |
| 179 | + lines.detect do |line| |
| 180 | + line[/dvtdevice.*:/, 0] |
| 181 | + end |
| 182 | + end |
| 183 | + end |
| 184 | + |
| 185 | + # @!visibility private |
| 186 | + def self.detect_selected_device |
| 187 | + file_name = find_user_state_file |
| 188 | + selected_device = plist_find_device(file_name) |
| 189 | + if selected_device != '' && !selected_device.nil? |
| 190 | + udid = selected_device.split(':')[1] |
| 191 | + selected_device = RunLoop::Device.device_with_identifier(udid) |
| 192 | + #TODO now only returning detected device if simulator detected |
| 193 | + if selected_device.simulator? |
| 194 | + RunLoop.log_info2("Detected simulator selected in Xcode is: #{selected_device}") |
| 195 | + RunLoop.log_info2("If this is not desired simulator, set the DEVICE_TARGET variable") |
| 196 | + selected_device |
| 197 | + |
| 198 | + else |
| 199 | + nil |
| 200 | + end |
| 201 | + end |
| 202 | + end |
154 | 203 | end |
155 | 204 | end |
156 | 205 | end |
|
0 commit comments