Skip to content

Commit

Permalink
Merge pull request #11715 from AllanOXDi/Bye-EmbeddedWebView
Browse files Browse the repository at this point in the history
Replaced isEmbeddedWebView with isAppContext
  • Loading branch information
rtibbles authored Jan 11, 2024
2 parents bab585a + 07193c2 commit 8ad89be
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 33 deletions.
2 changes: 2 additions & 0 deletions kolibri/core/assets/src/composables/useUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function useUser() {
const isAdmin = computed(() => store.getters.isAdmin);
const isSuperuser = computed(() => store.getters.isSuperuser);
const canManageContent = computed(() => store.getters.canManageContent);
const isAppContext = computed(() => store.getters.isAppContext);

return {
isLearnerOnlyImport,
Expand All @@ -18,5 +19,6 @@ export default function useUser() {
isAdmin,
isSuperuser,
canManageContent,
isAppContext,
};
}
24 changes: 0 additions & 24 deletions kolibri/core/assets/src/utils/browserInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,6 @@ export const os = {
patch: osVersion[2],
};

/**
* Detection of whether an Android device is using WebView based on
* https://developer.chrome.com/multidevice/user-agent#webview_user_agent
* First checks for 'wv' (Lolipop+), then for 'Version/x.x'
*/
const isAndroid = os.name === 'Android';
export const isAndroidWebView =
isAndroid &&
(browser.name === 'Chrome Webview' ||
(browser.name === 'Chrome' && /Version\/\d+\.\d+/.test(userAgent)));

/**
* Embedded WebViews on Mac have no app identifier, while all the major browsers do, so check
* for browser app strings and mark as embedded if none are found.
*/
const isMac = os.name === 'Mac OS';
export const isMacWebView =
isMac && !(/Safari/.test(userAgent) || /Chrome/.test(userAgent) || /Firefox/.test(userAgent));

/**
* All web views
*/
export const isEmbeddedWebView = isAndroidWebView || isMacWebView;

// Check for presence of the touch event in DOM or multi-touch capabilities
export const isTouchDevice =
'ontouchstart' in window ||
Expand Down
11 changes: 9 additions & 2 deletions kolibri/core/assets/src/views/ContentRenderer/DownloadButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@

<script>
import { isEmbeddedWebView } from 'kolibri.utils.browserInfo';
import useUser from 'kolibri.coreVue.composables.useUser';
import { getFilePresetString } from './filePresetStrings';
import { getRenderableFiles } from './utils';
export default {
name: 'DownloadButton',
setup() {
const { isAppContext } = useUser();
return {
isAppContext,
};
},
props: {
files: {
type: Array,
Expand All @@ -41,7 +48,7 @@
return getRenderableFiles(this.files).filter(file => file.preset !== 'exercise');
},
canDownload() {
return !isEmbeddedWebView && this.downloadableFiles.length;
return !this.isAppContext && this.downloadableFiles.length;
},
fileOptions() {
const options = this.files.map(file => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,22 @@

<script>
import { isEmbeddedWebView } from 'kolibri.utils.browserInfo';
import pickBy from 'lodash/pickBy';
import useUser from 'kolibri.coreVue.composables.useUser';
import commonCoach from '../common';
import { ClassesPageNames } from '../../../../../learn/assets/src/constants';
import { LastPages } from '../../constants/lastPagesConstants';
export default {
name: 'ReportsControls',
mixins: [commonCoach],
setup() {
const { isAppContext } = useUser();
return {
isAppContext,
};
},
props: {
disableExport: {
type: Boolean,
Expand All @@ -61,7 +68,7 @@
computed: {
exportDisabled() {
// Always disable in app mode until we add the ability to download files.
return isEmbeddedWebView || this.disableExport;
return this.isAppContext || this.disableExport;
},
isMainReport() {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import client from 'kolibri.client';
import urls from 'kolibri.urls';
import samePageCheckGenerator from 'kolibri.utils.samePageCheckGenerator';
import bytesForHumans from 'kolibri.utils.bytesForHumans';
import { isEmbeddedWebView } from 'kolibri.utils.browserInfo';
import { get } from '@vueuse/core';
import useUser from 'kolibri.coreVue.composables.useUser';

/* Function to fetch device info from the backend
* and resolve validated data
Expand All @@ -20,9 +21,10 @@ export function getDeviceInfo() {
data.device_name = nameResponse.data.name;

const { server } = infoResponse.headers;
const { isAppContext } = useUser();

if (server.includes('0.0.0.0')) {
if (isEmbeddedWebView) {
if (get(isAppContext)) {
data.server_type = 'Kolibri app server';
} else {
data.server_type = 'Kolibri internal server';
Expand Down
7 changes: 4 additions & 3 deletions kolibri/plugins/facility/assets/src/views/DataPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
<script>
import { mapState, mapGetters, mapActions } from 'vuex';
import { isEmbeddedWebView } from 'kolibri.utils.browserInfo';
import useUser from 'kolibri.coreVue.composables.useUser';
import urls from 'kolibri.urls';
import { FacilityResource } from 'kolibri.resources';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
Expand Down Expand Up @@ -221,7 +221,8 @@
mixins: [commonCoreStrings],
setup() {
const { windowIsMedium, windowIsSmall } = useKResponsiveWindow();
return { windowIsMedium, windowIsSmall };
const { isAppContext } = useUser();
return { windowIsMedium, windowIsSmall, isAppContext };
},
data() {
return {
Expand All @@ -247,7 +248,7 @@
// NOTE: We disable CSV file upload/download on embedded web views like the Mac
// and Android apps
canUploadDownloadFiles() {
return !isEmbeddedWebView;
return !this.isAppContext;
},
pollForTasks() {
return this.$route.name === PageNames.DATA_EXPORT_PAGE;
Expand Down

0 comments on commit 8ad89be

Please sign in to comment.