@deepkit/desktop-ui
Version:
Library for desktop UI widgets in Angular 10+
167 lines (147 loc) • 4.78 kB
text/typescript
/*
* Deepkit Framework
* Copyright (C) 2021 Deepkit UG, Marc J. Schmidt
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the MIT License.
*
* You should have received a copy of the MIT License along with this program.
*/
import {
ChangeDetectorRef,
Component,
ElementRef,
HostBinding,
Input,
OnDestroy,
OnInit,
SkipSelf,
TemplateRef,
ViewChild,
} from '@angular/core';
import { WindowState } from './window-state';
import { Electron } from '../../core/utils';
export class WindowHeaderComponent implements OnDestroy {
public size: 'small' | 'default' = 'default';
get withToolbar() {
return this.windowState.toolbars['default'] && this.windowState.toolbars['default'].length;
}
protected focusSub: any = this.windowState.focus.subscribe((v) => {
this.cdParent.markForCheck();
});
constructor(
public windowState: WindowState,
protected cdParent: ChangeDetectorRef,
protected element: ElementRef,
) {
this.windowState = windowState;
}
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();
}
}
export class WindowToolbarComponent implements OnDestroy, OnInit {
for: string = 'default';
template!: TemplateRef<any>;
constructor(protected windowState: WindowState) {
}
ngOnInit() {
this.windowState.addToolbarContainer(this.for, this.template);
}
ngOnDestroy(): void {
this.windowState.removeToolbarContainer(this.for, this.template);
}
}
export class WindowToolbarContainerComponent implements OnInit, OnDestroy {
name: string = 'default';
constructor(
public windowState: WindowState,
protected cd: ChangeDetectorRef,
) {
}
ngOnInit() {
if (this.windowState.toolbarContainers[this.name] && this.name === 'default') {
console.warn(`You have multiple <dui-window-toolbar-container> with no name. This is not allowed.`);
}
this.windowState.toolbarContainers[this.name] = this;
}
public toolbarsUpdated() {
this.cd.detectChanges();
}
ngOnDestroy(): void {
delete this.windowState.toolbarContainers[this.name];
}
}