feat: new default theme and background

This commit is contained in:
Jones Jankovic committed 2026-11-02 12:48:31 +10:30
1 parent 5cd471c1b3
commit a63e6c168e
11 files changed
+104 -16

No files matched your search

+2
View File
@@ -26,6 +26,7 @@ import {
refreshRemoteConfig,
} from "./background/remoteConfig";
import { BSPLUS_INSTALL_REGISTERED_AT_KEY } from "@/seqta/utils/remoteConfig/storageKeys";
import { DEFAULT_BACKGROUND_PENDING_KEY } from "@/seqta/ui/defaultBackground";
import { handleSearchThemeStockPhotos } from "./background/searchThemeStockPhotos";
import { bsplusApiQueryParams, withBsplusApiQuery } from "@/seqta/utils/bsplusClientContext";
import { initTimetableClassmatesBackgroundSync } from "./background/timetableClassmatesSync";
@@ -790,6 +791,7 @@ browser.runtime.onInstalled.addListener(function (event) {
if (event.reason === "install") {
void refreshRemoteConfig(apiBase);
void browser.storage.local.set({ [DEFAULT_BACKGROUND_PENDING_KEY]: true });
}
});
+1
View File
@@ -3,6 +3,7 @@ declare module "*.webm";
declare module "*.woff";
declare module "*.scss";
declare module "*.png";
declare module "*.webp";
declare module "*.html";
declare module "*.svelte";
@@ -37,6 +37,7 @@ const animatedBackgroundPlugin: Plugin<typeof settings> = {
description: "Adds an animated background to BetterSEQTA+",
version: "1.0.0",
disableToggle: true,
defaultEnabled: false,
styles: styles,
settings: instance.settings,
+3 -1
View File
@@ -553,7 +553,9 @@ export class PluginManager {
if (!plugin?.disableToggle) continue;
const enabled =
(change.newValue as PluginSettingsStorage)?.enabled ?? true;
(change.newValue as PluginSettingsStorage)?.enabled ??
plugin.defaultEnabled ??
true;
const wasEnabled =
(change.oldValue as PluginSettingsStorage)?.enabled ??
plugin.defaultEnabled ??
Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

+7 -1
View File
@@ -10,6 +10,7 @@ import { waitForElm } from "@/seqta/utils/waitForElm";
import { GetThresholdOfColor } from "@/seqta/ui/colors/getThresholdColour";
import { appendBackgroundToUI } from "./ImageBackgrounds";
import { applyDefaultBackgroundOnce } from "./defaultBackground";
import stringToHTML from "@/seqta/utils/stringToHTML";
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
import { updateAllColors } from "./colors/Manager";
@@ -155,7 +156,12 @@ export async function AddBetterSEQTAElements() {
menuList.insertBefore(fragment, menuList.firstChild);
try {
await Promise.all([appendBackgroundToUI(), handleUserInfoAndStudentData()]);
await Promise.all([
applyDefaultBackgroundOnce()
.catch((error) => console.warn("[BetterSEQTA+] Default background failed:", error))
.then(appendBackgroundToUI),
handleUserInfoAndStudentData(),
]);
} catch (error) {
console.error("[BetterSEQTA+] Failed to initialize UI elements:", error);
}
+51
View File
@@ -0,0 +1,51 @@
/**
* @jest-environment jsdom
*/
import browser from "webextension-polyfill";
import { writeData } from "@/interface/hooks/BackgroundDataLoader";
import {
applyDefaultBackgroundOnce,
DEFAULT_BACKGROUND_PENDING_KEY,
} from "./defaultBackground";
jest.mock("@/resources/backgrounds/default-background.webp", () => "default-background.webp", {
virtual: true,
});
jest.mock("@/lib/extensionAssetUrl", () => ({ resolveExtensionAssetUrl: (url: string) => url }));
jest.mock("@/interface/hooks/BackgroundDataLoader", () => ({ writeData: jest.fn() }));
const blob = { size: 1 };
beforeEach(() => {
localStorage.clear();
(writeData as jest.Mock).mockClear();
globalThis.fetch = jest.fn(async () => ({ blob: async () => blob })) as unknown as typeof fetch;
});
it("does nothing without the fresh-install flag", async () => {
await applyDefaultBackgroundOnce();
expect(writeData).not.toHaveBeenCalled();
expect(localStorage.getItem("selectedBackground")).toBeNull();
});
it("installs and selects the bundled background on a fresh install", async () => {
await browser.storage.local.set({ [DEFAULT_BACKGROUND_PENDING_KEY]: true });
await applyDefaultBackgroundOnce();
expect(writeData).toHaveBeenCalledWith("image-116", "image", blob);
expect(localStorage.getItem("selectedBackground")).toBe("image-116");
expect(await browser.storage.local.get(DEFAULT_BACKGROUND_PENDING_KEY)).toEqual({});
});
it("keeps a background the user already chose", async () => {
await browser.storage.local.set({ [DEFAULT_BACKGROUND_PENDING_KEY]: true });
localStorage.setItem("selectedBackground", "");
await applyDefaultBackgroundOnce();
expect(writeData).not.toHaveBeenCalled();
expect(localStorage.getItem("selectedBackground")).toBe("");
expect(await browser.storage.local.get(DEFAULT_BACKGROUND_PENDING_KEY)).toEqual({});
});
+24
View File
@@ -0,0 +1,24 @@
import browser from "webextension-polyfill";
import defaultBackgroundUrl from "@/resources/backgrounds/default-background.webp";
import { resolveExtensionAssetUrl } from "@/lib/extensionAssetUrl";
import { writeData } from "@/interface/hooks/BackgroundDataLoader";
/** Set by the background script on a fresh install; consumed on the first SEQTA page load. */
export const DEFAULT_BACKGROUND_PENDING_KEY = "defaultBackgroundPending";
/** Theme store id of the bundled image, so the store lists it as installed. */
const DEFAULT_BACKGROUND_ID = "image-116";
/** Install and select the bundled background once, unless the user already picked one. */
export async function applyDefaultBackgroundOnce(): Promise<void> {
const stored = await browser.storage.local.get(DEFAULT_BACKGROUND_PENDING_KEY);
if (!stored[DEFAULT_BACKGROUND_PENDING_KEY]) return;
if (localStorage.getItem("selectedBackground") === null) {
const response = await fetch(resolveExtensionAssetUrl(defaultBackgroundUrl));
await writeData(DEFAULT_BACKGROUND_ID, "image", await response.blob());
localStorage.setItem("selectedBackground", DEFAULT_BACKGROUND_ID);
}
await browser.storage.local.remove(DEFAULT_BACKGROUND_PENDING_KEY);
}
+9 -9
View File
@@ -1,4 +1,4 @@
export const DEFAULT_FONT_ID = "rubik";
export const DEFAULT_FONT_ID = "inter";
export interface FontPreset {
id: string;
@@ -9,14 +9,6 @@ export interface FontPreset {
}
export const FONT_PRESETS: FontPreset[] = [
{
id: "rubik",
name: "Rubik",
stack: "Rubik, sans-serif",
googleUrl:
"https://fonts.googleapis.com/css2?family=Rubik:wght@400;500;600;700&display=swap",
sample: "Assessment due tomorrow at 3:30pm",
},
{
id: "inter",
name: "Inter",
@@ -25,6 +17,14 @@ export const FONT_PRESETS: FontPreset[] = [
"https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap",
sample: "Assessment due tomorrow at 3:30pm",
},
{
id: "rubik",
name: "Rubik",
stack: "Rubik, sans-serif",
googleUrl:
"https://fonts.googleapis.com/css2?family=Rubik:wght@400;500;600;700&display=swap",
sample: "Assessment due tomorrow at 3:30pm",
},
{
id: "poppins",
name: "Poppins",
+5 -4
View File
@@ -1,4 +1,5 @@
import type { SettingsState } from "@/types/storage";
import { DEFAULT_FONT_ID } from "@/seqta/ui/fonts/presets";
function detectLowEndDevice(): boolean {
const lowCoreCount =
@@ -17,9 +18,9 @@ export function getDefaultSettingsState(): SettingsState {
return {
onoff: true,
settingsPopupExpanded: false,
animatedbk: true,
animatedbk: false,
bksliderinput: "50",
transparencyEffects: false,
transparencyEffects: true,
lessonalert: true,
defaultmenuorder: [],
menuitems: {
@@ -45,7 +46,7 @@ export function getDefaultSettingsState(): SettingsState {
subjectfilters: {},
selectedTheme: "",
selectedColor:
"linear-gradient(40deg, rgba(201,61,0,1) 0%, RGBA(170, 5, 58, 1) 100%)",
"linear-gradient(45deg, rgba(18,106,98,1) 0%, rgba(17,88,131,1) 100%)",
originalSelectedColor: "",
DarkMode: true,
animations: !isLowEndDevice,
@@ -79,7 +80,7 @@ export function getDefaultSettingsState(): SettingsState {
themeOfTheMonthDisabled: false,
autoCloudSettingsSync: true,
showTitlebarFounderBadge: true,
selectedFont: "rubik",
selectedFont: DEFAULT_FONT_ID,
timeFormat: "24",
privacyStatementShown: false,
bsCloudAutoSyncAnnouncementShown: false,
+1 -1
View File
@@ -95,7 +95,7 @@ export interface SettingsState {
adaptiveThemeColour?: boolean;
adaptiveThemeGradient?: boolean;
adaptiveThemeColourTransition?: boolean;
/** Google Font preset id for SEQTA interface typography (`rubik` default). */
/** Google Font preset id for SEQTA interface typography (`inter` default). */
selectedFont?: string;
// depreciated keys