Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 864e819

Browse files
authored
Merge pull request #54 from cryptic-game/experimental
44-Reworked the window system to fix wrong window closing-master
2 parents 4bd32b9 + d0743c5 commit 864e819

13 files changed

+805
-734
lines changed

package-lock.json

Lines changed: 715 additions & 694 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@
1111
},
1212
"private": true,
1313
"dependencies": {
14-
"@angular/animations": "~8.0.0",
15-
"@angular/cdk": "^8.0.1",
16-
"@angular/common": "~8.0.0",
17-
"@angular/compiler": "~8.0.0",
18-
"@angular/core": "~8.0.0",
19-
"@angular/forms": "~8.0.0",
20-
"@angular/platform-browser": "~8.0.0",
21-
"@angular/platform-browser-dynamic": "~8.0.0",
22-
"@angular/router": "~8.0.0",
14+
"@angular/animations": "^8.1.2",
15+
"@angular/cdk": "^8.1.1",
16+
"@angular/common": "^8.1.2",
17+
"@angular/compiler": "^8.1.2",
18+
"@angular/core": "^8.1.2",
19+
"@angular/forms": "^8.1.2",
20+
"@angular/platform-browser": "^8.1.2",
21+
"@angular/platform-browser-dynamic": "^8.1.2",
22+
"@angular/router": "^8.1.2",
2323
"ngx-contextmenu": "^5.2.0",
2424
"rxjs": "~6.4.0",
2525
"tslib": "^1.9.0",
2626
"zone.js": "~0.9.1"
2727
},
2828
"devDependencies": {
29-
"@angular-devkit/build-angular": "~0.800.0",
30-
"@angular/cli": "~8.0.2",
31-
"@angular/compiler-cli": "~8.0.0",
32-
"@angular/language-service": "~8.0.0",
33-
"@types/jasmine": "~3.3.8",
29+
"@angular-devkit/build-angular": "^0.800.6",
30+
"@angular/cli": "^8.1.2",
31+
"@angular/compiler-cli": "^8.1.2",
32+
"@angular/language-service": "^8.1.2",
33+
"@types/jasmine": "^3.3.15",
3434
"@types/jasminewd2": "~2.0.3",
3535
"@types/node": "~8.9.4",
3636
"codelyzer": "^5.0.1",
3737
"jasmine-core": "^3.4.0",
3838
"jasmine-spec-reporter": "~4.2.1",
3939
"karma": "~4.1.0",
4040
"karma-chrome-launcher": "~2.2.0",
41-
"karma-coverage-istanbul-reporter": "~2.0.1",
41+
"karma-coverage-istanbul-reporter": "^2.1.0",
4242
"karma-jasmine": "^2.0.1",
4343
"karma-jasmine-html-reporter": "^1.4.0",
4444
"protractor": "~5.4.0",

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { WindowFrameComponent } from './desktop/window/window-frame.component';
2121
import { WindowManagerComponent } from './desktop/window-manager/window-manager.component';
2222
import { TestWindowComponent } from './desktop/windows/test-window/test-window.component';
2323
import { TerminalComponent } from './desktop/windows/terminal/terminal.component';
24+
import { WindowPlaceDirective } from './desktop/window/window-place.directive';
2425

2526
const routes: Routes = [
2627
{ path: '', component: DesktopComponent, canActivate: [DesktopGuard] },
@@ -44,7 +45,8 @@ const routes: Routes = [
4445
WindowFrameComponent,
4546
WindowManagerComponent,
4647
TestWindowComponent,
47-
TerminalComponent
48+
TerminalComponent,
49+
WindowPlaceDirective
4850
],
4951
imports: [
5052
RouterModule.forRoot(routes),

src/app/desktop/window-manager/window-manager.component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[style.top.px]="window.position.maximized ? 0 : window.position.y"
55
[style.z-index]="window.position.zIndex"
66
style="position: fixed;">
7-
<ng-container [ngComponentOutlet]="window.type"></ng-container>
87
</app-window-frame>
98
</div>
109
</div>

src/app/desktop/window/window-delegate.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { Type } from '@angular/core';
33
export abstract class WindowDelegate {
44
title: string;
55
icon: string;
6-
type: Type<any>;
6+
type: Type<WindowComponent>;
7+
8+
component: WindowComponent;
79

810
position: WindowPosition = {
911
x: 0,
@@ -27,3 +29,7 @@ export interface WindowPosition {
2729
maximized: boolean;
2830
minimized: boolean;
2931
}
32+
33+
export abstract class WindowComponent {
34+
delegate: WindowDelegate;
35+
}

src/app/desktop/window/window-frame.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
</div>
2323

2424
<div class="window-content">
25-
<ng-content></ng-content>
25+
<ng-template appWindowPlace></ng-template>
2626
</div>
2727
</div>

src/app/desktop/window/window-frame.component.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { WindowFrameComponent } from './window-frame.component';
44
import { WindowDelegate } from './window-delegate';
5+
import { TestWindowComponent } from '../windows/test-window/test-window.component';
6+
import { NgModule } from '@angular/core';
7+
import { WindowPlaceDirective } from './window-place.directive';
58

69
describe('WindowFrameComponent', () => {
710
let component: WindowFrameComponent;
811
let fixture: ComponentFixture<WindowFrameComponent>;
912

1013
beforeEach(async(() => {
1114
TestBed.configureTestingModule({
12-
declarations: [WindowFrameComponent]
15+
imports: [EntryComponentsTestModule],
16+
declarations: [WindowFrameComponent, WindowPlaceDirective]
1317
})
1418
.compileComponents();
1519
}));
@@ -19,6 +23,7 @@ describe('WindowFrameComponent', () => {
1923
component = fixture.componentInstance;
2024
component.delegate = new class extends WindowDelegate {
2125
title = 'Test';
26+
type = TestWindowComponent;
2227
icon = '';
2328
};
2429
fixture.detectChanges();
@@ -28,3 +33,11 @@ describe('WindowFrameComponent', () => {
2833
expect(component).toBeTruthy();
2934
});
3035
});
36+
37+
38+
@NgModule({
39+
declarations: [TestWindowComponent],
40+
entryComponents: [TestWindowComponent]
41+
})
42+
class EntryComponentsTestModule {
43+
}

src/app/desktop/window/window-frame.component.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Component, HostListener, Input, OnInit } from '@angular/core';
1+
import { Component, ComponentFactoryResolver, HostListener, Input, OnInit, ViewChild } from '@angular/core';
22
import { WindowManagerService } from '../window-manager/window-manager.service';
33
import { WindowDelegate } from './window-delegate';
4+
import { WindowPlaceDirective } from './window-place.directive';
45

56
@Component({
67
selector: 'app-window-frame',
@@ -11,6 +12,8 @@ export class WindowFrameComponent implements OnInit {
1112
static minWidth = 300;
1213
static minHeight = 150;
1314

15+
@ViewChild(WindowPlaceDirective, { static: true }) windowPlace: WindowPlaceDirective;
16+
1417
@Input() delegate: WindowDelegate;
1518
dragging = false;
1619
dragStartWindowPos: [number, number] = [0, 0];
@@ -19,10 +22,18 @@ export class WindowFrameComponent implements OnInit {
1922
resizeDirection = 0;
2023
resizeStartSize: [number, number] = [0, 0];
2124

22-
constructor(public windowManager: WindowManagerService) {
25+
constructor(public windowManager: WindowManagerService, private componentFactoryResolver: ComponentFactoryResolver) {
2326
}
2427

2528
ngOnInit() {
29+
this.loadWindowContent();
30+
}
31+
32+
loadWindowContent() {
33+
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.delegate.type);
34+
const componentRef = this.windowPlace.viewContainerRef.createComponent(componentFactory);
35+
componentRef.instance.delegate = this.delegate;
36+
this.delegate.component = componentRef.instance;
2637
}
2738

2839
close() {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Directive, ViewContainerRef } from '@angular/core';
2+
3+
@Directive({
4+
selector: '[appWindowPlace]'
5+
})
6+
export class WindowPlaceDirective {
7+
8+
constructor(public viewContainerRef: ViewContainerRef) {
9+
}
10+
11+
}

src/app/desktop/windows/terminal/terminal-states.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ export class DefaultTerminalState extends CommandTerminalState {
167167
if (this.activeDevice['uuid'] === JSON.parse(sessionStorage.getItem('activeDevice'))['uuid']) {
168168
sessionStorage.setItem('activeDevice', JSON.stringify(newDevice));
169169
}
170+
} else {
171+
this.terminal.outputText('The hostname couldn\'t be changed');
170172
}
171173
});
172174
} else {

src/app/desktop/windows/terminal/terminal.component.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
import { Component, ElementRef, OnInit, SecurityContext, Type, ViewChild } from '@angular/core';
2-
import { WindowDelegate } from '../../window/window-delegate';
2+
import { WindowComponent, WindowDelegate } from '../../window/window-delegate';
33
import { TerminalAPI, TerminalState } from './terminal-api';
44
import { WindowManagerService } from '../../window-manager/window-manager.service';
55
import { DefaultTerminalState } from './terminal-states';
66
import { WebsocketService } from '../../../websocket.service';
77
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
88

9+
// noinspection AngularMissingOrInvalidDeclarationInModule
910
@Component({
1011
selector: 'app-terminal',
1112
templateUrl: './terminal.component.html',
1213
styleUrls: ['./terminal.component.scss']
1314
})
14-
export class TerminalComponent extends WindowDelegate
15+
export class TerminalComponent extends WindowComponent
1516
implements OnInit, TerminalAPI {
1617
@ViewChild('history', { static: true }) history: ElementRef;
1718
@ViewChild('prompt', { static: true }) prompt: ElementRef;
1819
@ViewChild('cmdLine', { static: true }) cmdLine: ElementRef;
1920

20-
title = 'Terminal';
21-
icon = 'assets/desktop/img/terminal.svg';
22-
type: Type<any> = TerminalComponent;
23-
2421
currentState: TerminalState[] = [];
2522
promptHtml: SafeHtml;
2623

@@ -146,11 +143,17 @@ export class TerminalComponent extends WindowDelegate
146143
}
147144

148145
closeTerminal() {
149-
this.windowManager.closeWindow(this);
146+
this.windowManager.closeWindow(this.delegate);
150147
}
151148

152149
clear() {
153150
this.history.nativeElement.value = '';
154151
}
155152

156153
}
154+
155+
export class TerminalWindowDelegate extends WindowDelegate {
156+
title = 'Terminal';
157+
icon = 'assets/desktop/img/terminal.svg';
158+
type: Type<any> = TerminalComponent;
159+
}
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { Component, OnInit, Type } from '@angular/core';
2-
import { WindowDelegate } from '../../window/window-delegate';
2+
import { WindowComponent, WindowDelegate } from '../../window/window-delegate';
33

4+
// noinspection AngularMissingOrInvalidDeclarationInModule
45
@Component({
56
selector: 'app-test-window',
67
templateUrl: './test-window.component.html',
78
styleUrls: ['./test-window.component.scss']
89
})
9-
export class TestWindowComponent extends WindowDelegate implements OnInit {
10-
11-
title = 'Testfenster';
12-
icon = 'assets/desktop/img/filemanager.svg';
13-
type: Type<any> = TestWindowComponent;
10+
export class TestWindowComponent extends WindowComponent implements OnInit {
1411

1512
constructor() {
1613
super();
@@ -20,3 +17,9 @@ export class TestWindowComponent extends WindowDelegate implements OnInit {
2017
}
2118

2219
}
20+
21+
export class TestWindowDelegate extends WindowDelegate {
22+
title = 'Testfenster';
23+
icon = 'assets/desktop/img/filemanager.svg';
24+
type: Type<any> = TestWindowComponent;
25+
}

src/assets/desktop/definition.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Program } from '../../dataclasses/program';
22
import { Position } from '../../dataclasses/position';
3-
import { TestWindowComponent } from '../../app/desktop/windows/test-window/test-window.component';
4-
import { TerminalComponent } from '../../app/desktop/windows/terminal/terminal.component';
3+
import { TestWindowDelegate } from '../../app/desktop/windows/test-window/test-window.component';
4+
import { TerminalWindowDelegate } from '../../app/desktop/windows/terminal/terminal.component';
55

66
export const programWindows = {
7-
'browser': TestWindowComponent,
8-
'fileManager': TestWindowComponent,
9-
'terminal': TerminalComponent
7+
'browser': TestWindowDelegate,
8+
'fileManager': TestWindowDelegate,
9+
'terminal': TerminalWindowDelegate
1010
};
1111

1212
export const desktopDefinition = {

0 commit comments

Comments
 (0)