Skip to content

Commit

Permalink
feat: add system screen size/width in the system info endpoint (#881)
Browse files Browse the repository at this point in the history
* feat: add system screen size/width

* simplify

* add nil statusBar case

* tune
  • Loading branch information
KazuCocoa authored Apr 1, 2024
1 parent d89424b commit 5ebc71c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
18 changes: 16 additions & 2 deletions WebDriverAgentLib/Commands/FBCustomCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "FBConfiguration.h"
#import "FBKeyboard.h"
#import "FBNotificationsHelper.h"
#import "FBMathUtils.h"
#import "FBPasteboard.h"
#import "FBResponsePayload.h"
#import "FBRoute.h"
Expand Down Expand Up @@ -48,6 +49,7 @@ + (NSArray *)routes
[[FBRoute GET:@"/wda/locked"].withoutSession respondWithTarget:self action:@selector(handleIsLocked:)],
[[FBRoute GET:@"/wda/locked"] respondWithTarget:self action:@selector(handleIsLocked:)],
[[FBRoute GET:@"/wda/screen"] respondWithTarget:self action:@selector(handleGetScreen:)],
[[FBRoute GET:@"/wda/screen"].withoutSession respondWithTarget:self action:@selector(handleGetScreen:)],
[[FBRoute GET:@"/wda/activeAppInfo"] respondWithTarget:self action:@selector(handleActiveAppInfo:)],
[[FBRoute GET:@"/wda/activeAppInfo"].withoutSession respondWithTarget:self action:@selector(handleActiveAppInfo:)],
#if !TARGET_OS_TV // tvOS does not provide relevant APIs
Expand Down Expand Up @@ -134,10 +136,22 @@ + (NSArray *)routes

+ (id<FBResponsePayload>)handleGetScreen:(FBRouteRequest *)request
{
FBSession *session = request.session;
CGSize statusBarSize = [FBScreen statusBarSizeForApplication:session.activeApplication];
XCUIApplication *app = XCUIApplication.fb_systemApplication;

XCUIElement *mainStatusBar = app.statusBars.allElementsBoundByIndex.firstObject;
CGSize statusBarSize = (nil == mainStatusBar) ? CGSizeZero : mainStatusBar.frame.size;

#if TARGET_OS_TV
CGSize screenSize = app.frame.size;
#else
CGSize screenSize = FBAdjustDimensionsForApplication(app.wdFrame.size, app.interfaceOrientation);
#endif

return FBResponseWithObject(
@{
@"screenSize":@{@"width": @(screenSize.width),
@"height": @(screenSize.height)
},
@"statusBarSize": @{@"width": @(statusBarSize.width),
@"height": @(statusBarSize.height),
},
Expand Down
5 changes: 0 additions & 5 deletions WebDriverAgentLib/Utilities/FBScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (double)scale;

/**
The absolute size of application's status bar or CGSizeZero if it's hidden or does not exist
*/
+ (CGSize)statusBarSizeForApplication:(XCUIApplication *)application;

@end

NS_ASSUME_NONNULL_END
13 changes: 0 additions & 13 deletions WebDriverAgentLib/Utilities/FBScreen.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,4 @@ + (double)scale
return [XCUIScreen.mainScreen scale];
}

+ (CGSize)statusBarSizeForApplication:(XCUIApplication *)application
{
XCUIApplication *app = XCUIApplication.fb_systemApplication;
// Since iOS 13 the status bar is no longer part of the application, it’s part of the SpringBoard
XCUIElement *mainStatusBar = app.statusBars.allElementsBoundByIndex.firstObject;
if (nil == mainStatusBar) {
return CGSizeZero;
}
CGSize result = mainStatusBar.frame.size;
// Workaround for https://github.com/appium/appium/issues/15961
return CGSizeMake(MAX(result.width, result.height), MIN(result.width, result.height));
}

@end
7 changes: 0 additions & 7 deletions WebDriverAgentTests/IntegrationTests/FBScreenTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,5 @@ - (void)testScreenScale
XCTAssertTrue([FBScreen scale] >= 2);
}

- (void)testStatusBarSize
{
CGSize statusBarSize = [FBScreen statusBarSizeForApplication:self.testedApplication];
BOOL statusBarSizeIsZero = CGSizeEqualToSize(CGSizeZero, statusBarSize);
XCTAssertFalse(statusBarSizeIsZero);
}

@end

0 comments on commit 5ebc71c

Please sign in to comment.