forked from owliehq/vue-addtohomescreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (26 loc) · 807 Bytes
/
index.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
import Vue from 'vue'
import addToHomescreen from './addToHomescreen'
import { isStandalone } from './utils'
import Cookies from 'js-cookie'
export default {
install(vue, opts) {
if (!isStandalone() || !Cookies.get('addToHomescreenCalled')) {
window.addEventListener('beforeinstallprompt', e => {
e.preventDefault()
vue.prototype.$deferedAddToHomescreen = e
})
}
Vue.component(addToHomescreen.name, addToHomescreen)
const addToHomescreenProt = {
mount: opt => {
const root = new Vue({
data: opt,
render: createElement => createElement(addToHomescreen)
})
root.$mount(document.body.appendChild(document.createElement('div')))
}
}
//
vue.prototype.$addToHomescreen = addToHomescreenProt
}
}