mirror of
https://github.com/openstf/stf
synced 2025-10-06 03:50:04 +02:00
Add Native Url opener service.
Chat temporarily enabled with the Native Url opener.
This commit is contained in:
parent
430103a913
commit
769a6b1d78
6 changed files with 118 additions and 5 deletions
4
res/app/components/stf/native-url/index.js
Normal file
4
res/app/components/stf/native-url/index.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
module.exports = angular.module('stf.native-url', [
|
||||||
|
|
||||||
|
])
|
||||||
|
.factory('NativeUrlService', require('./native-url-service'))
|
89
res/app/components/stf/native-url/native-url-service.js
Normal file
89
res/app/components/stf/native-url/native-url-service.js
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
module.exports = function NativeUrlServiceFactory($window, $timeout) {
|
||||||
|
var service = {}
|
||||||
|
|
||||||
|
// Ways of opening native URLs:
|
||||||
|
// - window.open
|
||||||
|
// - window.location.href
|
||||||
|
|
||||||
|
// Ways of detecting failure:
|
||||||
|
// - new window timeout
|
||||||
|
// - window onblur timeout
|
||||||
|
// - javascript single thread time elapsed
|
||||||
|
|
||||||
|
// Browser Behaviours:
|
||||||
|
// - Chrome Mac: 25ms timeout OK
|
||||||
|
// - Firefox Mac: 250ms timeout OK, 1000ms timeout better
|
||||||
|
// - Safari Mac: no working fallback, may need 2 html pages
|
||||||
|
// navigator.userAgent.match()
|
||||||
|
// TODO: Find which method works well in every browser
|
||||||
|
|
||||||
|
var fallbackMethod = 'USE_ON_BLUR'
|
||||||
|
|
||||||
|
var wasBlured = false
|
||||||
|
var windowOpened
|
||||||
|
|
||||||
|
// TODO: use a central on-blur event
|
||||||
|
var cachedWindowOnBlur = $window.onblur
|
||||||
|
|
||||||
|
service.open = function (options) {
|
||||||
|
|
||||||
|
switch (fallbackMethod) {
|
||||||
|
case 'USE_NEW_WINDOW':
|
||||||
|
// Doesn't work well on Chrome
|
||||||
|
windowOpened = $window.open(options.nativeUrl)
|
||||||
|
|
||||||
|
$timeout(function () {
|
||||||
|
if (windowOpened) {
|
||||||
|
windowOpened.close()
|
||||||
|
}
|
||||||
|
}, 500)
|
||||||
|
|
||||||
|
$window.location.href = options.webUrl
|
||||||
|
break;
|
||||||
|
case 'USE_ON_BLUR':
|
||||||
|
// Doesn't work on Safari
|
||||||
|
|
||||||
|
$window.onblur = function () {
|
||||||
|
wasBlured = true
|
||||||
|
}
|
||||||
|
|
||||||
|
$window.location.href = options.nativeUrl
|
||||||
|
|
||||||
|
$timeout(function () {
|
||||||
|
if (wasBlured) {
|
||||||
|
wasBlured = false
|
||||||
|
} else {
|
||||||
|
$window.open(options.webUrl, '_blank')
|
||||||
|
}
|
||||||
|
|
||||||
|
$window.onblur = cachedWindowOnBlur
|
||||||
|
}, 250)
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'USE_TIME_ELAPSED':
|
||||||
|
// Doesn't work on Chrome
|
||||||
|
|
||||||
|
var start, end, elapsed
|
||||||
|
start = new Date().getTime()
|
||||||
|
|
||||||
|
console.log(' window.performance.webkitNow()', window.performance.now())
|
||||||
|
|
||||||
|
// This depends on the fact that JS is single-thread
|
||||||
|
document.location = options.nativeUrl
|
||||||
|
|
||||||
|
end = new Date().getTime()
|
||||||
|
|
||||||
|
elapsed = (end - start)
|
||||||
|
|
||||||
|
if (elapsed < 1) {
|
||||||
|
document.location = options.webUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return service
|
||||||
|
}
|
11
res/app/components/stf/native-url/native-url-spec.js
Normal file
11
res/app/components/stf/native-url/native-url-spec.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
describe('NativeUrlService', function() {
|
||||||
|
|
||||||
|
beforeEach(angular.mock.module(require('./').name))
|
||||||
|
|
||||||
|
it('should ...', inject(function(NativeUrlService) {
|
||||||
|
|
||||||
|
//expect(NativeUrlService.doSomething()).toEqual('something')
|
||||||
|
|
||||||
|
}))
|
||||||
|
|
||||||
|
})
|
|
@ -3,7 +3,8 @@ require('./menu.css')
|
||||||
module.exports = angular.module('stf.menu', [
|
module.exports = angular.module('stf.menu', [
|
||||||
require('stf/nav-menu').name,
|
require('stf/nav-menu').name,
|
||||||
require('stf/settings').name,
|
require('stf/settings').name,
|
||||||
require('stf/common-ui/modals/external-url-modal').name
|
require('stf/common-ui/modals/external-url-modal').name,
|
||||||
|
require('stf/native-url').name
|
||||||
])
|
])
|
||||||
.controller('MenuCtrl', require('./menu-controller'))
|
.controller('MenuCtrl', require('./menu-controller'))
|
||||||
.run(["$templateCache", function ($templateCache) {
|
.run(["$templateCache", function ($templateCache) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module.exports = function MenuCtrl($scope, $rootScope, SettingsService,
|
module.exports = function MenuCtrl($scope, $rootScope, SettingsService,
|
||||||
$location, ExternalUrlModalService) {
|
$location, ExternalUrlModalService, NativeUrlService) {
|
||||||
|
|
||||||
SettingsService.bind($scope, {
|
SettingsService.bind($scope, {
|
||||||
target: 'lastUsedDevice'
|
target: 'lastUsedDevice'
|
||||||
|
@ -15,8 +15,16 @@ module.exports = function MenuCtrl($scope, $rootScope, SettingsService,
|
||||||
})
|
})
|
||||||
|
|
||||||
$scope.openChat = function () {
|
$scope.openChat = function () {
|
||||||
var hipChatUrl = 'https://cyberagent.hipchat.com/chat?focus_jid=' +
|
var hipChatNativeUrl = 'hipchat://cyberagent.hipchat.com/room/stf'
|
||||||
|
|
||||||
|
var hipChatWebUrl = 'https://cyberagent.hipchat.com/chat?focus_jid=' +
|
||||||
'44808_stf@conf.hipchat.com&minimal=true'
|
'44808_stf@conf.hipchat.com&minimal=true'
|
||||||
ExternalUrlModalService.open(hipChatUrl, 'HipChat #STF', 'fa-comment')
|
|
||||||
|
NativeUrlService.open({
|
||||||
|
nativeUrl: hipChatNativeUrl,
|
||||||
|
webUrl: hipChatWebUrl
|
||||||
|
})
|
||||||
|
|
||||||
|
//ExternalUrlModalService.open(hipChatUrl, 'HipChat #STF', 'fa-comment')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
.btn-group
|
.btn-group
|
||||||
button(type='button', ng-model='$root.platform', btn-radio="'web'", translate).btn.btn-sm.btn-default-outline Web
|
button(type='button', ng-model='$root.platform', btn-radio="'web'", translate).btn.btn-sm.btn-default-outline Web
|
||||||
button(type='button', ng-model='$root.platform', btn-radio="'native'", translate).btn.btn-sm.btn-default-outline Native
|
button(type='button', ng-model='$root.platform', btn-radio="'native'", translate).btn.btn-sm.btn-default-outline Native
|
||||||
//li(ng-if='!$root.basicMode')
|
li(ng-if='!$root.basicMode')
|
||||||
a(ng-click='openChat()').pointer
|
a(ng-click='openChat()').pointer
|
||||||
i.fa.fa-comment.fa-fw
|
i.fa.fa-comment.fa-fw
|
||||||
| {{ "Chat" | translate }}
|
| {{ "Chat" | translate }}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue