From 69a7adca2c86917f02e941a9c7477d2f09115377 Mon Sep 17 00:00:00 2001 From: PoJu Chen Date: Tue, 19 Mar 2024 11:05:59 -0500 Subject: [PATCH 1/5] detect mouse click accross the whole app --- kolibri/core/assets/src/kolibri_app.js | 10 ++++++++++ .../assets/src/views/PerseusRendererIndex.vue | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/kolibri/core/assets/src/kolibri_app.js b/kolibri/core/assets/src/kolibri_app.js index 44f60b9bd9f..352f0e3e03c 100644 --- a/kolibri/core/assets/src/kolibri_app.js +++ b/kolibri/core/assets/src/kolibri_app.js @@ -58,6 +58,12 @@ export default class KolibriApp extends KolibriModule { return {}; } + handlePointerDown(event) { + if (event.pointerType === 'mouse' && localStorage.getItem('mouseUsed') !== 'true') { + localStorage.setItem('mouseUsed', 'true'); + } + } + setupVue() { // VueRouter instance needs to be defined to use vuex-router-sync if (!router._vueRouter) { @@ -110,6 +116,10 @@ export default class KolibriApp extends KolibriModule { ...this.stateSetters.map(setter => setter(this.store)), ]).then(() => { this.startRootVue(); + window.addEventListener('pointerdown', this.handlePointerDown.bind(this)); + this.rootvue.$on('hook:beforeDestroy', () => { + window.removeEventListener('pointerdown', this.handlePointerDown.bind(this)); + }); }); }); } diff --git a/kolibri/plugins/perseus_viewer/assets/src/views/PerseusRendererIndex.vue b/kolibri/plugins/perseus_viewer/assets/src/views/PerseusRendererIndex.vue index a50fa8821ee..e08422ea775 100644 --- a/kolibri/plugins/perseus_viewer/assets/src/views/PerseusRendererIndex.vue +++ b/kolibri/plugins/perseus_viewer/assets/src/views/PerseusRendererIndex.vue @@ -144,7 +144,7 @@ return this.windowBreakpoint < 3; }, usesTouch() { - return isTouchDevice; + return isTouchDevice && localStorage.getItem('mouseUsed') !== 'true'; }, itemRenderData() { return { From 95d24a624a1b2fbf1b8a7e4d9815db24e27ee698 Mon Sep 17 00:00:00 2001 From: PoJuDeSu Date: Thu, 21 Mar 2024 11:23:26 -0500 Subject: [PATCH 2/5] Hide implementation of isMouseUsed Signed-off-by: PoJuDeSu --- kolibri/core/assets/src/kolibri_app.js | 9 --------- kolibri/core/assets/src/utils/browserInfo.js | 13 +++++++++++++ .../assets/src/views/PerseusRendererIndex.vue | 4 ++-- yarn.lock | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/kolibri/core/assets/src/kolibri_app.js b/kolibri/core/assets/src/kolibri_app.js index 352f0e3e03c..9b72dd94397 100644 --- a/kolibri/core/assets/src/kolibri_app.js +++ b/kolibri/core/assets/src/kolibri_app.js @@ -58,11 +58,6 @@ export default class KolibriApp extends KolibriModule { return {}; } - handlePointerDown(event) { - if (event.pointerType === 'mouse' && localStorage.getItem('mouseUsed') !== 'true') { - localStorage.setItem('mouseUsed', 'true'); - } - } setupVue() { // VueRouter instance needs to be defined to use vuex-router-sync @@ -116,10 +111,6 @@ export default class KolibriApp extends KolibriModule { ...this.stateSetters.map(setter => setter(this.store)), ]).then(() => { this.startRootVue(); - window.addEventListener('pointerdown', this.handlePointerDown.bind(this)); - this.rootvue.$on('hook:beforeDestroy', () => { - window.removeEventListener('pointerdown', this.handlePointerDown.bind(this)); - }); }); }); } diff --git a/kolibri/core/assets/src/utils/browserInfo.js b/kolibri/core/assets/src/utils/browserInfo.js index f78e728bc71..75ed3d98268 100644 --- a/kolibri/core/assets/src/utils/browserInfo.js +++ b/kolibri/core/assets/src/utils/browserInfo.js @@ -69,3 +69,16 @@ export const isTouchDevice = 'ontouchstart' in window || window.navigator?.maxTouchPoints > 0 || window.navigator?.msMaxTouchPoints > 0; + +function handlePointerDown(event) { + if (event.pointerType === 'mouse') { + localStorage.setItem('mouseUsed', 'true'); + window.removeEventListener('pointerdown', handlePointerDown); + } +} + +window.addEventListener('pointerdown', handlePointerDown); + +export function isMouseUsed() { + return localStorage.getItem('mouseUsed') === 'true'; +} \ No newline at end of file diff --git a/kolibri/plugins/perseus_viewer/assets/src/views/PerseusRendererIndex.vue b/kolibri/plugins/perseus_viewer/assets/src/views/PerseusRendererIndex.vue index e08422ea775..eae4f8e19dd 100644 --- a/kolibri/plugins/perseus_viewer/assets/src/views/PerseusRendererIndex.vue +++ b/kolibri/plugins/perseus_viewer/assets/src/views/PerseusRendererIndex.vue @@ -91,7 +91,7 @@ import client from 'kolibri.client'; import urls from 'kolibri.urls'; import responsiveWindowMixin from 'kolibri.coreVue.mixins.responsiveWindowMixin'; - import { isTouchDevice } from 'kolibri.utils.browserInfo'; + import { isTouchDevice, isMouseUsed } from 'kolibri.utils.browserInfo'; import scriptLoader from 'kolibri-common/utils/scriptLoader'; import perseus from '../../dist/perseus'; import icu from '../KAGlobals/icu'; @@ -144,7 +144,7 @@ return this.windowBreakpoint < 3; }, usesTouch() { - return isTouchDevice && localStorage.getItem('mouseUsed') !== 'true'; + return isTouchDevice && !isMouseUsed(); }, itemRenderData() { return { diff --git a/yarn.lock b/yarn.lock index 6e04f4c1691..cd59042c20e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11552,7 +11552,7 @@ vue2-teleport@^1.0.1: resolved "https://registry.yarnpkg.com/vue2-teleport/-/vue2-teleport-1.0.1.tgz#1b7f9f69c1223f522cf6cd81c39b8d6019e1cf66" integrity sha512-hbY/Q0x8qXGFxo6h4KU4YYesUcN+uUjliqqC0PoNSgpcbS2QRb3qXi+7XMTgLYs0a8i7o1H6Mu43UV4Vbgkhgw== -vue@2.6.14, vue@^2.6.14: +vue@2.6.14: version "2.6.14" resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.14.tgz#e51aa5250250d569a3fbad3a8a5a687d6036e235" integrity sha512-x2284lgYvjOMj3Za7kqzRcUSxBboHqtgRE2zlos1qWaOye5yUmHn42LB1250NJBLRwEcdrB0JRwyPTEPhfQjiQ== From 3f7c981149fe8a8581ca3ce275c89fac9e5295c9 Mon Sep 17 00:00:00 2001 From: PoJuDeSu Date: Thu, 21 Mar 2024 11:26:52 -0500 Subject: [PATCH 3/5] remove unnecessary lines Signed-off-by: PoJuDeSu --- kolibri/core/assets/src/kolibri_app.js | 1 - yarn.lock | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/kolibri/core/assets/src/kolibri_app.js b/kolibri/core/assets/src/kolibri_app.js index 9b72dd94397..44f60b9bd9f 100644 --- a/kolibri/core/assets/src/kolibri_app.js +++ b/kolibri/core/assets/src/kolibri_app.js @@ -58,7 +58,6 @@ export default class KolibriApp extends KolibriModule { return {}; } - setupVue() { // VueRouter instance needs to be defined to use vuex-router-sync if (!router._vueRouter) { diff --git a/yarn.lock b/yarn.lock index cd59042c20e..6e04f4c1691 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11552,7 +11552,7 @@ vue2-teleport@^1.0.1: resolved "https://registry.yarnpkg.com/vue2-teleport/-/vue2-teleport-1.0.1.tgz#1b7f9f69c1223f522cf6cd81c39b8d6019e1cf66" integrity sha512-hbY/Q0x8qXGFxo6h4KU4YYesUcN+uUjliqqC0PoNSgpcbS2QRb3qXi+7XMTgLYs0a8i7o1H6Mu43UV4Vbgkhgw== -vue@2.6.14: +vue@2.6.14, vue@^2.6.14: version "2.6.14" resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.14.tgz#e51aa5250250d569a3fbad3a8a5a687d6036e235" integrity sha512-x2284lgYvjOMj3Za7kqzRcUSxBboHqtgRE2zlos1qWaOye5yUmHn42LB1250NJBLRwEcdrB0JRwyPTEPhfQjiQ== From 158dc4084329a359d238cff54b61d94433e93676 Mon Sep 17 00:00:00 2001 From: PoJuDeSu Date: Thu, 21 Mar 2024 17:26:49 -0500 Subject: [PATCH 4/5] update isMouseUsed as a variable Signed-off-by: PoJuDeSu --- kolibri/core/assets/src/utils/browserInfo.js | 5 ++--- .../perseus_viewer/assets/src/views/PerseusRendererIndex.vue | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/kolibri/core/assets/src/utils/browserInfo.js b/kolibri/core/assets/src/utils/browserInfo.js index 75ed3d98268..3aecc519bfb 100644 --- a/kolibri/core/assets/src/utils/browserInfo.js +++ b/kolibri/core/assets/src/utils/browserInfo.js @@ -73,12 +73,11 @@ export const isTouchDevice = function handlePointerDown(event) { if (event.pointerType === 'mouse') { localStorage.setItem('mouseUsed', 'true'); + isMouseUsed = true; window.removeEventListener('pointerdown', handlePointerDown); } } window.addEventListener('pointerdown', handlePointerDown); -export function isMouseUsed() { - return localStorage.getItem('mouseUsed') === 'true'; -} \ No newline at end of file +export let isMouseUsed = localStorage.getItem('mouseUsed') === 'true'; \ No newline at end of file diff --git a/kolibri/plugins/perseus_viewer/assets/src/views/PerseusRendererIndex.vue b/kolibri/plugins/perseus_viewer/assets/src/views/PerseusRendererIndex.vue index eae4f8e19dd..b9756bbdec9 100644 --- a/kolibri/plugins/perseus_viewer/assets/src/views/PerseusRendererIndex.vue +++ b/kolibri/plugins/perseus_viewer/assets/src/views/PerseusRendererIndex.vue @@ -144,7 +144,7 @@ return this.windowBreakpoint < 3; }, usesTouch() { - return isTouchDevice && !isMouseUsed(); + return isTouchDevice && !isMouseUsed; }, itemRenderData() { return { From b8aae9f6079627f49a0e1d0b89b68777aa0db8d4 Mon Sep 17 00:00:00 2001 From: PoJuDeSu Date: Fri, 22 Mar 2024 10:23:36 -0500 Subject: [PATCH 5/5] add new line at end of file --- kolibri/core/assets/src/utils/browserInfo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kolibri/core/assets/src/utils/browserInfo.js b/kolibri/core/assets/src/utils/browserInfo.js index 3aecc519bfb..516024db0fe 100644 --- a/kolibri/core/assets/src/utils/browserInfo.js +++ b/kolibri/core/assets/src/utils/browserInfo.js @@ -80,4 +80,4 @@ function handlePointerDown(event) { window.addEventListener('pointerdown', handlePointerDown); -export let isMouseUsed = localStorage.getItem('mouseUsed') === 'true'; \ No newline at end of file +export let isMouseUsed = localStorage.getItem('mouseUsed') === 'true';