|
|
@ -9,17 +9,24 @@ export type DialogOptions = Record<
|
|
|
|
true | string | undefined | string[]
|
|
|
|
true | string | undefined | string[]
|
|
|
|
>; // array value means use this flag this many times
|
|
|
|
>; // array value means use this flag this many times
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Geometry = { x: number; y: number; width: number; height: number };
|
|
|
|
|
|
|
|
|
|
|
|
let last_position: { x: number; y: number } | null = null;
|
|
|
|
let last_position: { x: number; y: number } | null = null;
|
|
|
|
|
|
|
|
|
|
|
|
async function get_geometry() {
|
|
|
|
async function get_geometry(): Promise<Geometry | null> {
|
|
|
|
const result = (await simpleSpawn("bash", [
|
|
|
|
const result = (await simpleSpawn("bash", [
|
|
|
|
"-c",
|
|
|
|
"-c",
|
|
|
|
'wmctrl -l -x node-zenity -G | grep node-zenity | awk \'{print $3 " " $4 " " $5 " " $6}\'',
|
|
|
|
'wmctrl -l -x node-zenity -G | grep node-zenity | awk \'{print $3 " " $4 " " $5 " " $6}\'',
|
|
|
|
])) as string;
|
|
|
|
])) as string;
|
|
|
|
|
|
|
|
console.log(result);
|
|
|
|
const [x, y, width, height] = result
|
|
|
|
const [x, y, width, height] = result
|
|
|
|
.split("\n")[0]
|
|
|
|
.split("\n")[0]
|
|
|
|
.split(" ")
|
|
|
|
.split(" ")
|
|
|
|
.map((s) => parseInt(s));
|
|
|
|
.map((s) => parseInt(s));
|
|
|
|
|
|
|
|
console.log("getgeometry", result, { x, y, width, height });
|
|
|
|
|
|
|
|
if (!height) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
return { x, y, width, height };
|
|
|
|
return { x, y, width, height };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -40,7 +47,7 @@ async function set_geometry({
|
|
|
|
if (height === undefined) {
|
|
|
|
if (height === undefined) {
|
|
|
|
height = -1;
|
|
|
|
height = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await simpleSpawn("wmctrl", [
|
|
|
|
const args = [
|
|
|
|
"-x",
|
|
|
|
"-x",
|
|
|
|
"-a",
|
|
|
|
"-a",
|
|
|
|
"node-zenity",
|
|
|
|
"node-zenity",
|
|
|
@ -48,15 +55,28 @@ async function set_geometry({
|
|
|
|
`0,${Math.round(x)},${Math.round(y)},${Math.round(width)},${Math.round(
|
|
|
|
`0,${Math.round(x)},${Math.round(y)},${Math.round(width)},${Math.round(
|
|
|
|
height
|
|
|
|
height
|
|
|
|
)}`,
|
|
|
|
)}`,
|
|
|
|
]);
|
|
|
|
];
|
|
|
|
|
|
|
|
console.log(args);
|
|
|
|
|
|
|
|
await simpleSpawn("wmctrl", args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type DialogResponse = {
|
|
|
|
export type DialogResponse = {
|
|
|
|
code: number;
|
|
|
|
code: number;
|
|
|
|
output: string;
|
|
|
|
output: string;
|
|
|
|
error: string;
|
|
|
|
error: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setInterval(async () => {
|
|
|
|
|
|
|
|
const geometry = await get_geometry();
|
|
|
|
|
|
|
|
if (!geometry) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
last_position = {
|
|
|
|
|
|
|
|
x: Math.round(geometry.x + geometry.width / 2),
|
|
|
|
|
|
|
|
y: Math.round(geometry.y + geometry.height / 2),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
export default class Dialog extends EventEmitter {
|
|
|
|
export default class Dialog extends EventEmitter {
|
|
|
|
shown = false;
|
|
|
|
shown = false;
|
|
|
|
process: ChildProcessWithoutNullStreams;
|
|
|
|
process: ChildProcessWithoutNullStreams;
|
|
|
@ -83,7 +103,6 @@ export default class Dialog extends EventEmitter {
|
|
|
|
} else if (value === undefined) {
|
|
|
|
} else if (value === undefined) {
|
|
|
|
//void
|
|
|
|
//void
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
console.log("unknown value:", value);
|
|
|
|
|
|
|
|
throw new Error("uknown arg value type");
|
|
|
|
throw new Error("uknown arg value type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -98,17 +117,6 @@ export default class Dialog extends EventEmitter {
|
|
|
|
];
|
|
|
|
];
|
|
|
|
console.log("spawning process!", args.join(" "));
|
|
|
|
console.log("spawning process!", args.join(" "));
|
|
|
|
this.process = spawn("zenity", args);
|
|
|
|
this.process = spawn("zenity", args);
|
|
|
|
let position_listener_interval = setInterval(async () => {
|
|
|
|
|
|
|
|
const { x, y, width, height } = await get_geometry();
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
|
|
|
|
{ x, y, width, height },
|
|
|
|
|
|
|
|
{ x: Math.round(x + width / 2), y: Math.round(y + height / 2) }
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
last_position = {
|
|
|
|
|
|
|
|
x: Math.round(x + width / 2),
|
|
|
|
|
|
|
|
y: Math.round(y + height / 2),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let spawned = false;
|
|
|
|
let spawned = false;
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
@ -135,13 +143,13 @@ export default class Dialog extends EventEmitter {
|
|
|
|
]); // to activate it
|
|
|
|
]); // to activate it
|
|
|
|
if (last_position) {
|
|
|
|
if (last_position) {
|
|
|
|
const { width, height } = await get_geometry();
|
|
|
|
const { width, height } = await get_geometry();
|
|
|
|
|
|
|
|
console.log(last_position, width, height);
|
|
|
|
await set_geometry({
|
|
|
|
await set_geometry({
|
|
|
|
x: last_position.x - width / 2 - 11,
|
|
|
|
x: last_position.x - width / 2 - 11,
|
|
|
|
y: last_position.y - height / 2 - 82,
|
|
|
|
y: last_position.y - height / 2 - 82,
|
|
|
|
}); // to put it where it last was
|
|
|
|
}); // to put it where it last was
|
|
|
|
}
|
|
|
|
}
|
|
|
|
succeded = true;
|
|
|
|
succeded = true;
|
|
|
|
console.log("WMCTRL SUCCEEDED!");
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
@ -155,7 +163,6 @@ export default class Dialog extends EventEmitter {
|
|
|
|
this.error += chunk;
|
|
|
|
this.error += chunk;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.process.on("close", (code) => {
|
|
|
|
this.process.on("close", (code) => {
|
|
|
|
clearInterval(position_listener_interval);
|
|
|
|
|
|
|
|
console.log("process closed. output:", this.output);
|
|
|
|
console.log("process closed. output:", this.output);
|
|
|
|
if (code !== 0) {
|
|
|
|
if (code !== 0) {
|
|
|
|
if (!spawned) {
|
|
|
|
if (!spawned) {
|
|
|
|