From 181d03df2328509d2db8f4d6eda23e61d496352b Mon Sep 17 00:00:00 2001
From: Philipp Sautner <philipp.sautner@mni.thm.de>
Date: Mon, 25 Oct 2021 13:25:49 +0200
Subject: [PATCH] Uses App_initializer to init config service, which calls
 localstorageservice

---
 src/app/app.config.ts                           |  5 ++++-
 src/app/app.module.ts                           |  6 +++---
 .../http/local-storage-share.service.ts         | 17 ++++++++++-------
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/app/app.config.ts b/src/app/app.config.ts
index fb3eec3ad..e0edaec89 100644
--- a/src/app/app.config.ts
+++ b/src/app/app.config.ts
@@ -2,10 +2,13 @@ import { Injectable } from '@angular/core';
 import { HttpClient } from '@angular/common/http';
 import { environment } from '../environments/environment';
 import { IAppConfig } from './models/app-config.model';
+import { LocalStorageShareService } from './services/http/local-storage-share.service';
+
 @Injectable()
 export class AppConfig {
     static settings: IAppConfig;
-    constructor(private http: HttpClient) {}
+    constructor(private http: HttpClient, private localStorageShareService: LocalStorageShareService) {
+    }
     load() {
         const jsonFile = `assets/config/config.${environment.name}.json`;
         return new Promise<void>((resolve, reject) => {
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 658a12fe7..ee0157fe4 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -1,4 +1,4 @@
-import { NgModule } from '@angular/core';
+import { NgModule, APP_INITIALIZER } from '@angular/core';
 import { AppComponent } from './app.component';
 import { RegisterComponent } from './components/home/_dialogs/register/register.component';
 import { PasswordResetComponent } from './components/home/_dialogs/password-reset/password-reset.component';
@@ -149,11 +149,11 @@ export function initializeApp(appConfig: AppConfig) {
     QuillModule.forRoot()
   ],
   providers: [
-    /*AppConfig,
+    AppConfig,
     { provide: APP_INITIALIZER,
       useFactory: initializeApp,
       deps: [AppConfig], multi: true
-    },*/
+    },
     {
       provide: HTTP_INTERCEPTORS,
       useClass: AuthenticationInterceptor,
diff --git a/src/app/services/http/local-storage-share.service.ts b/src/app/services/http/local-storage-share.service.ts
index 9c58ad310..f8e50eb68 100644
--- a/src/app/services/http/local-storage-share.service.ts
+++ b/src/app/services/http/local-storage-share.service.ts
@@ -11,14 +11,17 @@ export class LocalStorageShareService {
 
   messageHandler(event) {
     const { action, key, value} = event.data;
-    if (action == 'save') {
+    if (action === 'save') {
       window.localStorage.setItem(key, JSON.stringify(value));
-    } else if (action == 'get') {
-      event.source.postMessage({
-        action: 'returnData',
-        key,
-        JSON.parse(window.localStorage.getItem(key))
-      }, '*')
+    } else if (action === 'get') {
+      const obj = JSON.parse(window.localStorage.getItem(key));
+      if(obj !== null) {
+        event.source.postMessage({
+          action: 'returnData',
+          key,
+          obj
+        }, '*');
+      }
     }
   }
 }
-- 
GitLab