initial update progress commit

This commit is contained in:
Drew Ansbacher
2021-09-15 12:04:55 -06:00
committed by Aiden McClelland
parent 0f1e2f0c5b
commit baad108081
6 changed files with 234 additions and 167 deletions

View File

@@ -7,11 +7,20 @@ import { PatchDbService } from '../services/patch-db/patch-db.service'
providedIn: 'root',
})
export class MaintenanceGuard implements CanActivate, CanActivateChild {
serverStatus: ServerStatus
isFullyDownloaded: boolean = false
constructor (
private readonly router: Router,
private readonly patch: PatchDbService,
) { }
) {
this.patch.watch$('server-info', 'status').subscribe(status => {
this.serverStatus = status
})
this.patch.watch$('server-info', 'update-progress').subscribe(progress => {
this.isFullyDownloaded = !!progress && (progress.size === progress.downloaded)
})
}
canActivate (): boolean {
return this.runServerStatusCheck()
@@ -22,7 +31,7 @@ export class MaintenanceGuard implements CanActivate, CanActivateChild {
}
private runServerStatusCheck (): boolean {
if ([ServerStatus.Updating, ServerStatus.BackingUp].includes(this.patch.getData()['server-info']?.status)) {
if (ServerStatus.BackingUp === this.serverStatus || !this.isFullyDownloaded) {
this.router.navigate(['/maintenance'], { replaceUrl: true })
return false
} else {

View File

@@ -8,6 +8,8 @@ import { PatchDbService } from '../services/patch-db/patch-db.service'
})
export class UnmaintenanceGuard implements CanActivate {
serverStatus: ServerStatus
isFullyDownloaded: boolean = false
constructor (
private readonly router: Router,
@@ -16,14 +18,17 @@ export class UnmaintenanceGuard implements CanActivate {
this.patch.watch$('server-info', 'status').subscribe(status => {
this.serverStatus = status
})
this.patch.watch$('server-info', 'update-progress').subscribe(progress => {
this.isFullyDownloaded = !!progress && (progress.size === progress.downloaded)
})
}
canActivate (): boolean {
if (![ServerStatus.Updating, ServerStatus.BackingUp].includes(this.serverStatus)) {
if (ServerStatus.BackingUp === this.serverStatus || this.isFullyDownloaded) {
return true
} else {
this.router.navigate([''], { replaceUrl: true })
return false
} else {
return true
}
}
}