@dotrino/install 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/install",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Botón de \"Instalar app\" (PWA) unificado del ecosistema Dotrino: Web Component <dotrino-install> que captura beforeinstallprompt temprano, maneja iOS con un modal de instrucciones (sin alert) y se oculta si ya está instalada. Vue o vanilla. Sin JS de terceros ni cookies, bilingüe es/en.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.d.ts CHANGED
@@ -19,6 +19,9 @@ export const INSTALL_PARAM: string
19
19
  /** ¿La URL trae el marcador `?pwa-install=1` (tras relanzar en Chrome)? */
20
20
  export function hasInstallFlag(param?: string): boolean
21
21
 
22
+ /** ¿La app fue abierta desde el hub instalado (el home le puso `?hub=1`)? */
23
+ export function isEmbeddedHub(): boolean
24
+
22
25
  /**
23
26
  * `intent://` que reabre la app en Chrome (no el Custom Tab/webview embebido)
24
27
  * con `?pwa-install=1`, con fallback a https. Solo útil en Android. null si falla.
package/src/index.js CHANGED
@@ -110,12 +110,22 @@ export function isAndroid () {
110
110
  }
111
111
 
112
112
  const INSTALL_PARAM = 'pwa-install'
113
+ const HUB_PARAM = 'hub'
113
114
 
114
115
  /** ¿La URL trae el marcador de "abrir para instalar" (tras relanzar en Chrome)? */
115
116
  export function hasInstallFlag (param = INSTALL_PARAM) {
116
117
  try { return new URLSearchParams(location.search).has(param) } catch (_) { return false }
117
118
  }
118
119
 
120
+ /**
121
+ * ¿La app fue abierta DESDE el hub instalado (el home le puso `?hub=1`)? En ese
122
+ * caso corre embebida en un Custom Tab que puede reportarse como standalone; este
123
+ * marcador es la señal fiable de "estoy embebido, ofrece instalar en Chrome".
124
+ */
125
+ export function isEmbeddedHub () {
126
+ try { return new URLSearchParams(location.search).has(HUB_PARAM) } catch (_) { return false }
127
+ }
128
+
119
129
  /**
120
130
  * Construye un `intent://` que reabre ESTA misma app en **Chrome** (no en el
121
131
  * Custom Tab/webview embebido) con el marcador `?pwa-install=1`, con fallback a
@@ -124,6 +134,7 @@ export function hasInstallFlag (param = INSTALL_PARAM) {
124
134
  export function chromeInstallUrl (param = INSTALL_PARAM) {
125
135
  try {
126
136
  const u = new URL(location.href)
137
+ u.searchParams.delete(HUB_PARAM) // el marcador del hub no debe viajar a Chrome
127
138
  u.searchParams.set(param, '1')
128
139
  const target = `${u.host}${u.pathname}${u.search}`
129
140
  const fallback = encodeURIComponent(u.toString())
@@ -141,8 +152,12 @@ export function chromeInstallUrl (param = INSTALL_PARAM) {
141
152
  * - 'none' nada que ofrecer (todavía esperando, o navegador sin soporte).
142
153
  */
143
154
  export function installContext () {
144
- if (isAppInstalled()) return 'installed'
155
+ // Prompt nativo (Chrome real) siempre gana.
145
156
  if (_deferred) return 'native'
157
+ // Embebido desde el hub (Android): ofrecer relanzar en Chrome AUNQUE el Custom
158
+ // Tab se reporte como standalone (por eso esto va ANTES de isAppInstalled()).
159
+ if (isEmbeddedHub() && isAndroid()) return 'relaunch'
160
+ if (isAppInstalled()) return 'installed'
146
161
  if (isIOS()) return 'ios'
147
162
  if (_settled && isAndroid()) return 'relaunch'
148
163
  return 'none'