preload icons and pause on setup complete for kiosk mode (#1997)

* preload two icons

* pause on setup complete for 4 seconds before redirecting kiosk mode
This commit is contained in:
Matt Hill
2022-11-29 18:59:17 -07:00
committed by GitHub
parent 74ddf7114c
commit e0678cc869
3 changed files with 16 additions and 57 deletions

View File

@@ -35,15 +35,11 @@
></ion-icon> ></ion-icon>
<h1>Setup Complete!</h1> <h1>Setup Complete!</h1>
</div> </div>
<h3 <h3 *ngIf="setupType === 'restore'">
*ngIf="recoverySource && recoverySource.type === 'backup'"
>
You can now safely unplug your backup drive You can now safely unplug your backup drive
</h3> </h3>
<h3 <h3 *ngIf="setupType === 'transfer'">
*ngIf="recoverySource && recoverySource.type === 'migrate'" You can now safely unplug your old Embassy drive
>
You can now safely unplug your old drive
</h3> </h3>
</div> </div>
<div class="card-container"> <div class="card-container">
@@ -82,8 +78,7 @@
</div> </div>
</ion-col> </ion-col>
</ion-row> </ion-row>
<!-- cert elem -->
<a hidden id="install-cert" download="embassy.crt"></a>
<!-- download elem --> <!-- download elem -->
<div hidden id="downloadable"> <div hidden id="downloadable">
<div <div

View File

@@ -8,11 +8,10 @@ import {
Output, Output,
ViewChild, ViewChild,
} from '@angular/core' } from '@angular/core'
import { IonContent, ToastController } from '@ionic/angular'
import { import {
copyToClipboard,
DownloadHTMLService, DownloadHTMLService,
ErrorToastService, ErrorToastService,
pauseFor,
} from '@start9labs/shared' } from '@start9labs/shared'
import { ApiService } from 'src/app/services/api/api.service' import { ApiService } from 'src/app/services/api/api.service'
import { StateService } from 'src/app/services/state.service' import { StateService } from 'src/app/services/state.service'
@@ -24,8 +23,6 @@ import { StateService } from 'src/app/services/state.service'
providers: [DownloadHTMLService], providers: [DownloadHTMLService],
}) })
export class SuccessPage { export class SuccessPage {
@ViewChild(IonContent)
private content?: IonContent
@ViewChild('canvas', { static: true }) @ViewChild('canvas', { static: true })
private canvas: ElementRef<HTMLCanvasElement> = {} as ElementRef<HTMLCanvasElement> private canvas: ElementRef<HTMLCanvasElement> = {} as ElementRef<HTMLCanvasElement>
private ctx: CanvasRenderingContext2D = {} as CanvasRenderingContext2D private ctx: CanvasRenderingContext2D = {} as CanvasRenderingContext2D
@@ -35,7 +32,6 @@ export class SuccessPage {
torAddress = '' torAddress = ''
lanAddress = '' lanAddress = ''
cert = '' cert = ''
isOnBottom = true
tileSize = 16 tileSize = 16
// a higher fade factor will make the characters fade quicker // a higher fade factor will make the characters fade quicker
@@ -46,16 +42,15 @@ export class SuccessPage {
constructor( constructor(
@Inject(DOCUMENT) private readonly document: Document, @Inject(DOCUMENT) private readonly document: Document,
private readonly toastCtrl: ToastController,
private readonly errCtrl: ErrorToastService, private readonly errCtrl: ErrorToastService,
private readonly stateService: StateService, private readonly stateService: StateService,
private api: ApiService, private readonly api: ApiService,
private readonly downloadHtml: DownloadHTMLService, private readonly downloadHtml: DownloadHTMLService,
private ngZone: NgZone, private readonly ngZone: NgZone,
) {} ) {}
get recoverySource() { get setupType() {
return this.stateService.recoverySource return this.stateService.setupType
} }
get isKiosk() { get isKiosk() {
@@ -66,20 +61,12 @@ export class SuccessPage {
this.ngZone.runOutsideAngular(() => this.initMatrix()) this.ngZone.runOutsideAngular(() => this.initMatrix())
try { try {
const ret = await this.api.complete() const ret = await this.api.complete()
if (!this.isKiosk) { if (this.isKiosk) {
setTimeout(() => this.checkBottom(), 42) await pauseFor(4000)
} else {
this.torAddress = ret['tor-address'] this.torAddress = ret['tor-address']
this.lanAddress = ret['lan-address'] this.lanAddress = ret['lan-address']
this.cert = ret['root-ca'] this.cert = ret['root-ca']
this.document
.getElementById('install-cert')
?.setAttribute(
'href',
'data:application/x-x509-ca-cert;base64,' +
encodeURIComponent(this.cert),
)
} }
await this.api.exit() await this.api.exit()
} catch (e: any) { } catch (e: any) {
@@ -87,24 +74,6 @@ export class SuccessPage {
} }
} }
async copy(address: string): Promise<void> {
const success = await copyToClipboard(address)
const message = success
? 'Copied to clipboard!'
: 'Failed to copy to clipboard.'
const toast = await this.toastCtrl.create({
header: message,
position: 'bottom',
duration: 1000,
})
await toast.present()
}
installCert() {
this.document.getElementById('install-cert')?.click()
}
download() { download() {
const torAddress = this.document.getElementById('tor-addr') const torAddress = this.document.getElementById('tor-addr')
const lanAddress = this.document.getElementById('lan-addr') const lanAddress = this.document.getElementById('lan-addr')
@@ -125,14 +94,7 @@ export class SuccessPage {
}) })
} }
checkBottom() { private initMatrix() {
const bottomDiv = document.getElementById('bottom-div')
this.isOnBottom =
!!bottomDiv &&
bottomDiv.getBoundingClientRect().top - 192 < window.innerHeight
}
initMatrix() {
this.ctx = this.canvas.nativeElement.getContext('2d')! this.ctx = this.canvas.nativeElement.getContext('2d')!
this.canvas.nativeElement.width = window.innerWidth this.canvas.nativeElement.width = window.innerWidth
this.canvas.nativeElement.height = window.innerHeight this.canvas.nativeElement.height = window.innerHeight
@@ -140,7 +102,7 @@ export class SuccessPage {
this.tick() this.tick()
} }
setupMatrixGrid() { private setupMatrixGrid() {
this.maxStackHeight = Math.ceil(this.ctx.canvas.height / this.tileSize) this.maxStackHeight = Math.ceil(this.ctx.canvas.height / this.tileSize)
// divide the canvas into columns // divide the canvas into columns
for (let i = 0; i < this.ctx.canvas.width / this.tileSize; ++i) { for (let i = 0; i < this.ctx.canvas.width / this.tileSize; ++i) {

View File

@@ -39,6 +39,7 @@ const ICONS = [
'finger-print-outline', 'finger-print-outline',
'flash-outline', 'flash-outline',
'folder-open-outline', 'folder-open-outline',
'globe-outline',
'grid-outline', 'grid-outline',
'help-circle-outline', 'help-circle-outline',
'hammer-outline', 'hammer-outline',
@@ -70,6 +71,7 @@ const ICONS = [
'remove', 'remove',
'remove-circle-outline', 'remove-circle-outline',
'remove-outline', 'remove-outline',
'repeat-outline',
'rocket-outline', 'rocket-outline',
'save-outline', 'save-outline',
'settings-outline', 'settings-outline',