Skip to content

Commit 685b2d8

Browse files
committed
[ 1.0.29 ] * This release requires the SpotifyPlus Integration v1.0.85+ release; please make sure you update the SpotifyPlus integration prior to updating this SpotifyPlus Card release.
* Modified `isTouchDevice` method to better detect touchscreen support for dual-monitor setups.
1 parent f2bbaea commit 685b2d8

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Change are listed in reverse chronological order (newest to oldest).
66

77
<span class="changelog">
88

9+
###### [ 1.0.29 ] - 2025/01/11
10+
11+
* This release requires the SpotifyPlus Integration v1.0.85+ release; please make sure you update the SpotifyPlus integration prior to updating this SpotifyPlus Card release.
12+
* Modified `isTouchDevice` method to better detect touchscreen support for dual-monitor setups.
13+
914
###### [ 1.0.28 ] - 2025/01/09
1015

1116
* This release requires the SpotifyPlus Integration v1.0.85+ release; please make sure you update the SpotifyPlus integration prior to updating this SpotifyPlus Card release.

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { css } from 'lit';
22

33
/** current version of the card. */
4-
export const CARD_VERSION = '1.0.28';
4+
export const CARD_VERSION = '1.0.29';
55

66
/** SpotifyPlus integration domain identifier. */
77
export const DOMAIN_SPOTIFYPLUS = 'spotifyplus';

src/utils/utils.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,27 @@ export function closestElement(selector: string, base: Element) {
455455
* Determine if the current device supports touch events.
456456
*
457457
* @returns true if touch events are supported; otherwise, false.
458-
*
459-
* examples:
460-
* - find element by it's `id=` value:
461-
* const container = this.closestElement('#spcPlayer');
462-
* - find element by it's html tag name (e.g. `<spc-player>`):
463-
* const container = this.closestElement('spc-player');
464458
*/
465459
export function isTouchDevice(): boolean {
466-
return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
460+
//return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
461+
462+
let result = false;
463+
if (window.PointerEvent && ('maxTouchPoints' in navigator)) {
464+
// if Pointer Events are supported, just check maxTouchPoints
465+
if (navigator.maxTouchPoints > 0) {
466+
result = true;
467+
}
468+
} else {
469+
// no Pointer Events...
470+
if (window.matchMedia && window.matchMedia("(any-pointer:coarse)").matches) {
471+
// check for any-pointer:coarse which mostly means touchscreen
472+
result = true;
473+
} else if (window.TouchEvent || ('ontouchstart' in window)) {
474+
// last resort - check for exposed touch events API / event handler
475+
result = true;
476+
}
477+
}
478+
return result;
467479
}
468480

469481

0 commit comments

Comments
 (0)