Skip to content

Commit 1774fc4

Browse files
committed
(#5) Added window API and Window class
1 parent 5eb3c05 commit 1774fc4

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

lib/window-api.interface.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* {@link WindowApi} provides helper functions to handle windows
3+
*/
4+
import { Window } from "./window.class";
5+
6+
export interface WindowApi {
7+
windows(): Promise<Window[]>;
8+
activeWindow(): Promise<Window>;
9+
}

lib/window.class.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { NativeAdapter } from "./adapter/native.adapter.class";
2+
import { Region } from "./region.class";
3+
4+
export class Window {
5+
constructor(private nativeActions: NativeAdapter, private windowHandle: number) {
6+
}
7+
8+
get title(): Promise<string> {
9+
return this.nativeActions.getWindowTitle(this.windowHandle);
10+
}
11+
12+
get region(): Promise<Region> {
13+
return this.nativeActions.getWindowRegion(this.windowHandle);
14+
}
15+
}

lib/window.function.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { WindowApi } from "./window-api.interface";
2+
import { NativeAdapter } from "./adapter/native.adapter.class";
3+
import { Window } from "./window.class";
4+
5+
export const createWindowApi = (nativeAdapter: NativeAdapter): WindowApi => {
6+
return ({
7+
async activeWindow(): Promise<Window> {
8+
const windowHandle = await nativeAdapter.getActiveWindow();
9+
return new Window(nativeAdapter, windowHandle);
10+
},
11+
async windows(): Promise<Window[]> {
12+
const windowHandles = await nativeAdapter.getWindows();
13+
return windowHandles.map((handle: number) => {
14+
return new Window(nativeAdapter, handle);
15+
});
16+
},
17+
});
18+
};

0 commit comments

Comments
 (0)