2018-09-22 06:22:51 +02:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2019-11-14 05:12:00 +01:00
|
|
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
|
|
|
import { Howl } from 'howler';
|
|
|
|
|
2019-05-22 02:18:01 +02:00
|
|
|
import { environment } from '../../../../environments/environment';
|
2019-11-14 05:12:00 +01:00
|
|
|
import { ToolsService } from '../../../services/tools.service';
|
|
|
|
import { UserNotificationService, NotificationSoundDefinition } from '../../../services/user-notification.service';
|
2018-09-22 06:22:51 +02:00
|
|
|
|
|
|
|
@Component({
|
2019-05-21 07:19:34 +02:00
|
|
|
selector: 'app-settings',
|
|
|
|
templateUrl: './settings.component.html',
|
|
|
|
styleUrls: ['./settings.component.scss']
|
2018-09-22 06:22:51 +02:00
|
|
|
})
|
2020-02-20 05:40:11 +01:00
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
export class SettingsComponent implements OnInit {
|
2019-11-15 04:58:09 +01:00
|
|
|
|
2019-11-14 05:12:00 +01:00
|
|
|
notificationSounds: NotificationSoundDefinition[];
|
|
|
|
notificationSoundId: string;
|
|
|
|
notificationForm: FormGroup;
|
2018-09-22 06:22:51 +02:00
|
|
|
|
2019-11-15 04:58:09 +01:00
|
|
|
disableAutofocusEnabled: boolean;
|
|
|
|
disableAvatarNotificationsEnabled: boolean;
|
|
|
|
disableSoundsEnabled: boolean;
|
|
|
|
version: string;
|
|
|
|
|
2020-02-20 05:40:11 +01:00
|
|
|
columnShortcutEnabled: ColumnShortcut = ColumnShortcut.Ctrl;
|
|
|
|
columnShortcutChanged = false;
|
2019-11-15 04:58:09 +01:00
|
|
|
|
2019-11-14 05:12:00 +01:00
|
|
|
constructor(
|
|
|
|
private formBuilder: FormBuilder,
|
|
|
|
private readonly toolsService: ToolsService,
|
|
|
|
private readonly userNotificationsService: UserNotificationService) { }
|
2019-05-21 07:19:34 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.version = environment.VERSION;
|
2019-11-14 05:12:00 +01:00
|
|
|
|
2019-11-16 23:27:29 +01:00
|
|
|
const settings = this.toolsService.getSettings();
|
|
|
|
|
2019-11-14 05:12:00 +01:00
|
|
|
this.notificationSounds = this.userNotificationsService.getAllNotificationSounds();
|
2019-11-16 23:27:29 +01:00
|
|
|
this.notificationSoundId = settings.notificationSoundFileId;
|
2019-11-14 05:12:00 +01:00
|
|
|
this.notificationForm = this.formBuilder.group({
|
|
|
|
countryControl: [this.notificationSounds[this.notificationSoundId].id]
|
|
|
|
});
|
2019-11-16 23:27:29 +01:00
|
|
|
|
|
|
|
this.disableAutofocusEnabled = settings.disableAutofocus;
|
|
|
|
this.disableAvatarNotificationsEnabled = settings.disableAvatarNotifications;
|
|
|
|
this.disableSoundsEnabled = settings.disableSounds;
|
2020-02-20 05:40:11 +01:00
|
|
|
|
|
|
|
if(!settings.columnSwitchingWinAlt){
|
|
|
|
this.columnShortcutEnabled = ColumnShortcut.Ctrl;
|
|
|
|
} else {
|
|
|
|
this.columnShortcutEnabled = ColumnShortcut.Win;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onShortcutChange(id: ColumnShortcut){
|
|
|
|
this.columnShortcutEnabled = id;
|
|
|
|
this.columnShortcutChanged = true;
|
|
|
|
|
|
|
|
let settings = this.toolsService.getSettings()
|
|
|
|
settings.columnSwitchingWinAlt = id === ColumnShortcut.Win;
|
|
|
|
this.toolsService.saveSettings(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
reload(): boolean {
|
|
|
|
window.location.reload();
|
|
|
|
return false;
|
2019-11-14 05:12:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onChange(soundId: string) {
|
|
|
|
this.notificationSoundId = soundId;
|
|
|
|
let settings = this.toolsService.getSettings()
|
|
|
|
settings.notificationSoundFileId = soundId;
|
|
|
|
this.toolsService.saveSettings(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
playNotificationSound(): boolean {
|
|
|
|
let soundData = this.notificationSounds.find(x => x.id === this.notificationSoundId);
|
|
|
|
|
|
|
|
let sound = new Howl({
|
|
|
|
src: [soundData.path]
|
|
|
|
});
|
|
|
|
sound.play();
|
|
|
|
|
|
|
|
return false;
|
2019-05-21 07:19:34 +02:00
|
|
|
}
|
2019-11-15 04:58:09 +01:00
|
|
|
|
|
|
|
onDisableAutofocusChanged(){
|
2019-11-16 23:27:29 +01:00
|
|
|
let settings = this.toolsService.getSettings();
|
|
|
|
settings.disableAutofocus = this.disableAutofocusEnabled;
|
|
|
|
this.toolsService.saveSettings(settings);
|
2019-11-15 04:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onDisableAvatarNotificationsChanged(){
|
2019-11-16 23:27:29 +01:00
|
|
|
let settings = this.toolsService.getSettings();
|
|
|
|
settings.disableAvatarNotifications = this.disableAvatarNotificationsEnabled;
|
|
|
|
this.toolsService.saveSettings(settings);
|
2019-11-15 04:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onDisableSoundsEnabledChanged(){
|
2019-11-16 23:27:29 +01:00
|
|
|
let settings = this.toolsService.getSettings();
|
|
|
|
settings.disableSounds = this.disableSoundsEnabled;
|
|
|
|
this.toolsService.saveSettings(settings);
|
2019-11-15 04:58:09 +01:00
|
|
|
}
|
|
|
|
|
2019-12-01 03:42:50 +01:00
|
|
|
isCleanningAll: boolean = false;
|
|
|
|
startClearAllLocalData(): boolean {
|
|
|
|
this.isCleanningAll = !this.isCleanningAll;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
confirmClearAll(): boolean{
|
|
|
|
localStorage.clear();
|
|
|
|
location.reload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cancelClearAll(): boolean {
|
|
|
|
this.isCleanningAll = false;
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-20 05:40:11 +01:00
|
|
|
}
|
|
|
|
|
2019-12-01 03:42:50 +01:00
|
|
|
|
2020-02-20 05:40:11 +01:00
|
|
|
enum ColumnShortcut {
|
|
|
|
Ctrl = 1,
|
|
|
|
Win = 2
|
2019-05-22 02:18:01 +02:00
|
|
|
}
|