@deepkit/desktop-ui
Version:
Library for desktop UI widgets in Angular 10+
139 lines (125 loc) • 4.11 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 { Component, ElementRef, forwardRef, HostBinding, inject, input, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { WindowState, WinHeader } from './window-state';
import { Electron } from '../../core/utils';
import { IconComponent } from '../icon/icon.component';
import { NgTemplateOutlet } from '@angular/common';
export class WindowHeaderComponent implements WinHeader {
public size = input<'small' | 'default'>('default');
protected get withToolbar() {
return this.windowState.toolbars()['default']?.length;
}
constructor(
public windowState: WindowState,
protected element: ElementRef,
) {
this.windowState = windowState;
}
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 = input<string>('default');
template?: TemplateRef<any>;
constructor(protected windowState: WindowState) {
}
ngOnInit() {
if (!this.template) return;
this.windowState.addToolbarContainer(this.for(), this.template);
}
ngOnDestroy(): void {
if (!this.template) return;
this.windowState.removeToolbarContainer(this.for(), this.template);
}
}
export class WindowToolbarContainerComponent {
name = input<string>('default');
windowState = inject(WindowState);
}