Skip to content

Commit

Permalink
Merge pull request #774 from ignacionar/#770
Browse files Browse the repository at this point in the history
#770 Fixing Landscape when closing device (reset to Portrait mode)
  • Loading branch information
ignacionar authored Aug 17, 2023
2 parents efd402c + f5b74c6 commit b9bacd1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
26 changes: 22 additions & 4 deletions lib/units/ios-device/plugins/screen/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,28 @@ module.exports = syrup.serial()

ws.on('close', function() {
// @TODO handle close event
//stream.socket.onclose()
WdaClient.stopSession()
isConnectionAlive = false
log.important('ws on close event')
// stream.socket.onclose()
const orientation = WdaClient.orientation

const stoppingSession = () => {
WdaClient.stopSession()
isConnectionAlive = false
log.important('ws on close event')
}

if (orientation === 'PORTRAIT') {
return stoppingSession()
}

// #770: Reset rotation to Portrait when closing device

const rotationPromise = new Promise((resolve, reject) => {
// Ensure that rotation is done, then stop session
WdaClient.rotation({orientation: 'PORTRAIT'})
resolve()
})

rotationPromise.then(() => stoppingSession())
})
ws.on('error', function() {
// @TODO handle error event
Expand Down
12 changes: 12 additions & 0 deletions lib/units/ios-device/plugins/util/iosutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ let iosutil = {
return 'UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT'
}
},
orientationToDegrees: function(orientation) {
switch (orientation) {
case 'PORTRAIT':
return 0
case 'LANDSCAPE':
return 90
case 'UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN':
return 180
case 'UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT':
return 270
}
},
pressButton: function(key) {
switch (key) {
case 'volume_up':
Expand Down
28 changes: 24 additions & 4 deletions lib/units/ios-device/plugins/wda/WdaClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ module.exports = syrup.serial()
return Promise.resolve()
}

this.handleRequest({
return this.handleRequest({
method: 'DELETE',
uri: `${this.baseUrl}/session/${currentSessionId}`
})

},
typeKey: function(params) {

Expand Down Expand Up @@ -533,8 +534,17 @@ module.exports = syrup.serial()
this.getOrientation()

this.size()
})

const rotationDegrees = iosutil.orientationToDegrees(this.orientation)

push.send([
wireutil.global,
wireutil.envelope(new wire.RotationEvent(
options.serial,
rotationDegrees
))
])
})
},
batteryIosEvent: function() {
return this.handleRequest({
Expand Down Expand Up @@ -636,13 +646,23 @@ module.exports = syrup.serial()
return resolve(response)
})
.catch(err => {
let errMes = err.error.value.message

// #762: Skip lock error message
if (err.error.value.message.includes('Timed out while waiting until the screen gets locked')) {
if (errMes.includes('Timed out while waiting until the screen gets locked')) {
return
}
if (err.error.value.message.includes('Unable To Rotate Device')) {

// #765: Skip rotation error message
if (errMes.includes('Unable To Rotate Device')) {
return log.info('The current application does not support rotation')
}

// #770 Skip session crash, immediately restart after Portrait mode reset
if (errMes.includes('Session does not exist')) {
return this.startSession()
}

recoverDevice()
// #409: capture wda/appium crash asap and exit with status 1 from stf
//notifier.setDeviceTemporaryUnavialable(err)
Expand Down

0 comments on commit b9bacd1

Please sign in to comment.