FIX: correctly checks user activation on use (#23793)

We can't have it computed only at start of the application as the state wouldn't most likely be false at this point in time.
This commit is contained in:
Joffrey JAFFEUX 2023-10-05 11:24:01 +02:00 committed by GitHub
parent ea9ad4dc0f
commit 9e5fc2e817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 11 deletions

View File

@ -2,7 +2,14 @@ const APPLE_NAVIGATOR_PLATFORMS = /iPhone|iPod|iPad|Macintosh|MacIntel/;
const APPLE_USER_AGENT_DATA_PLATFORM = /macOS/;
function calculateCapabilities() {
const capabilities = {};
const capabilities = {
get userHasBeenActive() {
return (
!("userActivation" in navigator) ||
navigator.userActivation.hasBeenActive
);
},
};
const ua = navigator.userAgent;
@ -31,10 +38,7 @@ function calculateCapabilities() {
capabilities.hasContactPicker =
"contacts" in navigator && "ContactsManager" in window;
capabilities.canVibrate =
"vibrate" in navigator &&
(!("userActivation" in navigator) ||
navigator.userActivation.hasBeenActive);
capabilities.canVibrate = "vibrate" in navigator;
capabilities.isPwa =
window.matchMedia("(display-mode: standalone)").matches ||

View File

@ -10,7 +10,6 @@ import {
NO_REMINDER_ICON,
WITH_REMINDER_ICON,
} from "discourse/models/bookmark";
import { isTesting } from "discourse-common/config/environment";
import DeleteTopicDisallowedModal from "discourse/components/modal/delete-topic-disallowed";
import RenderGlimmer from "discourse/widgets/render-glimmer";
import { hbs } from "ember-cli-htmlbars";
@ -820,7 +819,7 @@ export default createWidget("post-menu", {
return this.sendWidgetAction("showLogin");
}
if (this.capabilities.canVibrate && !isTesting()) {
if (this.capabilities.userHasBeenActive && this.capabilities.canVibrate) {
navigator.vibrate(VIBRATE_DURATION);
}

View File

@ -4,7 +4,6 @@ import { getOwner } from "@ember/application";
import { tracked } from "@glimmer/tracking";
import discourseLater from "discourse-common/lib/later";
import { action } from "@ember/object";
import { isTesting } from "discourse-common/config/environment";
import { inject as service } from "@ember/service";
import and from "truth-helpers/helpers/and";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
@ -142,7 +141,7 @@ export default class ChatMessageActionsMobile extends Component {
fadeAndVibrate() {
discourseLater(this.#addFadeIn.bind(this));
if (this.capabilities.canVibrate && !isTesting()) {
if (this.capabilities.userHasBeenActive && this.capabilities.canVibrate) {
navigator.vibrate(5);
}
}

View File

@ -7,7 +7,6 @@ import { BookmarkFormData } from "discourse/lib/bookmark";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { isTesting } from "discourse-common/config/environment";
import { clipboardCopy } from "discourse/lib/utilities";
import ChatMessageReaction, {
REACTIONS,
@ -284,7 +283,7 @@ export default class ChatMessageInteractor {
return;
}
if (this.capabilities.canVibrate && !isTesting()) {
if (this.capabilities.userHasBeenActive && this.capabilities.canVibrate) {
navigator.vibrate(5);
}