Skip to content

Commit

Permalink
Merge pull request #866 from zebrunner/develop
Browse files Browse the repository at this point in the history
2.6.2 rc
  • Loading branch information
vdelendik authored Jan 10, 2024
2 parents d404b9f + 653b199 commit 8c0f75a
Show file tree
Hide file tree
Showing 17 changed files with 378 additions and 90 deletions.
6 changes: 5 additions & 1 deletion lib/db/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1531,11 +1531,15 @@ dbapi.sizeIosDevice = function(message) {
return db.run(r.table('devices').get(message.id).update({
display: {
height: message.height,
width: message.width
width: message.width,
scale: message.scale
}
}
))
}
dbapi.getDeviceSize = function(serial) {
return db.run(r.table('devices').get(serial).pluck('display'))
}
dbapi.checkIosDeviceConnected = function(data) {
return db.run(r.table('devices').get(data.id))
}
Expand Down
13 changes: 13 additions & 0 deletions lib/units/api/controllers/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@ function getDeviceBySerial(req, res) {
})
}

function getDeviceSize (req, res) {
var serial = req.swagger.params.serial.value
dbapi.getDeviceSize(serial)
.then(response => {
return res.status(200).json(response.display)
})
.catch(function(err) {
apiutil.internalError(res, 'Failed to get device size', err.stack)
return apiutil.respond(res, 404, 'Not Found (device)')
})
}

