import { Injector } from '@angular/core'; import { Injectable, InjectionToken } from '@angular/core'; import { fromEvent, Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @Injectable({ providedIn: 'root' }) export class DebugService { private destroy$ = new Subject(); isDebug = false; // private key = 'FARRIS_DEBUGGING'; // this.isDebug = !!window[this.key]; constructor() { } destroy() { this.destroy$.next(); this.destroy$.complete(); } debug( msg: any, type: 'log' | 'warn' | 'error' | 'warn' = 'log') { if (this.isDebug) { console[type](msg); } } toggleDebugMode() { fromEvent(document.body, 'keydown').pipe( takeUntil(this.destroy$) ).subscribe( (e: KeyboardEvent) => { if (e.ctrlKey && e.shiftKey && e.key === 'D') { e.preventDefault(); e.stopPropagation(); this.isDebug = !this.isDebug; console.log(`Farris debug mode is ${ this.isDebug ? 'startting' : 'stopped'}.`); } }); } }