import { ChangeDetectorRef, Component, ElementRef, HostBinding, Input, OnDestroy, OnInit, SkipSelf, TemplateRef, ViewChild } from "@angular/core"; import {WindowState} from "./window-state"; import {Electron} from "../../core/utils"; @Component({ selector: 'dui-window-header', template: `
`, host: { '[class.inactive]': '!windowState.focus.value', '[class.size-default]': `size === 'default'`, '[class.size-small]': `size === 'small'`, }, styleUrls: ['./window-header.component.scss'] }) export class WindowHeaderComponent implements OnDestroy { @Input() public size: 'small' | 'default' = 'default'; @HostBinding('class.with-toolbar') get withToolbar() { return this.windowState.toolbars['default'] && this.windowState.toolbars['default'].length; } protected focusSub = this.windowState.focus.subscribe((v) => { this.cdParent.markForCheck(); }); constructor( public windowState: WindowState, @SkipSelf() protected cdParent: ChangeDetectorRef, protected element: ElementRef, ) { windowState.header = this; } ngOnDestroy() { this.focusSub.unsubscribe(); } public getBottomPosition(): number { const rect = this.element.nativeElement.getBoundingClientRect(); return rect.y + rect.height; } maximize() { const win = Electron.getRemote().BrowserWindow.getFocusedWindow(); if (!win.isMaximized()) { Electron.getRemote().BrowserWindow.getFocusedWindow().maximize(); } else { Electron.getRemote().BrowserWindow.getFocusedWindow().unmaximize(); } } minimize() { Electron.getRemote().BrowserWindow.getFocusedWindow().minimize(); } close() { Electron.getRemote().BrowserWindow.getFocusedWindow().close(); } } @Component({ selector: 'dui-window-toolbar', template: ` ` }) export class WindowToolbarComponent implements OnDestroy, OnInit { @Input() for: string = 'default'; @ViewChild('templateRef', {static: true}) template!: TemplateRef; constructor(protected windowState: WindowState) { } ngOnInit() { this.windowState.addToolbarContainer(this.for, this.template); } ngOnDestroy(): void { this.windowState.removeToolbarContainer(this.for, this.template); } } @Component({ selector: 'dui-window-toolbar-container', template: ` `, styles: [` :host { display: flex; } `], }) export class WindowToolbarContainerComponent implements OnInit, OnDestroy { @Input() name: string = 'default'; constructor( public windowState: WindowState, protected cd: ChangeDetectorRef, ) { } ngOnInit() { this.windowState.toolbarContainers[this.name] = this; } public toolbarsUpdated() { this.cd.detectChanges(); } ngOnDestroy(): void { delete this.windowState.toolbarContainers[this.name]; } }