static bool ShowDeviceBezels(InspectableWindow window) { var simDefaults = new NSUserDefaults( "com.apple.iphonesimulator", NSUserDefaultsType.SuiteName); const string ShowChromeSetting = "ShowChrome"; return(simDefaults.ValueForKey(new NSString(ShowChromeSetting)) == null ? true : simDefaults.BoolForKey(ShowChromeSetting)); }
// TODO: Replace this when Device Switching work lands, and we know from the AgentProcess what simulator // type is being used. static DeviceShape GetDeviceShape(InspectableWindow window) { if (window.Title.Contains("5s") || window.Title.Contains("SE")) { return(DeviceShape.IPhone5); } else if (window.Title.Contains("X")) { return(DeviceShape.IPhoneX); } else if (window.Title.Contains("Plus")) { return(DeviceShape.IPhoneStandardPlus); } else { return(DeviceShape.IPhoneStandard); } }
static CGRect GetXapHostRect() { foreach (var window in InspectableWindow.GetWindows("com.xamarin.androiddevice", onScreenOnly: false)) { if (window.Title == null || !window.Title.StartsWith("Xamarin Android Player - ", StringComparison.Ordinal)) { continue; } var xapRect = window.Bounds; xapRect.Y += 22; xapRect.Height -= 22; return(xapRect); } return(CGRect.Empty); }
static CGRect GetGoogleHostRect() { // TODO: In the future when we can reliably get Android device name, check title for that. foreach (var window in InspectableWindow.GetWindowMatchingOwnerName( "qemu-system-", onScreenOnly: false)) { if (window.Title == null || !window.Title.StartsWith("Android Emulator - ", StringComparison.Ordinal)) { continue; } var emuRect = window.Bounds; emuRect.Y += 22; emuRect.Height -= 22; return(emuRect); } return(CGRect.Empty); }
public iOSSimulatorCoordinateMapper(AgentIdentity agentIdentity) { // TODO: Pick the correct window with extra information available when Device Switching work // lands. For now, we know we always launch 5s, but in Xcode 9 there may be multiple // sims open simultaneously. var window = InspectableWindow .GetWindows("com.apple.iphonesimulator") .FirstOrDefault(w => w.Title != null && (ClientInfo.Flavor == ClientFlavor.Inspector || w.Title.Contains("5s"))); if (window == null) { Log.Error(TAG, "Unable to locate simulator window"); return; } if (!ShowDeviceBezels(window)) { appBounds = window.Bounds; appBounds.Y += 22; appBounds.Height -= 22; } else { var shape = GetDeviceShape(window); var chromeScale = window.Bounds.Height / GetDeviceFullHeight(shape); var verticalMargin = GetDeviceVerticalMargin(shape) * chromeScale; var horizontalMargin = GetDeviceHorizontalMargin(shape) * chromeScale; appBounds = new CGRect { X = window.Bounds.X + horizontalMargin, Y = window.Bounds.Y + verticalMargin, Width = window.Bounds.Width - (horizontalMargin * 2), Height = window.Bounds.Height - (verticalMargin * 2), }; } scale = agentIdentity.ScreenWidth / appBounds.Width; }