Add Progress dialog

master
Kuba Orlik 4 years ago
parent 8bb828191d
commit 2bc172043a

@ -81,6 +81,7 @@ export default class Dialog extends EventEmitter {
process: ChildProcessWithoutNullStreams; process: ChildProcessWithoutNullStreams;
output: string = ""; output: string = "";
error: string = ""; error: string = "";
killing = false;
constructor( constructor(
public type_option: string, public type_option: string,
public args: DialogOptions, public args: DialogOptions,
@ -170,7 +171,7 @@ export default class Dialog extends EventEmitter {
if (code !== 0) { if (code !== 0) {
if (!spawned) { if (!spawned) {
reject({ code, message: this.error }); reject({ code, message: this.error });
} else { } else if (!this.killing) {
this.emit("error", code); this.emit("error", code);
} }
} else { } else {
@ -190,4 +191,9 @@ export default class Dialog extends EventEmitter {
}); });
}); });
} }
hide() {
this.killing = true;
return this.process.kill();
}
} }

@ -6,4 +6,5 @@ export {
ItemsSelectedResponse, ItemsSelectedResponse,
} from "./list"; } from "./list";
export { default as Entry } from "./entry"; export { default as Entry } from "./entry";
export { default as Progress } from "./progress";
export { default as TextInfo } from "./text-info"; export { default as TextInfo } from "./text-info";

@ -0,0 +1,26 @@
import Dialog, { DialogOptions } from "./dialog";
type ProgressOptions = Partial<{ text: string; pulsate: true; noCancel: true }>;
export default class Progress {
private dialog: Dialog;
async show(options: ProgressOptions): Promise<void> {
this.dialog = new Dialog("progress", Progress.prepareOptions(options));
await this.dialog.show();
}
static prepareOptions(options: ProgressOptions): DialogOptions {
const ret: DialogOptions = {};
if (typeof options.text === "string") {
ret.text = options.text;
}
ret.pulsate = options.pulsate;
ret["no-cancel"] = options.noCancel;
return ret;
}
async hide() {
return this.dialog.hide();
}
}
Loading…
Cancel
Save