mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
initial update progress commit
This commit is contained in:
committed by
Aiden McClelland
parent
0f1e2f0c5b
commit
baad108081
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user