From 1df21551f679645c5ed1dfce91f4ca88638f80dc Mon Sep 17 00:00:00 2001 From: Aditya Chandel <8075870+adityachandelgit@users.noreply.github.com> Date: Mon, 15 Sep 2025 11:03:34 -0600 Subject: [PATCH] Rollback background blur and transparency due to high CPU/GPU usage (#1160) --- .../extractor/CbxMetadataExtractorTest.java | 30 ++++- booklore-ui/src/app/app.component.html | 17 +-- booklore-ui/src/app/app.component.scss | 22 ---- booklore-ui/src/app/app.component.ts | 22 ---- .../src/app/core/model/app-state.model.ts | 5 - .../app/core/service/app-config.service.ts | 114 +++--------------- .../theme-configurator.component.html | 61 ---------- .../theme-configurator.component.scss | 95 --------------- .../theme-configurator.component.ts | 100 +-------------- .../assets/layout/styles/layout/_topbar.scss | 5 +- 10 files changed, 49 insertions(+), 422 deletions(-) diff --git a/booklore-api/src/test/java/com/adityachandel/booklore/service/metadata/extractor/CbxMetadataExtractorTest.java b/booklore-api/src/test/java/com/adityachandel/booklore/service/metadata/extractor/CbxMetadataExtractorTest.java index 05e5cda22..f026b1a5d 100644 --- a/booklore-api/src/test/java/com/adityachandel/booklore/service/metadata/extractor/CbxMetadataExtractorTest.java +++ b/booklore-api/src/test/java/com/adityachandel/booklore/service/metadata/extractor/CbxMetadataExtractorTest.java @@ -5,7 +5,9 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -19,6 +21,9 @@ import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import javax.imageio.ImageIO; +import java.awt.Color; + import static org.junit.jupiter.api.Assertions.*; class CbxMetadataExtractorTest { @@ -90,9 +95,9 @@ class CbxMetadataExtractorTest { " " + ""; - byte[] img1 = new byte[]{11}; - byte[] img2 = new byte[]{22, 22}; // expect this one - byte[] img3 = new byte[]{33, 33, 33}; + byte[] img1 = createTestImage(Color.RED); + byte[] img2 = createTestImage(Color.GREEN); // expect this one + byte[] img3 = createTestImage(Color.BLUE); File cbz = createCbz("with_cover.cbz", new LinkedHashMap<>() {{ put("ComicInfo.xml", xml.getBytes(StandardCharsets.UTF_8)); @@ -108,9 +113,9 @@ class CbxMetadataExtractorTest { @Test void extractCover_fromCbz_fallbackAlphabeticalFirst() throws Exception { // No ComicInfo.xml, images intentionally added in unsorted order - byte[] aPng = new byte[]{1,1}; // alphabetically first (A.png) - byte[] bJpg = new byte[]{2}; - byte[] cJpeg = new byte[]{3,3,3}; + byte[] aPng = createTestImage(Color.YELLOW); // alphabetically first (A.png) + byte[] bJpg = createTestImage(Color.MAGENTA); + byte[] cJpeg = createTestImage(Color.CYAN); File cbz = createCbz("fallback.cbz", new LinkedHashMap<>() {{ put("z/pageC.jpeg", cJpeg); @@ -150,4 +155,17 @@ class CbxMetadataExtractorTest { } return out.toFile(); } + + private byte[] createTestImage(Color color) throws IOException { + BufferedImage image = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); + for (int x = 0; x < 10; x++) { + for (int y = 0; y < 10; y++) { + image.setRGB(x, y, color.getRGB()); + } + } + try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + ImageIO.write(image, "jpg", baos); + return baos.toByteArray(); + } + } } \ No newline at end of file diff --git a/booklore-ui/src/app/app.component.html b/booklore-ui/src/app/app.component.html index f36225ead..4a654f4bb 100644 --- a/booklore-ui/src/app/app.component.html +++ b/booklore-ui/src/app/app.component.html @@ -1,23 +1,14 @@ @if (loading) {
- +

Loading Booklore…

Please wait while we get things ready.

} @else { -
-
-
- - - -
-
+ + + } diff --git a/booklore-ui/src/app/app.component.scss b/booklore-ui/src/app/app.component.scss index 04329c096..397661ebe 100644 --- a/booklore-ui/src/app/app.component.scss +++ b/booklore-ui/src/app/app.component.scss @@ -1,25 +1,3 @@ -.app-background { - min-height: 100vh; - position: relative; - background-size: cover; - background-position: center center; - background-attachment: fixed; - background-repeat: no-repeat; -} - -.app-overlay { - position: absolute; - inset: 0; - background: rgba(20, 20, 20, 0.4); - z-index: 0; -} - -.app-content { - position: relative; - z-index: 1; - min-height: 100vh; -} - .splash-screen { display: flex; align-items: center; diff --git a/booklore-ui/src/app/app.component.ts b/booklore-ui/src/app/app.component.ts index 71aa844fd..87c69794c 100644 --- a/booklore-ui/src/app/app.component.ts +++ b/booklore-ui/src/app/app.component.ts @@ -37,7 +37,6 @@ export class AppComponent implements OnInit, OnDestroy { private taskEventService = inject(TaskEventService); private duplicateFileService = inject(DuplicateFileService); private appConfigService = inject(AppConfigService); // Keep it here to ensure the service is initialized - private readonly configService = inject(AppConfigService); ngOnInit(): void { this.authInit.initialized$.subscribe(ready => { @@ -102,25 +101,4 @@ export class AppComponent implements OnInit, OnDestroy { ngOnDestroy(): void { this.subscriptions.forEach(sub => sub.unsubscribe()); } - - readonly backgroundStyle = computed(() => { - const state = this.configService.appState(); - const backgroundImage = state.backgroundImage; - if (!backgroundImage) { - return 'none'; - } - - return `url('${backgroundImage}')`; - }); - - readonly blurStyle = computed(() => { - const state = this.configService.appState(); - const blur = state.backgroundBlur ?? AppConfigService.DEFAULT_BACKGROUND_BLUR; - return `blur(${blur}px)`; - }); - - readonly showBackground = computed(() => { - const state = this.configService.appState(); - return state.showBackground ?? true; - }); } diff --git a/booklore-ui/src/app/core/model/app-state.model.ts b/booklore-ui/src/app/core/model/app-state.model.ts index 4c6b23042..823544493 100644 --- a/booklore-ui/src/app/core/model/app-state.model.ts +++ b/booklore-ui/src/app/core/model/app-state.model.ts @@ -2,9 +2,4 @@ export interface AppState { preset?: string; primary?: string; surface?: string; - backgroundImage?: string; - backgroundBlur?: number; - showBackground?: boolean; - lastUpdated?: number; // Not persisted, used for cache busting - surfaceAlpha?: number; } diff --git a/booklore-ui/src/app/core/service/app-config.service.ts b/booklore-ui/src/app/core/service/app-config.service.ts index 97d05a4db..477f9911c 100644 --- a/booklore-ui/src/app/core/service/app-config.service.ts +++ b/booklore-ui/src/app/core/service/app-config.service.ts @@ -1,9 +1,8 @@ import {DOCUMENT, isPlatformBrowser} from '@angular/common'; import {effect, inject, Injectable, PLATFORM_ID, signal} from '@angular/core'; -import {$t} from '@primeng/themes'; +import {$t, updatePreset, updateSurfacePalette} from '@primeng/themes'; import Aura from '@primeng/themes/aura'; import {AppState} from '../model/app-state.model'; -import {UrlHelperService} from '../../utilities/service/url-helper.service'; type ColorPalette = Record; @@ -16,15 +15,10 @@ interface Palette { providedIn: 'root', }) export class AppConfigService { - public static readonly DEFAULT_BACKGROUND_BLUR = 20; - public static readonly DEFAULT_SURFACE_ALPHA = 0.88; - public static readonly DEFAULT_PRIMARY_COLOR = 'indigo'; - private readonly STORAGE_KEY = 'appConfigState'; appState = signal({}); document = inject(DOCUMENT); platformId = inject(PLATFORM_ID); - private readonly urlHelper = inject(UrlHelperService); private initialized = false; readonly surfaces: Palette[] = [ @@ -168,20 +162,17 @@ export class AppConfigService { constructor() { const initialState = this.loadAppState(); - this.appState.set(initialState); + this.appState.set({...initialState}); this.document.documentElement.classList.add('p-dark'); if (isPlatformBrowser(this.platformId)) { - this.setBackendImage(); - setTimeout(() => { - this.onPresetChange(); - this.initialized = true; - }, 0); + this.onPresetChange(); } effect(() => { const state = this.appState(); if (!this.initialized || !state) { + this.initialized = true; return; } this.saveAppState(state); @@ -189,87 +180,33 @@ export class AppConfigService { }, {allowSignalWrites: true}); } - private setBackendImage(): void { - const backendUrl = this.urlHelper.getBackgroundImageUrl(Date.now()); - this.appState.update(state => ({ - ...state, - backgroundImage: backendUrl, - lastUpdated: Date.now() - })); - } - - refreshBackgroundImage(): void { - const timestamp = Date.now(); - const backendUrl = this.urlHelper.getBackgroundImageUrl(timestamp); - this.appState.update(state => ({ - ...state, - backgroundImage: backendUrl, - lastUpdated: timestamp - })); - } - private loadAppState(): AppState { - const defaultState: AppState = { - preset: 'Aura', - primary: AppConfigService.DEFAULT_PRIMARY_COLOR, - surface: 'neutral', - backgroundBlur: AppConfigService.DEFAULT_BACKGROUND_BLUR, - showBackground: true, - surfaceAlpha: AppConfigService.DEFAULT_SURFACE_ALPHA, - }; - if (isPlatformBrowser(this.platformId)) { const storedState = localStorage.getItem(this.STORAGE_KEY); if (storedState) { - try { - const parsed = JSON.parse(storedState); - return { - preset: parsed.preset || defaultState.preset, - primary: parsed.primary || defaultState.primary, - surface: parsed.surface || defaultState.surface, - backgroundBlur: parsed.backgroundBlur ?? defaultState.backgroundBlur, - showBackground: parsed.showBackground ?? defaultState.showBackground, - surfaceAlpha: parsed.surfaceAlpha ?? defaultState.surfaceAlpha, - }; - } catch (error) { - return defaultState; - } + return JSON.parse(storedState); } } - return defaultState; + return { + preset: 'Aura', + primary: 'green', + surface: 'neutral', + }; } private saveAppState(state: AppState): void { if (isPlatformBrowser(this.platformId)) { - const {backgroundImage, lastUpdated, ...stateToSave} = state; - localStorage.setItem(this.STORAGE_KEY, JSON.stringify(stateToSave)); + localStorage.setItem(this.STORAGE_KEY, JSON.stringify(state)); } } private getSurfacePalette(surface: string): ColorPalette { - const palette = this.surfaces.find(s => s.name === surface)?.palette ?? {}; - const alpha = this.appState().surfaceAlpha ?? AppConfigService.DEFAULT_SURFACE_ALPHA; - const transparentPalette: ColorPalette = {}; - - // Text/content colors that should remain opaque (not transparent) - const opaqueKeys = ['0', '50', '100', '200', '300', '400']; - - Object.entries(palette).forEach(([key, hex]) => { - if (opaqueKeys.includes(key)) { - // Keep text colors opaque - transparentPalette[key] = hex; - } else { - // Apply transparency to background colors (500-950) - transparentPalette[key] = this.hexToRgba(hex, alpha); - } - }); - - return transparentPalette; + return this.surfaces.find(s => s.name === surface)?.palette ?? {}; } getPresetExt(): object { const surfacePalette = this.getSurfacePalette(this.appState().surface ?? 'neutral'); - const primaryName = this.appState().primary ?? AppConfigService.DEFAULT_PRIMARY_COLOR; + const primaryName = this.appState().primary ?? 'green'; const presetPalette = (Aura.primitive ?? {}) as Record; const color = presetPalette[primaryName] ?? {}; @@ -311,8 +248,8 @@ export class AppConfigService { highlight: { background: 'color-mix(in srgb, {primary.400}, transparent 84%)', focusBackground: 'color-mix(in srgb, {primary.400}, transparent 76%)', - color: 'rgba(255,255,255,.88)', - focusColor: 'rgba(255,255,255,.88)' + color: 'rgba(255,255,255,.87)', + focusColor: 'rgba(255,255,255,.87)' } } } @@ -320,30 +257,9 @@ export class AppConfigService { }; } - private hexToRgba(hex: string, alpha: number = AppConfigService.DEFAULT_SURFACE_ALPHA): string { - const r = parseInt(hex.slice(1, 3), 16); - const g = parseInt(hex.slice(3, 5), 16); - const b = parseInt(hex.slice(5, 7), 16); - return `rgba(${r}, ${g}, ${b}, ${alpha})`; - } - onPresetChange(): void { const surfacePalette = this.getSurfacePalette(this.appState().surface ?? 'neutral'); const preset = this.getPresetExt(); $t().preset(Aura).preset(preset).surfacePalette(surfacePalette).use({useDefaultOptions: true}); } - - updateBackgroundBlur(blur: number): void { - this.appState.update(state => ({ - ...state, - backgroundBlur: blur - })); - } - - updateSurfaceAlpha(alpha: number): void { - this.appState.update(state => ({ - ...state, - surfaceAlpha: alpha - })); - } } diff --git a/booklore-ui/src/app/layout/component/theme-configurator/theme-configurator.component.html b/booklore-ui/src/app/layout/component/theme-configurator/theme-configurator.component.html index cd40e5be6..0ca7f3072 100644 --- a/booklore-ui/src/app/layout/component/theme-configurator/theme-configurator.component.html +++ b/booklore-ui/src/app/layout/component/theme-configurator/theme-configurator.component.html @@ -28,67 +28,6 @@ } -
- Transparency: {{ (1 - surfaceAlphaValue).toFixed(2) }} - - -
- - -
- Background -
-
-
- - - -
- @if (backgroundVisible) { -
- - - -
- } -
- @if (backgroundVisible) { -
- - - - -
- } -
diff --git a/booklore-ui/src/app/layout/component/theme-configurator/theme-configurator.component.scss b/booklore-ui/src/app/layout/component/theme-configurator/theme-configurator.component.scss index 6767b5627..e69de29bb 100644 --- a/booklore-ui/src/app/layout/component/theme-configurator/theme-configurator.component.scss +++ b/booklore-ui/src/app/layout/component/theme-configurator/theme-configurator.component.scss @@ -1,95 +0,0 @@ -.config-panel-section { - margin-bottom: 1.5rem; - padding-bottom: 1rem; - border-bottom: 1px solid var(--surface-border); -} - -.config-panel-field { - display: flex; - flex-direction: column; - gap: 0.5rem; - margin-bottom: 1rem; - - label { - font-weight: 500; - color: var(--text-color); - } - - input[type="text"], input[type="range"] { - padding: 0.5rem; - border: 1px solid var(--surface-border); - border-radius: var(--border-radius); - background: var(--surface-ground); - color: var(--text-color); - } - - input[type="range"] { - width: 100%; - } -} - -// Background section styles -.config-panel-colors { - .surface-alpha-control { - display: flex; - flex-direction: column; - margin-top: 0.75rem; - padding: 0.5rem 0; - - .config-panel-label { - margin-bottom: 0.5rem; - } - - .alpha-slider { - width: 100%; - } - } - - .background-center-wrapper { - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - - .background-controls { - display: flex; - flex-direction: column; - width: 100%; - box-sizing: border-box; - } - - .background-control { - display: flex; - align-items: center; - padding-top: 0.5rem; - padding-bottom: 0.1rem; - - label { - min-width: 80px; - font-size: 0.85em; - font-weight: 500; - color: var(--text-secondary-color); - } - - .blur-slider { - flex: 1; - margin-left: 0.5rem; - } - } - - .background-actions-row { - display: flex; - flex-direction: row; - gap: 0.75rem; - margin-top: 0.75rem; - width: 100%; - box-sizing: border-box; - align-items: center; - justify-content: flex-end; - - .upload-bg-btn { - margin-left: 0; - } - } - } -} diff --git a/booklore-ui/src/app/layout/component/theme-configurator/theme-configurator.component.ts b/booklore-ui/src/app/layout/component/theme-configurator/theme-configurator.component.ts index fd7ebab0a..236ea2def 100644 --- a/booklore-ui/src/app/layout/component/theme-configurator/theme-configurator.component.ts +++ b/booklore-ui/src/app/layout/component/theme-configurator/theme-configurator.component.ts @@ -1,19 +1,13 @@ import {CommonModule} from '@angular/common'; import {Component, computed, effect, inject} from '@angular/core'; import {FormsModule} from '@angular/forms'; +import {$t} from '@primeng/themes'; import Aura from '@primeng/themes/aura'; import {ButtonModule} from 'primeng/button'; import {RadioButtonModule} from 'primeng/radiobutton'; import {ToggleSwitchModule} from 'primeng/toggleswitch'; -import {InputTextModule} from 'primeng/inputtext'; -import {SliderModule, SliderSlideEndEvent} from 'primeng/slider'; import {AppConfigService} from '../../../core/service/app-config.service'; import {FaviconService} from './favicon-service'; -import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog'; -import {UploadDialogComponent} from './upload-dialog/upload-dialog.component'; -import {UrlHelperService} from '../../../utilities/service/url-helper.service'; -import {BackgroundUploadService} from './background-upload.service'; -import {debounceTime, Subject} from 'rxjs'; type ColorPalette = Record; @@ -26,7 +20,6 @@ interface Palette { selector: 'app-theme-configurator', standalone: true, templateUrl: './theme-configurator.component.html', - styleUrls: ['./theme-configurator.component.scss'], host: { class: 'config-panel hidden' }, @@ -35,17 +28,12 @@ interface Palette { FormsModule, ButtonModule, RadioButtonModule, - ToggleSwitchModule, - InputTextModule, - SliderModule - ], - providers: [DialogService] + ToggleSwitchModule + ] }) export class ThemeConfiguratorComponent { readonly configService = inject(AppConfigService); readonly faviconService = inject(FaviconService); - readonly urlHelper = inject(UrlHelperService); - private readonly backgroundUploadService = inject(BackgroundUploadService); readonly surfaces = this.configService.surfaces; @@ -53,7 +41,7 @@ export class ThemeConfiguratorComponent { readonly selectedSurfaceColor = computed(() => this.configService.appState().surface); readonly faviconColor = computed(() => { - const name = this.selectedPrimaryColor() ?? AppConfigService.DEFAULT_PRIMARY_COLOR; + const name = this.selectedPrimaryColor() ?? 'green'; const presetPalette = (Aura.primitive ?? {}) as Record; const colorPalette = presetPalette[name]; return colorPalette?.[500] ?? name; @@ -74,64 +62,6 @@ export class ThemeConfiguratorComponent { ); }); - get backgroundVisible(): boolean { - return this.configService.appState().showBackground ?? true; - } - - set backgroundVisible(value: boolean) { - this.configService.appState.update(state => ({ - ...state, - showBackground: value - })); - } - - get backgroundBlurValue(): number { - return this.configService.appState().backgroundBlur ?? AppConfigService.DEFAULT_BACKGROUND_BLUR; - } - - set backgroundBlurValue(value: number) { - this.configService.updateBackgroundBlur(value); - } - - get surfaceAlphaValue(): number { - return this.configService.appState().surfaceAlpha ?? AppConfigService.DEFAULT_SURFACE_ALPHA; - } - - set surfaceAlphaValue(value: number) { - this.configService.updateSurfaceAlpha(value); - } - - private readonly dialogService = inject(DialogService); - private dialogRef: DynamicDialogRef | undefined; - - private surfaceAlphaSubject = new Subject(); - - constructor() { - this.surfaceAlphaSubject.pipe( - debounceTime(100) - ).subscribe(value => { - this.configService.updateSurfaceAlpha(value); - }); - } - - openUploadDialog() { - this.dialogRef = this.dialogService.open(UploadDialogComponent, { - header: 'Upload or Paste Image URL', - width: '450px', - modal: true, - closable: true, - data: {} - }); - - this.dialogRef.onClose.subscribe((result) => { - if (result) { - if (result.success || result.uploaded || result.url || result.imageUrl) { - this.configService.refreshBackgroundImage(); - } - } - }); - } - updateColors(event: Event, type: 'primary' | 'surface', color: { name: string; palette?: ColorPalette }) { this.configService.appState.update((state) => ({ ...state, @@ -139,26 +69,4 @@ export class ThemeConfiguratorComponent { })); event.stopPropagation(); } - - updateBackgroundBlur(event: SliderSlideEndEvent): void { - this.configService.appState.update(state => ({ - ...state, - backgroundBlur: Number(event.value) - })); - } - - updateSurfaceAlpha(event: SliderSlideEndEvent): void { - this.surfaceAlphaSubject.next(Number(event.value)); - } - - resetBackground() { - this.backgroundUploadService.resetToDefault().subscribe({ - next: () => { - this.configService.refreshBackgroundImage(); - }, - error: (err) => { - console.error('Failed to reset background:', err); - } - }); - } } diff --git a/booklore-ui/src/assets/layout/styles/layout/_topbar.scss b/booklore-ui/src/assets/layout/styles/layout/_topbar.scss index 910b33a48..afac58f4c 100644 --- a/booklore-ui/src/assets/layout/styles/layout/_topbar.scss +++ b/booklore-ui/src/assets/layout/styles/layout/_topbar.scss @@ -114,15 +114,14 @@ } .config-panel-colors { - // Only apply flex to color picker rows, not background-center-wrapper - > div:not(.background-center-wrapper) { + > div { justify-content: flex-start; padding-top: .5rem; display: flex; gap: .5rem; flex-wrap: wrap; - button:not([pbutton]):not(.p-button) { + button { border: none; width: 1.25rem; height: 1.25rem;