2024-07-01 03:51:25 +00:00
|
|
|
import {AdapterState, AdapterData} from "./adapter";
|
|
|
|
import {Message, Attachment, Author} from "./message"
|
2024-06-29 17:04:08 +00:00
|
|
|
import util from "./util"
|
2024-07-01 03:51:25 +00:00
|
|
|
import { TabBarElement } from "./tabbar-element"
|
|
|
|
import { MessageElement } from "./message-element"
|
|
|
|
import { SettingsElement } from "./settings-element"
|
2024-07-05 01:27:29 +00:00
|
|
|
import { AdapterElement } from "./adapter-element"
|
|
|
|
import { ThreadSummaryElement } from "./thread-summary-element"
|
2024-04-22 00:02:44 +00:00
|
|
|
|
2024-06-29 17:04:08 +00:00
|
|
|
var $ = util.$
|
|
|
|
var _ = util._
|
2024-04-22 00:32:14 +00:00
|
|
|
|
2024-07-01 03:51:25 +00:00
|
|
|
function main() {
|
2024-04-27 22:39:53 +00:00
|
|
|
const settings = _("settings", JSON.parse(localStorage.getItem("settings") ?? "{}"));
|
2024-04-27 16:50:27 +00:00
|
|
|
|
2024-07-01 03:51:25 +00:00
|
|
|
customElements.define("underbbs-tabbar", TabBarElement);
|
|
|
|
customElements.define("underbbs-message", MessageElement);
|
|
|
|
customElements.define("underbbs-settings", SettingsElement);
|
2024-07-05 01:27:29 +00:00
|
|
|
customElements.define("underbbs-adapter", AdapterElement);
|
|
|
|
customElements.define("underbbs-thread-summary", ThreadSummaryElement);
|
2024-07-01 03:51:25 +00:00
|
|
|
|
|
|
|
tabbarInit(settings.adapters?.map((a:any)=>a.nickname) ?? []);
|
|
|
|
|
2024-05-13 00:26:44 +00:00
|
|
|
registerServiceWorker();
|
2024-07-01 03:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function tabbarInit(adapters: string[]) {
|
|
|
|
const nav = $("tabbar_injectparent");
|
|
|
|
if (nav) {
|
|
|
|
nav.innerHTML = `<underbbs-tabbar data-adapters="${adapters.join(",")}" data-currentadapter=""></underbbs-tabbar>`;
|
|
|
|
}
|
|
|
|
}
|
2024-04-22 00:02:44 +00:00
|
|
|
|
2024-05-13 00:26:44 +00:00
|
|
|
async function registerServiceWorker() {
|
|
|
|
if ("serviceWorker" in navigator) {
|
|
|
|
try {
|
|
|
|
const registration = await navigator.serviceWorker.register("/serviceWorker.js", {
|
|
|
|
scope: "/",
|
|
|
|
});
|
|
|
|
if (registration.installing) {
|
|
|
|
console.log("Service worker installing");
|
|
|
|
} else if (registration.waiting) {
|
|
|
|
console.log("Service worker installed");
|
|
|
|
} else if (registration.active) {
|
|
|
|
console.log("Service worker active");
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error(`Registration failed with ${error}`);
|
|
|
|
}
|
|
|
|
const registration = await navigator.serviceWorker.ready;
|
|
|
|
(registration as any).sync.register("testdata").then((r:any)=>{console.log("but i will see this!")});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-27 16:50:27 +00:00
|
|
|
main();
|