-
Notifications
You must be signed in to change notification settings - Fork 12
/
cordova.client.js
115 lines (102 loc) · 2.84 KB
/
cordova.client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
export default (ctx, inject) => {
const { app } = ctx
const cordovaApp = {
// Application Constructor
initialize() {
document.addEventListener(
'deviceready',
this.onDeviceReady.bind(this),
false
)
},
// deviceready Event Handler
//
// Bind any cordova events here. Common events are:
// 'pause', 'resume', etc.
onDeviceReady() {
/**
* initialize all different stuff here:
* e.g.
* - sentry
* - firebase
* - adjust
* - push notifications
* - fabric
* - custom url schema
* - facebook
* - universal links
* - google analytics
* - ...
*
* context to "app" is avaialble, but beware only the app scope of a plugin (which means if any other plugin
* extends the app scope, it could be that it is not available yet)
*/
try {
this.initStatusBar()
} catch (err) {
// console.error('status bar failed', err)
}
try {
this.initWKWebView()
} catch (err) {
// console.error('init WKWebView failed', err)
}
try {
this.initCustomUrlScheme()
} catch (err) {}
},
initCustomUrlScheme() {
window.handleOpenURL = url => {
alert('DeepLink: ' + url)
}
},
initStatusBar() {
window.StatusBar.overlaysWebView(false)
window.StatusBar.backgroundColorByHexString('#009896')
},
initWKWebView() {
/* window.WkWebView.allowsBackForwardNavigationGestures(false)
EventBus.$on('OpenInsidePages', count => {
if (count > 0) {
window.WkWebView.allowsBackForwardNavigationGestures(true)
} else {
window.WkWebView.allowsBackForwardNavigationGestures(false)
}
}) */
}
}
cordovaApp.initialize()
// patch redirect url for cordova - removes "formatUrl" call because it add "//" to the path
app.context.redirect = (status, path, query) => {
if (!status) {
return
}
app.context._redirected = true
// if only 1 or 2 arguments: redirect('/') or redirect('/', { foo: 'bar' })
let pathType = typeof path
if (
typeof status !== 'number' &&
(pathType === 'undefined' || pathType === 'object')
) {
query = path || {}
path = status
pathType = typeof path
status = 302
}
if (pathType === 'object') {
path = app.router.resolve(path).href
}
// "/absolute/route", "./relative/route" or "../relative/route"
if (/(^[.]{1,2}\/)|(^\/(?!\/))/.test(path)) {
app.context.next({
path: path,
query: query,
status: status
})
} else {
// https://developer.mozilla.org/en-US/docs/Web/API/Location/replace
// path = formatUrl(path, query) removed
window.location.replace(path)
}
}
}