Skip to content

Commit 30dac1f

Browse files
authored
Merge pull request #1975 from christianmemije/download
Disable download button for Android WebView
2 parents e1b72fc + d454cb7 commit 30dac1f

File tree

1 file changed

+34
-1
lines changed
  • kolibri/plugins/learn/assets/src/views/content-page

1 file changed

+34
-1
lines changed

kolibri/plugins/learn/assets/src/views/content-page/index.vue

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,42 @@
142142
},
143143
data: () => ({ wasIncomplete: false }),
144144
computed: {
145+
/**
146+
* Detects whether an Android device is using WebView.
147+
* Based on https://developer.chrome.com/multidevice/user-agent#webview_user_agent
148+
*/
149+
isAndroidWebView() {
150+
const ua = window.navigator.userAgent;
151+
const isAndroid = /Android/.test(ua);
152+
153+
if (isAndroid) {
154+
const androidVersion = parseFloat(ua.match(/Android\s([0-9\.]*)/)[1]);
155+
const isChrome = /Chrome/.test(ua);
156+
157+
// WebView UA in Lollipop and Above
158+
// Android >=5.0
159+
if (androidVersion >= 5.0 && isChrome && /wv/.test(ua)) {
160+
return true;
161+
}
162+
163+
// WebView UA in KitKat to Lollipop
164+
// Android >= 4.4
165+
if (androidVersion >= 4.4 && androidVersion < 5.0 && isChrome && /Version\//.test(ua)) {
166+
return true;
167+
}
168+
169+
// Old WebView UA
170+
// Android < 4.4
171+
if (androidVersion < 4.4 && /Version\//.test(ua) && /\/534.30/.test(ua)) {
172+
return true;
173+
}
174+
}
175+
176+
return false;
177+
},
145178
canDownload() {
146179
if (this.content) {
147-
return this.content.kind !== ContentNodeKinds.EXERCISE;
180+
return this.content.kind !== ContentNodeKinds.EXERCISE && !this.isAndroidWebView;
148181
}
149182
return false;
150183
},

0 commit comments

Comments
 (0)