1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 10:39:25 +02:00
OpenSTF/res/app/components/stf/standalone/standalone-service.js
2014-09-24 20:05:39 +09:00

81 lines
2.2 KiB
JavaScript

module.exports =
function StandaloneServiceFactory($window, $rootScope, SettingsService,
ScalingService, GroupService) {
var service = {}
service.windows = []
//SettingsService.sync($scope, 'ControlWindow', {
// controlWindowWidth: 600,
// controlWindowHeight: 900,
// controlWindowTop: 50,
// controlWindowLeft: 50
//})
var screenWidth = $window.screen.availWidth || $window.screen.width || 1024
var screenHeight = $window.screen.availHeight || $window.screen.height ||
768
var windowSizeRatio = 0.5
function fitDeviceInGuestScreen(device) {
//console.log('device.width', device.width)
//console.log('device', device)
var screen = {
scaler: ScalingService.coordinator(
device.display.width, device.display.height
),
rotation: device.display.rotation,
bounds: {
x: 0, y: 0, w: screenWidth, h: screenHeight
}
}
var projectedSize = screen.scaler.projectedSize(
screen.bounds.w * windowSizeRatio,
screen.bounds.h * windowSizeRatio,
screen.rotation
)
return projectedSize
}
service.open = function (device) {
var url = '#!/c/' + (device.serial ? device.serial : '')
var projected = fitDeviceInGuestScreen(device)
var features = [
'width=' + projected.width,
'height=' + projected.height,
//'top=' + 0,
//'left=' + 0,
'toolbar=no',
'location=no',
'dialog=yes',
'personalbar=no',
'directories=no',
'status=no',
'menubar=no',
'scrollbars=no',
'copyhistory=no',
'resizable=yes'
].join(',')
var newWindow = $window.open(url, 'STFNewWindow' + Date.now(), features)
newWindow.onbeforeunload = function () {
GroupService.kick(device).then(function () {
$rootScope.$digest()
})
// $scope.controlWindowWidth = windowOpen.innerWidth
// $scope.controlWindowHeight = windowOpen.innerHeight
// $scope.controlWindowTop = windowOpen.screenTop
// $scope.controlWindowLeft = windowOpen.screenLeft
}
}
return service
}