-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
UnsupportedBrowser.vue
203 lines (179 loc) · 5.2 KB
/
UnsupportedBrowser.vue
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!--
- @copyright 2022 John Molakvoæ <[email protected]>
-
- @author John Molakvoæ <[email protected]>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->
<template>
<div class="content-unsupported-browser guest-box">
<NcEmptyContent>
{{ t('core', 'This browser is not supported') }}
<template #icon>
<Web />
</template>
<template #action>
<div>
<h2>
{{ t('core', 'Your browser is not supported. Please upgrade to a newer version or a supported one.') }}
</h2>
<NcButton class="content-unsupported-browser__continue" type="primary" @click="forceBrowsing">
{{ t('core', 'Continue with this unsupported browser') }}
</NcButton>
</div>
<ul class="content-unsupported-browser__list">
<h3>{{ t('core', 'Supported versions') }}</h3>
<li v-for="browser in formattedBrowsersList" :key="browser">
{{ browser }}
</li>
</ul>
</template>
</NcEmptyContent>
</div>
</template>
<script>
import { generateUrl } from '@nextcloud/router'
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
import Web from 'vue-material-design-icons/Web.vue'
import { browserStorageKey } from '../utils/RedirectUnsupportedBrowsers.js'
import { supportedBrowsers } from '../services/BrowsersListService.js'
import browserStorage from '../services/BrowserStorageService.js'
import logger from '../logger.js'
logger.debug('Supported browsers', { supportedBrowsers })
export default {
name: 'UnsupportedBrowser',
components: {
Web,
NcButton,
NcEmptyContent,
},
data() {
return {
agents: {},
}
},
computed: {
isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
},
/**
* Filter out or include mobile/desktop browsers depending
* on the current user platform/device
*/
filteredSupportedBrowsers() {
return supportedBrowsers.filter(browser => {
if (!browser) {
return false
}
if (this.isMobile) {
return this.isMobileBrowser(browser)
}
return !this.isMobileBrowser(browser)
})
},
formattedBrowsersList() {
const list = {}
// supportedBrowsers is generated by webpack at compilation time
this.filteredSupportedBrowsers.forEach(browser => {
const [id, version] = browser.split(' ')
if (!list[id] || list[id] < parseFloat(version, 10)) {
list[id] = parseFloat(version, 10)
}
})
return Object.keys(list).map(id => {
if (!this.agents[id]?.browser) {
return null
}
const version = list[id]
const name = this.agents[id]?.browser
return this.t('core', '{name} version {version} and above', {
name, version,
})
}).filter(entry => entry !== null)
},
},
async beforeMount() {
// Dynamic load big list of user agents
// eslint-disable-next-line n/no-extraneous-import
const { agents } = await import('caniuse-lite')
this.agents = agents
},
methods: {
t,
n,
// Set the flag allowing this browser and redirect to home
forceBrowsing() {
browserStorage.setItem(browserStorageKey, true)
// Redirect if there is the data
const urlParams = new URLSearchParams(window.location.search)
if (urlParams.has('redirect_url')) {
const redirectPath = Buffer.from(urlParams.get('redirect_url'), 'base64').toString() || '/'
if (redirectPath.startsWith('/')) {
window.location = generateUrl(redirectPath)
return
}
}
window.location = generateUrl('/')
},
/**
* Detect if the browserslist browser is a mobile one
* https://github.com/browserslist/browserslist#query-composition
*
* @param {string} browser a valid browserlist browser. e.g `and_chr 90`
*/
isMobileBrowser(browser) {
browser = browser.toLowerCase()
return browser.includes('and_')
|| browser.includes('android')
|| browser.includes('ios_')
|| browser.includes('mobile')
|| browser.includes('_mob')
|| browser.includes('samsung')
},
},
}
</script>
<style lang="scss" scoped>
$spacing: 30px;
.content-unsupported-browser {
display: flex;
justify-content: center;
width: 400px;
max-width: calc(90vw - 2 * $spacing);
margin: auto;
padding: $spacing;
.empty-content {
margin: 0;
&::v-deep .empty-content__icon {
opacity: 1;
}
}
&__continue {
display: block;
margin: $spacing auto;
}
&__list {
margin-top: 2 * $spacing;
margin-bottom: $spacing;
li {
text-align: left;
}
}
}
</style>