title.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * This file is part of Threema Web.
  3. *
  4. * Threema Web is free software: you can redistribute it and/or modify it
  5. * under the terms of the GNU Affero General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or (at
  7. * your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Affero General Public License
  15. * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. import {StateService} from './state';
  18. /**
  19. * The title service can update the window title.
  20. */
  21. export class TitleService {
  22. private $document: ng.IDocumentService;
  23. private stateService: StateService;
  24. private DEFAULT_TITLE = 'Threema Web';
  25. private title: string;
  26. private unreadCount: number = 0;
  27. public static $inject = ['$document', 'StateService'];
  28. constructor($document: ng.IDocumentService, stateService: StateService) {
  29. this.$document = $document;
  30. this.stateService = stateService;
  31. // Event handlers
  32. this.stateService.evtUnreadCountChange.attach(
  33. (count: number) => {
  34. this.unreadCount = count;
  35. this.update();
  36. },
  37. );
  38. this.update();
  39. }
  40. private update(): void {
  41. if (this.unreadCount > 0) {
  42. this.title = `(${this.unreadCount}) ${this.DEFAULT_TITLE}`;
  43. } else {
  44. this.title = this.DEFAULT_TITLE;
  45. }
  46. this.$document[0].title = this.title;
  47. }
  48. }