Listen to window change and pass through to ScreenDprMonitor

This commit is contained in:
Daniel Imms
2023-10-17 08:39:48 -07:00
parent c80453f602
commit 45605db3c5
8 changed files with 64 additions and 18 deletions
+21 -2
View File
@@ -3,23 +3,42 @@
* @license MIT
*/
import { Disposable } from 'common/Lifecycle';
import { ICoreBrowserService } from './Services';
import { EventEmitter } from 'common/EventEmitter';
export class CoreBrowserService implements ICoreBrowserService {
export class CoreBrowserService extends Disposable implements ICoreBrowserService {
public serviceBrand: undefined;
private _isFocused = false;
private _cachedIsFocused: boolean | undefined = undefined;
private readonly _onWindowChange = this.register(new EventEmitter<Window & typeof globalThis>());
public readonly onWindowChange = this._onWindowChange.event;
constructor(
private _textarea: HTMLTextAreaElement,
public readonly window: Window & typeof globalThis,
// TODO: Add getter and setter and event
private _window: Window & typeof globalThis,
public readonly mainDocument: Document
) {
super();
this._textarea.addEventListener('focus', () => this._isFocused = true);
this._textarea.addEventListener('blur', () => this._isFocused = false);
}
public get window(): Window & typeof globalThis {
return this._window;
}
public set window(value: Window & typeof globalThis) {
if (this._window !== value) {
this._window = value;
this._onWindowChange.fire(this._window);
}
}
public get dpr(): number {
return this.window.devicePixelRatio;
}