mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-08-28 17:21:05 +00:00
chore: merge main and release 3.7.3 bugfix bundle
Resolve conflicts with deep-reform (PR #452) while keeping bugfix branch changes: sidebar visibility, verbose logging, device login name, and notification archive. Bump to 3.7.3 with What's New release notes. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -18,6 +18,26 @@ import { LUCIDE_MOON_ICON_SVG } from "@/lib/icons/lucideMoon";
|
||||
import { LUCIDE_SUN_ICON_SVG } from "@/lib/icons/lucideSun";
|
||||
|
||||
let cachedUserInfo: any = null;
|
||||
let userInfoFetchPromise: Promise<any> | null = null;
|
||||
let userInfoCacheListenersAttached = false;
|
||||
|
||||
export function invalidateCachedUserInfo(): void {
|
||||
cachedUserInfo = null;
|
||||
userInfoFetchPromise = null;
|
||||
}
|
||||
|
||||
function attachUserInfoCacheInvalidation(): void {
|
||||
if (userInfoCacheListenersAttached || typeof window === "undefined") return;
|
||||
userInfoCacheListenersAttached = true;
|
||||
|
||||
window.addEventListener("pageshow", (event) => {
|
||||
if (event.persisted) {
|
||||
invalidateCachedUserInfo();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
attachUserInfoCacheInvalidation();
|
||||
|
||||
let LightDarkModeSnakeEggButton = 0;
|
||||
let sidebarAccessibilityObserver: MutationObserver | null = null;
|
||||
@@ -27,28 +47,66 @@ let sidebarAccessibilityListenersAttached = false;
|
||||
/** Marks menu rows that are off-screen in the drill stack (CSS blocks clicks). */
|
||||
const BSPLUS_SIDEBAR_OFFSCREEN = "bsplus-sidebar-offscreen";
|
||||
|
||||
export async function getUserInfo() {
|
||||
if (cachedUserInfo) return cachedUserInfo;
|
||||
|
||||
try {
|
||||
const response = await fetch(`${location.origin}/seqta/student/login`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
mode: "normal",
|
||||
query: null,
|
||||
redirect_url: location.origin,
|
||||
}),
|
||||
});
|
||||
|
||||
cachedUserInfo = (await response.json()).payload;
|
||||
export async function getUserInfo(options?: { validateSession?: boolean }) {
|
||||
if (cachedUserInfo && !options?.validateSession) {
|
||||
return cachedUserInfo;
|
||||
} catch (error) {
|
||||
console.error("[BetterSEQTA+] Failed to get user info:", error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (userInfoFetchPromise && !options?.validateSession) {
|
||||
return userInfoFetchPromise;
|
||||
}
|
||||
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const response = await fetch(`${location.origin}/seqta/student/login`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
mode: "normal",
|
||||
query: null,
|
||||
redirect_url: location.origin,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to get user info: HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
const payload = (await response.json()).payload;
|
||||
|
||||
if (
|
||||
cachedUserInfo &&
|
||||
options?.validateSession &&
|
||||
payload?.id != null &&
|
||||
cachedUserInfo.id != null &&
|
||||
payload.id !== cachedUserInfo.id
|
||||
) {
|
||||
console.warn(
|
||||
"[BetterSEQTA+] Session user changed; invalidating cached user info",
|
||||
);
|
||||
invalidateCachedUserInfo();
|
||||
}
|
||||
|
||||
cachedUserInfo = payload;
|
||||
return cachedUserInfo;
|
||||
} catch (error) {
|
||||
console.error("[BetterSEQTA+] Failed to get user info:", error);
|
||||
throw error;
|
||||
} finally {
|
||||
if (!options?.validateSession) {
|
||||
userInfoFetchPromise = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (options?.validateSession) {
|
||||
return fetchUserInfo();
|
||||
}
|
||||
|
||||
userInfoFetchPromise = fetchUserInfo();
|
||||
return userInfoFetchPromise;
|
||||
}
|
||||
|
||||
export async function AddBetterSEQTAElements() {
|
||||
@@ -78,11 +136,7 @@ export async function AddBetterSEQTAElements() {
|
||||
menuList.insertBefore(fragment, menuList.firstChild);
|
||||
|
||||
try {
|
||||
await Promise.all([
|
||||
appendBackgroundToUI(),
|
||||
handleUserInfo(),
|
||||
handleStudentData(),
|
||||
]);
|
||||
await Promise.all([appendBackgroundToUI(), handleUserInfoAndStudentData()]);
|
||||
} catch (error) {
|
||||
console.error("[BetterSEQTA+] Failed to initialize UI elements:", error);
|
||||
}
|
||||
@@ -112,11 +166,26 @@ function createHomeButton(fragment: DocumentFragment, _: HTMLElement) {
|
||||
);
|
||||
}
|
||||
|
||||
async function handleUserInfo() {
|
||||
async function handleUserInfoAndStudentData() {
|
||||
try {
|
||||
updateUserInfo(await getUserInfo());
|
||||
const [userInfo, studentResponse] = await Promise.all([
|
||||
getUserInfo(),
|
||||
fetch(`${location.origin}/seqta/student/load/message/people`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
},
|
||||
body: JSON.stringify({ mode: "student" }),
|
||||
}),
|
||||
]);
|
||||
|
||||
updateUserInfo(userInfo);
|
||||
await updateStudentInfo((await studentResponse.json()).payload, userInfo);
|
||||
} catch (error) {
|
||||
console.error("[BetterSEQTA+] Failed to handle user info:", error);
|
||||
console.error(
|
||||
"[BetterSEQTA+] Failed to handle user info and student data:",
|
||||
error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,27 +241,7 @@ function updateUserInfo(info: {
|
||||
.appendChild(document.getElementsByClassName("logout")[0]);
|
||||
}
|
||||
|
||||
async function handleStudentData() {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${location.origin}/seqta/student/load/message/people`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
},
|
||||
body: JSON.stringify({ mode: "student" }),
|
||||
},
|
||||
);
|
||||
|
||||
await updateStudentInfo((await response.json()).payload);
|
||||
} catch (error) {
|
||||
console.error("[BetterSEQTA+] Failed to handle student data:", error);
|
||||
}
|
||||
}
|
||||
|
||||
async function updateStudentInfo(students: any) {
|
||||
const info = await getUserInfo();
|
||||
async function updateStudentInfo(students: any, info: Awaited<ReturnType<typeof getUserInfo>>) {
|
||||
const index = students.findIndex(
|
||||
(person: any) =>
|
||||
person.firstname == info.userDesc.split(" ")[0] &&
|
||||
|
||||
@@ -21,6 +21,7 @@ export async function appendBackgroundToUI() {
|
||||
}
|
||||
|
||||
let lastLoadedId: string | null = null;
|
||||
let lastBlobUrl: string | null = null;
|
||||
|
||||
export async function loadBackground() {
|
||||
if (!isIndexedDBSupported()) {
|
||||
@@ -36,6 +37,10 @@ export async function loadBackground() {
|
||||
backgroundContainer.remove();
|
||||
}
|
||||
lastLoadedId = null;
|
||||
if (lastBlobUrl) {
|
||||
URL.revokeObjectURL(lastBlobUrl);
|
||||
lastBlobUrl = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -73,12 +78,19 @@ export async function loadBackground() {
|
||||
|
||||
mediaContainer.innerHTML = "";
|
||||
|
||||
if (lastBlobUrl) {
|
||||
URL.revokeObjectURL(lastBlobUrl);
|
||||
lastBlobUrl = null;
|
||||
}
|
||||
|
||||
const mediaElement =
|
||||
background.type === "video"
|
||||
? document.createElement("video")
|
||||
: document.createElement("img");
|
||||
|
||||
mediaElement.src = URL.createObjectURL(background.blob);
|
||||
const blobUrl = URL.createObjectURL(background.blob);
|
||||
lastBlobUrl = blobUrl;
|
||||
mediaElement.src = blobUrl;
|
||||
mediaElement.classList.add("background");
|
||||
|
||||
if (mediaElement instanceof HTMLVideoElement) {
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
import renderSvelte from "@/interface/main";
|
||||
import Store from "@/interface/pages/store.svelte";
|
||||
|
||||
import { unmount } from "svelte";
|
||||
|
||||
let remove: () => void;
|
||||
|
||||
export function OpenStorePage() {
|
||||
remove = renderStore();
|
||||
export async function OpenStorePage(): Promise<void> {
|
||||
remove = await renderStore();
|
||||
}
|
||||
|
||||
export function renderStore() {
|
||||
export async function renderStore() {
|
||||
const [{ default: renderSvelte }, { default: Store }] = await Promise.all([
|
||||
import("@/interface/main"),
|
||||
import("@/interface/pages/store.svelte"),
|
||||
]);
|
||||
|
||||
const container = document.querySelector("#container");
|
||||
if (!container) {
|
||||
throw new Error("Container not found");
|
||||
}
|
||||
|
||||
// Avoid stacking multiple store roots if opened repeatedly without close.
|
||||
document.getElementById("store")?.remove();
|
||||
|
||||
const child = document.createElement("div");
|
||||
child.id = "store";
|
||||
container!.appendChild(child);
|
||||
container.appendChild(child);
|
||||
|
||||
const shadow = child.attachShadow({ mode: "open" });
|
||||
const app = renderSvelte(Store, shadow);
|
||||
|
||||
Reference in New Issue
Block a user