-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
213 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { AppService } from './app.service'; | ||
|
||
describe('AppService', () => { | ||
let service: AppService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(AppService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { IStreamStatus, SignalKDeltaService } from './signalk-delta.service'; | ||
import { NotificationsService } from './notifications.service'; | ||
import { IConnectionConfig } from './app-settings.interfaces'; | ||
import { AppSettingsService } from './app-settings.service'; | ||
import { Injectable } from '@angular/core'; | ||
import { SignalKService } from './signalk.service'; | ||
import { Observable } from 'rxjs'; | ||
|
||
const sunPath: string = 'self.environment.sun'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class AppService { | ||
public autoNightMode: boolean; // from Config value | ||
private sunValue: string = 'day'; | ||
private dayTheme: string; | ||
|
||
constructor( | ||
private settings: AppSettingsService, | ||
private delta: SignalKDeltaService, | ||
private sk: SignalKService, | ||
private notification: NotificationsService | ||
) { | ||
this.autoNightMode = this.settings.getAutoNightMode(); | ||
this.autoNightModeObserver(); | ||
} | ||
|
||
private autoNightModeObserver(): void { | ||
let deltaStatus = this.delta.getDataStreamStatusAsO(); // wait for delta service to start | ||
deltaStatus.subscribe(stat => { | ||
stat as IStreamStatus; | ||
if(stat.operation == 2) { | ||
|
||
setTimeout(() => { // Wait for path data to come in on startup | ||
const autoNightMode: Observable<boolean> = this.settings.getAutoNightModeAsO(); | ||
autoNightMode.subscribe(mode => { | ||
this.autoNightMode = mode; | ||
if (mode) { | ||
if (this.sk.getPathObject(sunPath) !== null) { | ||
|
||
// capture none nightMode theme name changes | ||
this.settings.getThemeNameAsO().subscribe(theme => { | ||
if (theme != 'nightMode') | ||
this.dayTheme = theme; | ||
}); | ||
|
||
const connConf: IConnectionConfig = this.settings.getConnectionConfig(); // get app UUUID | ||
|
||
this.sk.subscribePath(connConf.kipUUID, sunPath, 'default').subscribe(sun => { | ||
if (sun.value == 'night' && this.sunValue != sun.value) { | ||
this.sunValue = sun.value; | ||
this.settings.setThemName('nightMode'); | ||
} else if (sun.value == 'day' && this.sunValue != sun.value) { | ||
this.sunValue = sun.value; | ||
this.settings.setThemName(this.dayTheme); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
}, 0); | ||
} | ||
}); | ||
} | ||
|
||
public validateAutoNighModeSupported(): boolean { | ||
if (this.sk.getPathObject(sunPath) == null) { | ||
this.notification.sendSnackbarNotification("Dependency Error: self.environment.sun path was not found. To enable Automatic Night Mode, verify that the following Signal K requirements are meet: 1) The Derived Data plugin is installed and enabled. 2) The plugin's Sun:Sets environment.sun parameter is checked.", 0); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public set autoNightModeConfig(isEnabled : boolean) { | ||
this.settings.setAutoNightMode(isEnabled); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...fications/notifications.component.spec.ts → ...ettings/general/general.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { INotificationConfig } from '../../app-settings.interfaces'; | ||
import { AppService } from '../../app.service'; | ||
import { AppSettingsService } from '../../app-settings.service'; | ||
import { NotificationsService } from '../../notifications.service'; | ||
|
||
|
||
@Component({ | ||
selector: 'settings-general', | ||
templateUrl: './general.component.html', | ||
styleUrls: ['./general.component.css'], | ||
}) | ||
export class SettingsGeneralComponent implements OnInit { | ||
|
||
public notificationConfig: INotificationConfig; | ||
public autoNightModeConfig: boolean; | ||
|
||
constructor( | ||
private notifications: NotificationsService, | ||
private app: AppService, | ||
private settings: AppSettingsService, | ||
) { } | ||
|
||
ngOnInit() { | ||
this.notificationConfig = this.settings.getNotificationConfig(); | ||
this.autoNightModeConfig = this.app.autoNightMode; | ||
} | ||
|
||
public saveAllSettings():void { | ||
try { | ||
this.saveNotificationsSettings(); | ||
this.saveAutoNightMode(); | ||
this.notifications.sendSnackbarNotification("General settings saved", 5000, false); | ||
} catch (error) { | ||
this.notifications.sendSnackbarNotification("Error saving settings: " + error, 5000, false); | ||
} | ||
|
||
} | ||
|
||
public saveNotificationsSettings(): void { | ||
this.settings.setNotificationConfig(this.notificationConfig); | ||
} | ||
|
||
public saveAutoNightMode() { | ||
this.app.autoNightModeConfig = this.autoNightModeConfig; | ||
} | ||
|
||
public isAutoNightPathSupported(event):void { | ||
if (event.checked) { | ||
if (!this.app.validateAutoNighModeSupported()) { | ||
this.autoNightModeConfig = false; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.