import {FileElegularWindow} from "../../../window/fileMode/file-elegular-window.class"; import {ElegularWindowEvent} from "./elegular-window-event.enum"; import { ElegularWindowEventListener, IElegularWindowEventListenerConstructor } from "./elegular-window-event-listener/elegular-window-enent-listener"; // import SwipeDirection = Electron.SwipeDirection; import {ElegularWindowBase} from "../../../window/elegular-winodw-base.class"; export class ElegularWindowEventManager { constructor(private _elegularWindow: ElegularWindowBase) { } private _eventListenerMap = new Map>(); public getEventListener(event: ElegularWindowEvent, constructor?: IElegularWindowEventListenerConstructor): ElegularWindowEventListener { if (!constructor) { constructor = ElegularWindowEventListener; } let result = >this._eventListenerMap.get(event); if (!result) { result = new constructor(event, this._elegularWindow); this._eventListenerMap.set(event, result); } return result; } /** * Emitted when the document changed its title, * calling event.preventDefault() would prevent the native window’s title to change. */ public get pageTitleUpdated(): ElegularWindowEventListener { return this.getEventListener<(event: Event, title: string) => void>(ElegularWindowEvent.PageTitleUpdated); } /** * Emitted when the window is going to be closed. It's emitted before the before unload * and unload event of the DOM. Calling event.preventDefault() will cancel the close. */ public get close(): ElegularWindowEventListener<(event: Event) => void> { return this.getEventListener<(event: Event) => void>(ElegularWindowEvent.Close); } /** * Emitted when the window is closed. After you have received this event * you should remove the reference to the window and avoid using it anymore. */ public get closed(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.Closed); } /** * Emitted when the web page becomes unresponsive. */ public get unresponsive(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.Unresponsive); } /** * Emitted when the unresponsive web page becomes responsive again. */ public get responsive(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.Responsive); } /** * Emitted when the window loses focus. */ public get blur(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.Blur); } /** * Emitted when the window gains focus. */ public get focus(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.Focus); } /** * Emitted when the window is shown. */ public get show(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.Show); } /** * Emitted when the window is hidden. */ public get hide(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.Hide); } /** * Emitted when the web page has been rendered and window can be displayed without visual flash. */ public get readyToShow(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.ReadyToShow); } /** * Emitted when window is maximized. */ public get maximize(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.Maximize); } /** * Emitted when the window exits from maximized state. */ public get unmaximize(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.Unmaximize); } /** * Emitted when the window is minimized. */ public get minimize(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.Minimize); } /** * Emitted when the window is restored from minimized state. */ public get restore(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.Restore); } /** * Emitted when the window is getting resized. */ public get resize(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.Resize); } /** * Emitted when the window is getting moved to a new position. */ public get move(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.Move); } /** * Emitted when the window enters full screen state. */ public get enterFullScreen(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.EnterFullScreen); } /** * Emitted when the window leaves full screen state. */ public get leaveFullScreen(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.LeaveFullScreen); } /** * Emitted when the window enters full screen state triggered by HTML API. */ public get enterHtmlFullScreen(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.EnterHtmlFullScreen); } /** * Emitted when the window leaves full screen state triggered by HTML API. */ public get leaveHtmlFullScreen(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.LeaveHtmlFullScreen); } /** * Emitted when an App Command is invoked. These are typically related * to keyboard media keys or browser commands, as well as the "Back" / * "Forward" buttons built into some mice on Windows. * Note: This is only implemented on Windows. */ public get appCommand(): ElegularWindowEventListener { return this.getEventListener<(event: Event, command: string) => void>(ElegularWindowEvent.AppCommand); } /** * Emitted when scroll wheel event phase has begun. * Note: This is only implemented on macOS. */ public get scrollTouchBegin(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.ScrollTouchBegin); } /** * Emitted when scroll wheel event phase has ended. * Note: This is only implemented on macOS. */ public get scrollTouchEnd(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.ScrollTouchEnd); } /** * Emitted when scroll wheel event phase filed upon reaching the edge of element. * Note: This is only implemented on macOS. */ public get scrollTouchEdge(): ElegularWindowEventListener { return this.getEventListener(ElegularWindowEvent.ScrollTouchEdge); } /** * Emitted on 3-finger swipe. * Note: This is only implemented on macOS. */ public get swipe(): ElegularWindowEventListener { return this.getEventListener<(event: Event, direction: string) => void>(ElegularWindowEvent.Swipe); } }