<commit_before>import { useEffect, useState } from 'react'
import { usePlatform } from 'rt-platforms'
import { isMobileDevice } from 'apps/utils'

export const usePWABannerPrompt = (): [
  BeforeInstallPromptEvent | null,
  () => Promise<void> | undefined
] => {
  const [prompt, setPrompt] = useState<BeforeInstallPromptEvent | null>(null)
  const platform = usePlatform()

  const promptToInstall = () => {
    if (prompt) {
      return prompt.prompt()
    }
    return Promise.reject(new Error("Browser hasn't sent a 'beforeinstallprompt' event"))
  }

  useEffect(() => {
    const ready = (e: BeforeInstallPromptEvent) => {
      e.preventDefault()
      if (isMobileDevice || platform.type !== 'browser') {
        setPrompt(null)
      } else {
        setPrompt(e)
      }
    }

    if (typeof window.beforeInstallPromptEvent === 'undefined') {
      window.addEventListener('beforeinstallprompt', ready)
    } else {
      ready(window.beforeInstallPromptEvent)<commit_msg>fix(workspace): native android pwa (ARTP-1211)<commit_after>import { useEffect, useState } from 'react'
import { usePlatform } from 'rt-platforms'
import { isMobileDevice } from 'apps/utils'

export const usePWABannerPrompt = (): [
  BeforeInstallPromptEvent | null,
  () => Promise<void> | undefined
] => {
  const [prompt, setPrompt] = useState<BeforeInstallPromptEvent | null>(null)
  const platform = usePlatform()

  const promptToInstall = () => {
    if (prompt) {
      return prompt.prompt()
    }
    return Promise.reject(new Error("Browser hasn't sent a 'beforeinstallprompt' event"))
  }

  useEffect(() => {
    const ready = (e: BeforeInstallPromptEvent) => {
      if (isMobileDevice || platform.type !== 'browser') {
        setPrompt(null)
      } else {
        setPrompt(e)
      }
    }

    if (typeof window.beforeInstallPromptEvent === 'undefined') {
      window.addEventListener('beforeinstallprompt', ready)
    } else {
      ready(window.beforeInstallPromptEvent)
{'fraction_non_alphanumeric': 0.13006072874493926, 'fraction_numerical': 0.0020242914979757085, 'mean_word_length': 3.576388888888889, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5400695', 'n_tokens_mistral': 600, 'n_tokens_neox': 580, 'n_words': 128}