diff --git a/.idea/.idea.WebDesktop 2.0/.idea/dataSources.local.xml b/.idea/.idea.WebDesktop 2.0/.idea/dataSources.local.xml index 646bf29..0505125 100644 --- a/.idea/.idea.WebDesktop 2.0/.idea/dataSources.local.xml +++ b/.idea/.idea.WebDesktop 2.0/.idea/dataSources.local.xml @@ -1,6 +1,6 @@ - + #@ diff --git a/.idea/.idea.WebDesktop 2.0/.idea/workspace.xml b/.idea/.idea.WebDesktop 2.0/.idea/workspace.xml index 4616a18..ac99de0 100644 --- a/.idea/.idea.WebDesktop 2.0/.idea/workspace.xml +++ b/.idea/.idea.WebDesktop 2.0/.idea/workspace.xml @@ -6,23 +6,12 @@ - + + - - - - - - - - - - - - @@ -206,6 +204,7 @@ - \ No newline at end of file diff --git a/Frontend/src/app/components/window-wrapper/window-wrapper.component.ts b/Frontend/src/app/components/window-wrapper/window-wrapper.component.ts index 48f3cc1..68718d9 100644 --- a/Frontend/src/app/components/window-wrapper/window-wrapper.component.ts +++ b/Frontend/src/app/components/window-wrapper/window-wrapper.component.ts @@ -4,6 +4,19 @@ import {TaskbarIcon} from "../../sites/desktop/taskbar-icon/taskbar-icon.compone import {Package} from "webdesktop_windowapi/dist/helper/Package"; import {WindowEvent} from "webdesktop_windowapi/dist/helper/EventData"; +class StaticPromise { + public readonly innerPromise: Promise; + public reject: (reason?: any) => void; + public resolve: (value: (T | PromiseLike)) => void; + + public constructor() { + this.innerPromise = new Promise((resolve1, reject1) => { + this.reject = reject1; + this.resolve = resolve1; + }); + } +} + @Component({ selector: 'app-window-wrapper', templateUrl: './window-wrapper.component.html', @@ -24,6 +37,7 @@ export class WindowWrapper { public resizable: boolean = true; public asPopup: boolean; public args: string[]; + public globalAwait: StaticPromise; public resizeIcon: string = "fullscreen"; public maximized: boolean = false; @@ -36,7 +50,8 @@ export class WindowWrapper { window.addEventListener('message', this.messageHandler); } - public initialize(taskbar: TaskbarIcon, args: string[], asPopup: boolean) { + public initialize(taskbar: TaskbarIcon, args: string[], asPopup: boolean): Promise { + this.globalAwait = new StaticPromise(); this.title = this.program.name; this.args = args; this.asPopup = asPopup; @@ -45,6 +60,7 @@ export class WindowWrapper { this.taskbar = taskbar; this.content.nativeElement.src = this.program.handlerUrl; this.focus(); + return this.globalAwait.innerPromise; } public close() { @@ -122,6 +138,7 @@ export class WindowWrapper { } public applyContentListeners(content: HTMLIFrameElement) { + // TODO: Handle inFrame events /*content.contentWindow.addEventListener('mousemove', this.onMove.bind(this)); content.contentWindow.addEventListener('mousedown', this.focus.bind(this)); content.contentWindow.addEventListener('mouseup', this.resizeHandler?.windowResizeStop.bind(this.resizeHandler));*/ @@ -132,6 +149,8 @@ export class WindowWrapper { this.dispatchEvent({type: "openAsPopup", data: this.args}); else this.dispatchEvent({type: "open", data: this.args}); + + this.globalAwait.resolve(); } public onMove(event: MouseEvent) { @@ -139,7 +158,7 @@ export class WindowWrapper { this.resizeHandler?.windowResize(event); } - private onMessage(event: MessageEvent) { + private async onMessage(event: MessageEvent) { const iframe = this.content.nativeElement as HTMLIFrameElement; if (event.source != iframe.contentWindow) return; @@ -152,9 +171,9 @@ export class WindowWrapper { this.handleSet(data); } else if (data.method == 'action') { - const pkg: Package = {method: "action", content: this.handleAction(data)}; + const pkg: Package = {method: "action", content: await this.handleAction(data)}; - if (data.action != 'closeSelf' && (data.action == 'closeWindow' && data.content.uuid == this.uuid)) + if (data.action != 'closeSelf' && (data.action == 'closeWindow' && data.content.uuid != this.uuid)) iframe.contentWindow.postMessage(pkg, event.origin); } } @@ -232,7 +251,7 @@ export class WindowWrapper { } } - private handleAction(data: Package): any { + private async handleAction(data: Package): Promise { switch (data.action) { case "openWindow": return DesktopComponent.instance.openProgram(data.content.identifier, data.content.args, data.content.asPopup); diff --git a/Frontend/src/app/sites/desktop/desktop.component.ts b/Frontend/src/app/sites/desktop/desktop.component.ts index b89a288..65943cb 100644 --- a/Frontend/src/app/sites/desktop/desktop.component.ts +++ b/Frontend/src/app/sites/desktop/desktop.component.ts @@ -61,7 +61,7 @@ export class DesktopComponent implements OnInit { }); } - public openProgram(programUUID: string, args?: string[], asPopup?: boolean): number { + public openProgram(programUUID: string, args?: string[], asPopup?: boolean): Promise { const program = programs[programUUID]; const exists = this.getTaskbarIcon(programUUID) != undefined; diff --git a/Frontend/src/app/sites/desktop/taskbar-icon/taskbar-icon.component.ts b/Frontend/src/app/sites/desktop/taskbar-icon/taskbar-icon.component.ts index bca0016..2d061e6 100644 --- a/Frontend/src/app/sites/desktop/taskbar-icon/taskbar-icon.component.ts +++ b/Frontend/src/app/sites/desktop/taskbar-icon/taskbar-icon.component.ts @@ -21,22 +21,22 @@ export class TaskbarIcon { this.type = type; } - public openProgram(args?: string[], asPopup: boolean = false): number { + public async openProgram(args?: string[], asPopup: boolean = false): Promise { const window = DesktopComponent.windowContainer.createComponent(WindowWrapper); window.instance.program = this.type.program; DesktopComponent.instance.cdr.detectChanges(); - window.instance.initialize(this, args || [], asPopup); + await window.instance.initialize(this, args || [], asPopup); this.windows.push(window.instance); this.setIndicator('wide'); return window.instance.uuid; } - public onTaskbarClick(event: MouseEvent) { + public async onTaskbarClick(event: MouseEvent) { if (this.instancesOpen) return; if (this.windows.length == 0 || event.shiftKey) { - this.openProgram(); + await this.openProgram(); return; } diff --git a/global.json b/global.json new file mode 100644 index 0000000..9e5e1fd --- /dev/null +++ b/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "6.0.0", + "rollForward": "latestMajor", + "allowPrerelease": true + } +} \ No newline at end of file