From aeee8f74e5a06214fc89680ee7be3f2e9dd88499 Mon Sep 17 00:00:00 2001 From: ThaUnknown <6506529+ThaUnknown@users.noreply.github.com> Date: Sun, 16 Jun 2024 18:01:25 +0200 Subject: [PATCH] fix: android clicks --- capacitor/webpack.config.cjs | 3 ++- common/modules/click.js | 42 ++++++++++++++++++++---------------- common/modules/webtorrent.js | 2 +- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/capacitor/webpack.config.cjs b/capacitor/webpack.config.cjs index 1eb336b..a09f95e 100644 --- a/capacitor/webpack.config.cjs +++ b/capacitor/webpack.config.cjs @@ -29,8 +29,9 @@ const capacitorConfig = { alias: { ...alias, wrtc: false, + 'node-datachannel': false, 'bittorrent-tracker/lib/client/http-tracker.js': resolve('../node_modules/bittorrent-tracker/lib/client/http-tracker.js'), - 'webrtc-polyfill': resolve('../node_modules/webrtc-polyfill/browser.js') + 'webrtc-polyfill': false // no webrtc on mobile, need the resources } }, target: 'node', diff --git a/common/modules/click.js b/common/modules/click.js index f872523..e8d4f01 100644 --- a/common/modules/click.js +++ b/common/modules/click.js @@ -1,3 +1,5 @@ +import { SUPPORTS } from '@/modules/support.js' + let lastTapElement = null let lastHoverElement = null @@ -26,12 +28,14 @@ export function click (node, cb = noop) { node.addEventListener('pointerleave', e => { e.stopPropagation() }) - node.addEventListener('keydown', e => { - if (e.key === 'Enter') { - e.stopPropagation() - cb(e) - } - }) + if (!SUPPORTS.isAndroid) { + node.addEventListener('keydown', e => { + if (e.key === 'Enter') { + e.stopPropagation() + cb(e) + } + }) + } } export function hoverClick (node, [cb = noop, hoverUpdate = noop]) { @@ -57,19 +61,21 @@ export function hoverClick (node, [cb = noop, hoverUpdate = noop]) { lastTapElement = hoverUpdate } }) - node.addEventListener('keydown', e => { - if (e.key === 'Enter') { - e.stopPropagation() - lastTapElement?.(false) - if (lastTapElement === hoverUpdate) { - lastTapElement = null - cb(e) - } else { - hoverUpdate(true) - lastTapElement = hoverUpdate + if (!SUPPORTS.isAndroid) { + node.addEventListener('keydown', e => { + if (e.key === 'Enter') { + e.stopPropagation() + lastTapElement?.(false) + if (lastTapElement === hoverUpdate) { + lastTapElement = null + cb(e) + } else { + hoverUpdate(true) + lastTapElement = hoverUpdate + } } - } - }) + }) + } node.addEventListener('pointerup', e => { e.stopPropagation() if (e.pointerType === 'mouse') setTimeout(() => hoverUpdate(false)) diff --git a/common/modules/webtorrent.js b/common/modules/webtorrent.js index dbbd117..c6bdc89 100644 --- a/common/modules/webtorrent.js +++ b/common/modules/webtorrent.js @@ -28,7 +28,7 @@ const announce = [ let storedSettings = {} // HACK: this is https only, but electron doesnt run in https -if (!globalThis.FileSystemFileHandle) global.FileSystemFileHandle = false +if (!globalThis.FileSystemFileHandle) globalThis.FileSystemFileHandle = false try { storedSettings = JSON.parse(localStorage.getItem('settings')) || {}