/shared/js/cyph/components/not-found/not-found.component.ts

https://github.com/cyph/cyph · TypeScript · 103 lines · 75 code · 14 blank · 14 comment · 11 complexity · ad6a208c9510c2d23110b97280093135 MD5 · raw file

  1. import {
  2. ChangeDetectionStrategy,
  3. Component,
  4. Inject,
  5. OnInit,
  6. Optional
  7. } from '@angular/core';
  8. import {ActivatedRoute, Router} from '@angular/router';
  9. import {map} from 'rxjs/operators';
  10. import {BaseProvider} from '../../base-provider';
  11. import {AccountService} from '../../services/account.service';
  12. import {AccountDatabaseService} from '../../services/crypto/account-database.service';
  13. import {EnvService} from '../../services/env.service';
  14. import {SessionService} from '../../services/session.service';
  15. import {StringsService} from '../../services/strings.service';
  16. /**
  17. * Angular component for the cyph not found screen.
  18. */
  19. @Component({
  20. changeDetection: ChangeDetectionStrategy.OnPush,
  21. selector: 'cyph-not-found',
  22. styleUrls: ['./not-found.component.scss'],
  23. templateUrl: './not-found.component.html'
  24. })
  25. export class NotFoundComponent extends BaseProvider implements OnInit {
  26. /** Indicates whether to display the user profile variant of 404 content. */
  27. public readonly accountProfile = this.activatedRoute.data.pipe(
  28. map(o => o.accountProfile === true)
  29. );
  30. /** @inheritDoc */
  31. public ngOnInit () : void {
  32. super.ngOnInit();
  33. if (
  34. !this.envService.isAccounts ||
  35. !this.accountService ||
  36. !this.accountDatabaseService
  37. ) {
  38. return;
  39. }
  40. /* Workaround for edge case where app starts up preloading an unexpected route */
  41. if (
  42. this.envService.isCordova &&
  43. !this.accountDatabaseService.currentUser.value
  44. ) {
  45. this.router.navigate(['']);
  46. return;
  47. }
  48. /* Workaround for bizarre Electron/Chromium behavior on Windows */
  49. const windowsURLPrefix = 'C:/%23';
  50. if (this.router.url.startsWith(windowsURLPrefix)) {
  51. this.router.navigateByUrl(
  52. this.router.url.slice(windowsURLPrefix.length)
  53. );
  54. return;
  55. }
  56. if (this.router.url.split('/').slice(-1)[0] !== '404') {
  57. this.router.navigate(['404']);
  58. return;
  59. }
  60. this.accountService.transitionEnd();
  61. this.accountService.resolveUiReady();
  62. }
  63. constructor (
  64. /** @ignore */
  65. private readonly router: Router,
  66. /** @ignore */
  67. @Inject(AccountService)
  68. @Optional()
  69. private readonly accountService: AccountService | undefined,
  70. /** @ignore */
  71. @Inject(AccountDatabaseService)
  72. @Optional()
  73. private readonly accountDatabaseService:
  74. | AccountDatabaseService
  75. | undefined,
  76. /** @see ActivatedRoute */
  77. public readonly activatedRoute: ActivatedRoute,
  78. /** @see EnvService */
  79. public readonly envService: EnvService,
  80. /** @see SessionService */
  81. @Inject(SessionService)
  82. @Optional()
  83. public readonly sessionService: SessionService | undefined,
  84. /** @see StringsService */
  85. public readonly stringsService: StringsService
  86. ) {
  87. super();
  88. }
  89. }