function getDeviceGroups(req, res) {
const serial = req.swagger.params.serial.value
const fields = req.swagger.params.fields.value
Expand Down Expand Up @@ -563,6 +575,7 @@ module.exports = {
getDevices: getDevices
, putDeviceBySerial: putDeviceBySerial
, getDeviceBySerial: getDeviceBySerial
, getDeviceSize: getDeviceSize
, getDeviceGroups: getDeviceGroups
, getDeviceBookings: getDeviceBookings
, addOriginGroupDevice: addOriginGroupDevice
Expand Down
35 changes: 35 additions & 0 deletions lib/units/api/swagger/api_v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,32 @@ paths:
$ref: "#/definitions/UnexpectedErrorResponse"
security:
- accessTokenAuth: [ ]
/devices/{serial}/size:
x-swagger-router-controller: devices
get:
summary: Gets the size of a device
description: Gets the size of a device
operationId: getDeviceSize
tags:
- user
parameters:
- name: serial
in: path
description: Device identifier (serial)
required: true
type: string
responses:
"200":
description: Device size information
schema:
$ref: "#/definitions/SizeResponse"
default:
description: >
Unexpected Error:
* 404: Not Found => unknown device
* 500: Internal Server Error
schema:
$ref: "#/definitions/ErrorResponse"
/devices/groups/{id}:
x-swagger-router-controller: devices
put:
Expand Down Expand Up @@ -2331,6 +2357,15 @@ definitions:
type: array
items:
type: object
SizeResponse:
required:
- height
- width
properties:
height:
type: integer
width:
type: integer
DeviceResponse:
required:
- success
Expand Down
44 changes: 44 additions & 0 deletions lib/units/api/swagger/api_v1_generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,39 @@
]
}
},
"/devices/{serial}/size": {
"get": {
"summary": "Gets the size of a device",
"description": "Gets the size of a device",
"operationId": "getDeviceSize",
"tags": [
"user"
],
"parameters": [
{
"name": "serial",
"in": "path",
"description": "Device identifier (serial)",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "Device size information",
"schema": {
"$ref": "#/definitions/SizeResponse"
}
},
"default": {
"description": "Unexpected Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
}
}
},
"/swagger.json": {}
},
"definitions": {
Expand Down Expand Up @@ -488,6 +521,17 @@
"type": "string"
}
}
},
"SizeResponse": {
"required": ["height", "width"],
"properties": {
"height": {
"type": "integer"
},
"width": {
"type": "integer"
}
}
}
},
"securityDefinitions": {
Expand Down
85 changes: 52 additions & 33 deletions lib/units/ios-device/plugins/wda/WdaClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,41 +453,60 @@ module.exports = syrup.serial()
size: function() {
log.info('getting device window size...')

// #556: Get device size from RethinkDB
return this.handleRequest({
method: 'GET',
uri: `${this.baseUrl}/session/${this.sessionId}/window/size`,
uri: `${options.storageUrl}api/v1/devices/${options.serial}/size`,
})
.then((windowSizeResponse) => {
try {
this.deviceSize = JSON.parse(windowSizeResponse).value
let {height, width} = this.deviceSize

return this.handleRequest({
method: 'GET',
uri: `${this.baseUrl}/session/${this.sessionId}/wda/screen`,
})
.then((wdaScreenResponse) => {
const {scale} = JSON.parse(wdaScreenResponse).value

height *= scale
width *= scale

push.send([
wireutil.global,
wireutil.envelope(new wire.SizeIosDevice(
options.serial,
height,
width,
))
])

return this.deviceSize
let {height, width, scale} = JSON.parse(windowSizeResponse)

// First device session
if (!height || !width || !scale) {
return this.handleRequest({
method: 'GET',
uri: `${this.baseUrl}/session/${this.sessionId}/window/size`,
}).then((firstSessionSize) => {
this.deviceSize = JSON.parse(firstSessionSize).value
let {height, width} = this.deviceSize

return this.handleRequest({
method: 'GET',
uri: `${this.baseUrl}/session/${this.sessionId}/wda/screen`,
})
.then((wdaScreenResponse) => {
const {scale} = JSON.parse(wdaScreenResponse).value

log.info(scale)

height *= scale
width *= scale

log.info('Storing device size/scale')

push.send([
wireutil.global,
wireutil.envelope(new wire.SizeIosDevice(
options.serial,
height,
width,
scale
))
])

return this.deviceSize
})
})
}
catch (e) {
throw new Error('Failed to parse json window size response object')
}
})
} else {
log.info('Reusing device size/scale')
if (this.orientation === 'PORTRAIT') {
this.deviceSize = { height: height /= scale, width: width /= scale }
} else if (this.orientation === 'LANDSCAPE') {
this.deviceSize = { height: width /= scale, width: height /= scale }
}
return this.deviceSize
}
})
},
setVersion: function(currentSession) {
log.info('Setting device version: ' + currentSession.value.capabilities.sdkVersion)
Expand Down Expand Up @@ -668,10 +687,10 @@ module.exports = syrup.serial()
return resolve(response)
})
.catch(err => {
let errMes = err.error.value.message
let errMes = err.error.value.message ? err.error.value.message : ''

// #762: Skip lock error message
if (errMes.includes('Timed out while waiting until the screen gets locked')) {
// #762 & #864: Skip lock/unlock error messages
if (errMes.includes('Timed out while waiting until the screen gets locked') || errMes.includes('unlocked')) {
return
}

Expand Down
22 changes: 13 additions & 9 deletions lib/units/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,9 @@ module.exports = function(options) {
log.info('output promise resolve ',resolve)
privateTracker.once('register', resolve)
})

register.catch(function(err) {
log.fatal('Register promise error', err)
lifecycle.fatal()
.catch((err) => {
// #444 Exit process on EHOSTUNREACH
lifecycle.graceful(err)
})

// Spawn a device worker
Expand Down Expand Up @@ -294,11 +293,16 @@ module.exports = function(options) {
, device.id
, err.code
)
log.info('Restarting device worker "%s"', device.id)
return Promise.delay(500)
.then(function() {
return work()
})
// #847 exit process and set Unhealthy status,
// not restarting since it must be reviewed manually
push.send([
wireutil.global,
wireutil.envelope(new wire.DeviceStatusMessage(
device.id,
7
))
])
return Promise.delay(3000).then(lifecycle.graceful(err))
}
})
}
Expand Down
1 change: 1 addition & 0 deletions lib/wire/wire.proto
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ message SizeIosDevice{
required string id = 1;
required double height = 2;
required double width = 3;
required int32 scale = 4;
}
message DashboardOpenMessage {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ module.exports = function() {
resetData: '&'
},
template: require('./column-choice.pug'),
link: function (scope) {
if (!localStorage.getItem('deviceData')) {
scope.resetData()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = function EnhanceDeviceServiceFactory($filter, AppState) {
}

function enhanceDevice(device) {
device.enhancedName = device.marketName || device.name || device.model || device.serial || 'Unknown'
device.enhancedName = device.model || device.product || device.marketName || device.serial || 'Unknown'
device.enhancedModel = device.model || 'Unknown'
device.enhancedImage120 = '/static/app/devices/icon/x120/' + (device.platform || device.image || '_default.jpg')
device.enhancedImage24 = '/static/app/devices/icon/x24/' + (device.platform || device.image || '_default.jpg')
Expand All @@ -62,12 +62,12 @@ module.exports = function EnhanceDeviceServiceFactory($filter, AppState) {
device.enhancedStatePassive = $filter('statusNamePassive')('available')
return
}
if (device.ios && device.status === 1) {
if (device.status === 1) {
device.enhancedStateAction = $filter('statusNameAction')('offline')
device.enhancedStatePassive = $filter('statusNamePassive')('offline')
return
}
if (device.ios && device.status === 7) {
if (device.status === 7) {
device.enhancedStateAction = $filter('statusNameAction')('unhealthy')
device.enhancedStatePassive = $filter('statusNamePassive')('unhealthy')
return
Expand Down
6 changes: 5 additions & 1 deletion res/app/components/stf/screen/screen-directive.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const _ = require('lodash') // TODO: import debounce only
const rotator = require('./rotator')
const ImagePool = require('./imagepool')
const Promise = require('bluebird')

module.exports = function DeviceScreenDirective(
$document,
Expand All @@ -21,10 +22,13 @@ module.exports = function DeviceScreenDirective(
template: require('./screen.pug'),
scope: {
control: '<',
device: '<',
device: '=',
},
link: function($scope, $element) {
// eslint-disable-next-line prefer-destructuring
if ($scope.device.ios && $scope.device.present && (!$scope.device.display.width || !$scope.device.display.height)) {
Promise.delay(1000).then(() => window.location.reload())
}
const element = $element[0]
const URL = window.URL || window.webkitURL
const BLANK_IMG = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='
Expand Down
2 changes: 1 addition & 1 deletion res/app/device-list/column/device-column-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ function compareRespectCase(a, b) {
return 0
}
else {
return a < b ? -1 : 1
return a.localeCompare(b)
}
}

Expand Down
Loading

0 comments on commit 8c0f75a

Please sign in to comment.