diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 2f4ef70..dd7fbb3 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -55,6 +55,20 @@ export class AppComponent implements OnInit { } }); + this.loadConfig(); + this.postsService.settings_changed.subscribe(changed => { + if (changed) { + this.loadConfig(); + } + }); + + } + + toggleSidenav() { + this.sidenav.toggle(); + } + + loadConfig() { // loading config this.postsService.loadNavItems().subscribe(res => { // loads settings const result = !this.postsService.debugMode ? res['config_file'] : res; @@ -71,11 +85,6 @@ export class AppComponent implements OnInit { }, error => { console.log(error); }); - - } - - toggleSidenav() { - this.sidenav.toggle(); } // theme stuff diff --git a/src/app/main/main.component.ts b/src/app/main/main.component.ts index bc7b2be..24b7037 100644 --- a/src/app/main/main.component.ts +++ b/src/app/main/main.component.ts @@ -213,6 +213,25 @@ export class MainComponent implements OnInit { private router: Router, public dialog: MatDialog, private platform: Platform, private route: ActivatedRoute) { this.audioOnly = false; + this.configLoad(); + + this.postsService.settings_changed.subscribe(changed => { + if (changed) { + this.loadConfig(); + } + }); + } + + async configLoad() { + await this.loadConfig(); + if (this.autoStartDownload) { + this.downloadClicked(); + } + + setInterval(() => this.getSimulatedOutput(), 1000); + } + + async loadConfig() { // loading config this.postsService.loadNavItems().subscribe(res => { // loads settings const result = !this.postsService.debugMode ? res['config_file'] : res; @@ -266,16 +285,13 @@ export class MainComponent implements OnInit { if (youtubeUsername && youtubeUsername !== 'null') { this.youtubeUsername = youtubeUsername }; } - if (this.autoStartDownload) { - this.downloadClicked(); - } - - setInterval(() => this.getSimulatedOutput(), 1000); + return true; }, error => { console.log(error); - }); + return false; + }); } // app initialization. diff --git a/src/app/posts.services.ts b/src/app/posts.services.ts index 4ecff3b..f618f39 100644 --- a/src/app/posts.services.ts +++ b/src/app/posts.services.ts @@ -9,6 +9,7 @@ import 'rxjs/add/observable/throw'; import { THEMES_CONFIG } from '../themes'; import { Router } from '@angular/router'; import { DOCUMENT } from '@angular/common'; +import { BehaviorSubject } from 'rxjs'; @Injectable() export class PostsService { @@ -20,6 +21,7 @@ export class PostsService { handShakeComplete = false; THEMES_CONFIG = THEMES_CONFIG; theme; + settings_changed = new BehaviorSubject(false); debugMode = false; constructor(private http: HttpClient, private router: Router, @Inject(DOCUMENT) private document: Document) { diff --git a/src/app/settings/settings.component.ts b/src/app/settings/settings.component.ts index 39cdcbc..7386852 100644 --- a/src/app/settings/settings.component.ts +++ b/src/app/settings/settings.component.ts @@ -38,6 +38,7 @@ export class SettingsComponent implements OnInit { this.postsService.setConfig(settingsToSave).subscribe(res => { if (res['success']) { // sets new config as old config + this.postsService.settings_changed.next(true); this.initial_config = JSON.parse(JSON.stringify(this.new_config)); } }, err => {