mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
77 lines
2.3 KiB
TypeScript
77 lines
2.3 KiB
TypeScript
import { settingsState } from "../listeners/SettingsState";
|
|
import { OpenWhatsNewPopup } from "./OpenWhatsNewPopup";
|
|
import {
|
|
fetchThemeOfTheMonth,
|
|
OpenThemeOfTheMonthPopup,
|
|
shouldShowThemeOfTheMonth,
|
|
} from "./OpenThemeOfTheMonthPopup";
|
|
import { maybeQueueFeedbackReplyPopup } from "./OpenFeedbackReplyPopup";
|
|
import {
|
|
OpenCoursesAssessmentsFixPopup,
|
|
shouldShowCoursesAssessmentsFixPopup,
|
|
} from "./OpenCoursesAssessmentsFixPopup";
|
|
import { syncApiBaseToBackground } from "../DevApiBase";
|
|
import {
|
|
fetchTermsOfService,
|
|
openTermsOfServicePopup,
|
|
shouldShowTermsOfServicePopup,
|
|
} from "./OpenTermsOfServicePopup";
|
|
|
|
type QueueStep = (goNext: () => void) => void;
|
|
|
|
/**
|
|
* Runs startup modals in order: What's New (if the extension just updated),
|
|
* Courses/Assessments fix notice (only if features are off),
|
|
* Theme of the Month (when the user hasn't dismissed this calendar month),
|
|
* feedback reply notifications for pending submissions, then terms of service
|
|
* acceptance (always last).
|
|
*/
|
|
export async function runStartupPopupQueue() {
|
|
// Make sure the background script knows about any dev-mode API override
|
|
// before we start firing requests.
|
|
syncApiBaseToBackground();
|
|
|
|
const steps: QueueStep[] = [];
|
|
const afterWhatsNew = !!settingsState.justupdated;
|
|
|
|
if (afterWhatsNew) {
|
|
steps.push((goNext) => OpenWhatsNewPopup(goNext));
|
|
}
|
|
|
|
if (shouldShowCoursesAssessmentsFixPopup(settingsState)) {
|
|
steps.push((goNext) => OpenCoursesAssessmentsFixPopup(goNext));
|
|
}
|
|
|
|
// Fetch the Theme of the Month before queueing so we don't show an empty
|
|
// popup if the network or server is unavailable.
|
|
const themeOfTheMonth = await fetchThemeOfTheMonth();
|
|
if (shouldShowThemeOfTheMonth(themeOfTheMonth)) {
|
|
steps.push((goNext) => {
|
|
void OpenThemeOfTheMonthPopup(themeOfTheMonth!, goNext);
|
|
});
|
|
}
|
|
|
|
const feedbackReplyStep = await maybeQueueFeedbackReplyPopup();
|
|
if (feedbackReplyStep) {
|
|
steps.push(feedbackReplyStep);
|
|
}
|
|
|
|
steps.push((goNext) => {
|
|
void (async () => {
|
|
const termsDocument = await fetchTermsOfService();
|
|
if (!shouldShowTermsOfServicePopup(settingsState, termsDocument)) {
|
|
goNext();
|
|
return;
|
|
}
|
|
await openTermsOfServicePopup(goNext, { terms: termsDocument });
|
|
})();
|
|
});
|
|
|
|
function runNext() {
|
|
const step = steps.shift();
|
|
if (step) step(runNext);
|
|
}
|
|
|
|
runNext();
|
|
}
|