-
Notifications
You must be signed in to change notification settings - Fork 1
/
WindowName.js
38 lines (34 loc) · 1.11 KB
/
WindowName.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const XDoToolBase = require( "./BaseClass.js" );
function sleep( ms ) { return new Promise( function( resolve ) { setTimeout( resolve , ms ) } ); }
class WindowName extends XDoToolBase {
constructor( windowName ) {
super();
this.windowName = windowName;
super.windowGeometry();
}
windowIDFromName() {
//let x1 = this.exec( "xdotool search --name '" + this.windowName + "'" );
let x1 = this.exec( "xdotool search --desktop 0 --name '" + this.windowName + "'" );
if ( x1 ) { x1 = x1.split( "\n" ); x1 = x1[ 0 ]; }
this.windowID = x1;
return x1;
}
searchID() {
let xFoundID = this.windowIDFromName();
if ( xFoundID !== null ) { if ( xFoundID.length > 1 ) { return true; } }
return false;
}
ensureWindowNameIsReady() {
let that = this;
return new Promise( async function( resolve , reject ) {
try {
let xFound = false;
while( !xFound ) { xFound = that.searchID(); await sleep( 1000 ); }
console.log( "XDoTool-Wrapper --> X-Window READY !!! " + that.windowID );
resolve();
}
catch( error ) { console.log( error ); reject( error ); }
});
}
}
module.exports = WindowName;