7 changed files with 263 additions and 10 deletions
@ -0,0 +1,41 @@ |
|||
<!-- |
|||
|
|||
SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. |
|||
SPDX-License-Identifier: BUSL-1.1 |
|||
|
|||
--> |
|||
<tb-home-card [card]="card" [hideable]="true"> |
|||
@if (settings()) { |
|||
<div class="tb-app-widget" [class.badges-left]="badgesLeft()"> |
|||
<div class="tb-app-widget-row"> |
|||
<div class="tb-app-qr" role="img" [attr.aria-label]="'home.mobile-app.qr' | translate" |
|||
[innerHTML]="qrCode() | safe: 'html'" (click)="openDeepLink()"></div> |
|||
@if (badges()) { |
|||
<div class="tb-store-badges"> |
|||
@if (settings().iosEnabled) { |
|||
<a class="tb-store-badge apple" [href]="settings().appStoreLink" target="_blank" rel="noopener noreferrer" |
|||
[attr.aria-label]="'widgets.mobile-app-qr-code.download-on-the-app-store' | translate"> |
|||
<span class="tb-store-mark"> |
|||
<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.546 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.676-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701"/></svg> |
|||
</span> |
|||
<span class="tb-store-text"><small>{{ 'home.mobile-app.download-on-the' | translate }}</small><b>App Store</b></span> |
|||
</a> |
|||
} |
|||
@if (settings().androidEnabled) { |
|||
<a class="tb-store-badge play" [href]="settings().googlePlayLink" target="_blank" rel="noopener noreferrer" |
|||
[attr.aria-label]="'widgets.mobile-app-qr-code.get-it-on-google-play' | translate"> |
|||
<span class="tb-store-mark"> |
|||
<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="#ffd500" d="M22.018 13.298l-3.919 2.218-3.515-3.493 3.543-3.521 3.891 2.202a1.49 1.49 0 0 1 0 2.594z"/><path fill="#00c3ff" d="M1.337.924a1.486 1.486 0 0 0-.112.568v21.017c0 .217.045.419.124.6l11.155-11.087L1.337.924z"/><path fill="#00f076" d="M13.544 10.989l3.258-3.238L3.45.195a1.466 1.466 0 0 0-.946-.179l11.04 10.973z"/><path fill="#ff3a44" d="M13.544 13.056l-11 10.933c.298.036.612-.016.906-.183l13.324-7.54-3.23-3.21z"/></svg> |
|||
</span> |
|||
<span class="tb-store-text"><small>{{ 'home.mobile-app.get-it-on' | translate }}</small><b>Google Play</b></span> |
|||
</a> |
|||
} |
|||
</div> |
|||
} |
|||
</div> |
|||
@if (label()) { |
|||
<div class="tb-app-widget-label">{{ label() }}</div> |
|||
} |
|||
</div> |
|||
} |
|||
</tb-home-card> |
|||
@ -0,0 +1,138 @@ |
|||
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. |
|||
// SPDX-License-Identifier: BUSL-1.1 |
|||
:host { |
|||
display: block; |
|||
min-width: 0; |
|||
container: tb-mobile-app-home / inline-size; |
|||
} |
|||
|
|||
.tb-app-widget { |
|||
display: flex; |
|||
flex-direction: column; |
|||
align-items: center; |
|||
gap: 10px; |
|||
} |
|||
|
|||
.tb-app-widget-row { |
|||
display: flex; |
|||
align-items: center; |
|||
justify-content: center; |
|||
gap: 12px; |
|||
} |
|||
|
|||
.badges-left .tb-app-widget-row { |
|||
flex-direction: row-reverse; |
|||
} |
|||
|
|||
.tb-app-qr { |
|||
flex: none; |
|||
box-sizing: border-box; |
|||
width: 96px; |
|||
height: 96px; |
|||
padding: 4px; |
|||
border-radius: 6px; |
|||
background: #fff; |
|||
|
|||
::ng-deep svg { |
|||
display: block; |
|||
width: 100%; |
|||
height: 100%; |
|||
} |
|||
} |
|||
|
|||
.tb-store-badges { |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 8px; |
|||
} |
|||
|
|||
.tb-store-badge { |
|||
display: inline-flex; |
|||
flex: none; |
|||
align-items: center; |
|||
gap: 8px; |
|||
box-sizing: border-box; |
|||
width: 136px; |
|||
height: 40px; |
|||
padding: 0 12px 0 10px; |
|||
border: 1px solid #a6a6a6; |
|||
border-radius: 7px; |
|||
background: #000; |
|||
color: #fff; |
|||
text-decoration: none; |
|||
white-space: nowrap; |
|||
transition: background-color .2s ease, border-color .2s ease; |
|||
|
|||
&:hover { |
|||
border-color: #c8c8c8; |
|||
background: #1f1f1f; |
|||
color: #fff; |
|||
} |
|||
|
|||
&:focus-visible { |
|||
outline: 2px solid var(--tb-primary-500); |
|||
outline-offset: 2px; |
|||
} |
|||
} |
|||
|
|||
.tb-store-mark { |
|||
display: flex; |
|||
flex: none; |
|||
align-items: center; |
|||
justify-content: center; |
|||
width: 24px; |
|||
height: 24px; |
|||
|
|||
svg { |
|||
display: block; |
|||
width: 22px; |
|||
height: 22px; |
|||
} |
|||
} |
|||
|
|||
.apple .tb-store-mark svg { |
|||
width: 24px; |
|||
height: 24px; |
|||
margin-top: -2px; |
|||
} |
|||
|
|||
.tb-store-text { |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 1px; |
|||
font-family: var(--tb-font, Roboto, sans-serif); |
|||
text-align: left; |
|||
|
|||
small { |
|||
font-size: 10px; |
|||
line-height: 11px; |
|||
letter-spacing: 0.1px; |
|||
opacity: 0.92; |
|||
} |
|||
|
|||
b { |
|||
font-size: 16px; |
|||
font-weight: 500; |
|||
line-height: 18px; |
|||
letter-spacing: -0.1px; |
|||
} |
|||
} |
|||
|
|||
.play .tb-store-text small { |
|||
font-size: 9px; |
|||
letter-spacing: 0.5px; |
|||
text-transform: uppercase; |
|||
} |
|||
|
|||
.tb-app-widget-label { |
|||
font: 400 14px/20px var(--tb-font, Roboto, sans-serif); |
|||
letter-spacing: 0.2px; |
|||
text-align: center; |
|||
color: var(--tb-ink-60, rgba(0, 0, 0, 0.6)); |
|||
} |
|||
|
|||
@container tb-mobile-app-home (max-width: 290px) { |
|||
.tb-store-badges { |
|||
display: none; |
|||
} |
|||
} |
|||
@ -1,16 +1,79 @@ |
|||
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
|
|||
// SPDX-License-Identifier: BUSL-1.1
|
|||
import { ChangeDetectionStrategy, Component } from '@angular/core'; |
|||
import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, signal } from '@angular/core'; |
|||
import { MobileApplicationService } from '@core/http/mobile-application.service'; |
|||
import { UtilsService } from '@core/services/utils.service'; |
|||
import { unwrapModule } from '@core/utils'; |
|||
import { BadgePosition, QrCodeSettings } from '@shared/models/mobile-app.models'; |
|||
import { MINUTE } from '@shared/models/time/time.models'; |
|||
import { HomeCardId } from '@shared/models/user-settings.models'; |
|||
import { HOME_CARDS } from '@home/pages/home-page/home-cards.models'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-mobile-app-home', |
|||
template: `<tb-home-card [card]="card"></tb-home-card>`, |
|||
templateUrl: './mobile-app-home.component.html', |
|||
styleUrls: ['./mobile-app-home.component.scss'], |
|||
standalone: false, |
|||
changeDetection: ChangeDetectionStrategy.OnPush |
|||
}) |
|||
export class MobileAppHomeComponent { |
|||
|
|||
readonly card = HOME_CARDS[HomeCardId.MOBILE_APP]; |
|||
|
|||
private mobileAppService = inject(MobileApplicationService); |
|||
private utils = inject(UtilsService); |
|||
|
|||
readonly settings = signal<QrCodeSettings | null>(null); |
|||
|
|||
readonly qrCode = signal(''); |
|||
|
|||
readonly badges = computed(() => { |
|||
const settings = this.settings(); |
|||
return !!settings?.qrCodeConfig?.badgeEnabled && (settings.iosEnabled || settings.androidEnabled); |
|||
}); |
|||
|
|||
readonly badgesLeft = computed(() => this.settings()?.qrCodeConfig?.badgePosition === BadgePosition.LEFT); |
|||
|
|||
readonly label = computed(() => { |
|||
const config = this.settings()?.qrCodeConfig; |
|||
return config?.qrCodeLabelEnabled ? config.qrCodeLabel : ''; |
|||
}); |
|||
|
|||
private deepLink = ''; |
|||
private deepLinkTimer: ReturnType<typeof setTimeout> | null = null; |
|||
private destroyed = false; |
|||
|
|||
constructor() { |
|||
this.mobileAppService.getMergedMobileAppSettings().subscribe(settings => this.settings.set(settings)); |
|||
this.loadDeepLink(); |
|||
inject(DestroyRef).onDestroy(() => { |
|||
this.destroyed = true; |
|||
clearTimeout(this.deepLinkTimer); |
|||
}); |
|||
} |
|||
|
|||
openDeepLink(): void { |
|||
if (this.deepLink && window.matchMedia('(pointer: coarse)').matches) { |
|||
window.open(this.deepLink, '_blank'); |
|||
} |
|||
} |
|||
|
|||
private loadDeepLink(): void { |
|||
clearTimeout(this.deepLinkTimer); |
|||
this.mobileAppService.getMobileAppDeepLink().subscribe(link => { |
|||
if (this.destroyed) { |
|||
return; |
|||
} |
|||
this.deepLink = link; |
|||
import('qrcode').then(QRCode => unwrapModule(QRCode).toString(link, {type: 'svg', margin: 0}, (_error: Error, svg: string) => { |
|||
if (!this.destroyed) { |
|||
this.qrCode.set(svg); |
|||
} |
|||
})); |
|||
const ttl = Number(this.utils.getQueryParam('ttl', link)) * MINUTE; |
|||
if (ttl > 0) { |
|||
this.deepLinkTimer = setTimeout(() => this.loadDeepLink(), ttl); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue