TeaWeb/shared/popup/certaccept/js/main.ts

41 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-08-31 18:31:01 +02:00
function tr(text: string) { return text; }
2019-09-01 17:24:06 +02:00
loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, {
2019-08-31 18:31:01 +02:00
name: "certificate accept tester",
function: async () => {
const certificate_accept = settings.static_global(Settings.KEY_CERTIFICATE_CALLBACK, undefined);
2019-09-01 17:24:06 +02:00
const container_success = $("#container-success").hide();
2019-08-31 18:31:01 +02:00
if(!certificate_accept) {
2019-09-01 17:24:06 +02:00
loader.critical_error(tr("Missing certificate callback data"), tr("Please reconnect manually."));
2019-08-31 18:31:01 +02:00
throw "missing data";
}
log.info(LogCategory.IPC, tr("Using this instance as certificate callback. ID: %s"), certificate_accept);
try {
2019-09-01 17:24:06 +02:00
await bipc.get_handler().post_certificate_accpected(certificate_accept);
2019-08-31 18:31:01 +02:00
log.info(LogCategory.IPC, tr("Other instance has acknowledged out work. Closing this window."));
let seconds = 5;
let interval_id;
interval_id = setInterval(() => {
seconds--;
2019-09-01 17:24:06 +02:00
$("#time-left").text(seconds.toString());
2019-08-31 18:31:01 +02:00
if(seconds <= 0) {
clearTimeout(interval_id);
log.info(LogCategory.GENERAL, tr("Closing window"));
window.close();
return;
}
}, 1000);
2019-09-01 17:24:06 +02:00
container_success.show();
2019-08-31 18:31:01 +02:00
} catch(error) {
log.warn(LogCategory.IPC, tr("Failed to successfully post certificate accept status: %o"), error);
2019-09-01 17:24:06 +02:00
loader.critical_error(tr("Failed to emit success!"), tr("Please reconnect manually."));
2019-08-31 18:31:01 +02:00
}
},
priority: 10
2019-09-01 17:24:06 +02:00
});