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

68 lines
2.4 KiB
TypeScript
Raw Normal View History

2020-03-30 13:44:18 +02:00
import {settings, Settings} from "tc-shared/settings";
import * as loader from "tc-loader";
2020-03-31 01:27:59 +02:00
import * as log from "tc-shared/log";
2020-03-30 13:44:18 +02:00
import {LogCategory} from "tc-shared/log";
import * as bipc from "tc-shared/BrowserIPC";
2019-08-31 18:31:01 +02:00
2020-03-30 13:44:18 +02:00
const is_debug = false; //TODO: Sync with loader!
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
2020-03-30 13:44:18 +02:00
});
loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, {
name: "settings initialisation",
function: async () => Settings.initialize(),
priority: 200
});
loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, {
name: "bipc initialisation",
function: async () => bipc.setup(),
priority: 100
});
loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, {
name: "log enabled initialisation",
function: async () => log.initialize(is_debug ? log.LogType.TRACE : log.LogType.INFO),
priority: 150
2019-09-01 17:24:06 +02:00
});