Rollback background blur and transparency due to high CPU/GPU usage (#1160)

This commit is contained in:
Aditya Chandel
2025-09-15 11:03:34 -06:00
committed by GitHub
parent 11935ae5a7
commit 1df21551f6
10 changed files with 49 additions and 422 deletions
@@ -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 {
" </Pages>" +
"</ComicInfo>";
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();
}
}
}
+4 -13
View File
@@ -1,23 +1,14 @@
@if (loading) {
<div class="splash-screen">
<div class="splash-content">
<img src="assets/favicon.svg" alt="Booklore logo" class="logo"/>
<img src="assets/favicon.svg" alt="Booklore logo" class="logo" />
<h1>Loading Booklore…</h1>
<p>Please wait while we get things ready.</p>
<div class="loader"></div>
</div>
</div>
} @else {
<div class="app-background"
[style.background-image]="showBackground() ? backgroundStyle() : 'none'">
<div class="app-overlay"
[style.backdrop-filter]="showBackground() ? blurStyle() : 'none'"
[style.-webkit-backdrop-filter]="showBackground() ? blurStyle() : 'none'"
[style.display]="showBackground() ? 'block' : 'none'"></div>
<div class="app-content">
<p-confirmDialog></p-confirmDialog>
<p-toast></p-toast>
<router-outlet></router-outlet>
</div>
</div>
<p-confirmDialog />
<p-toast></p-toast>
<router-outlet></router-outlet>
}
-22
View File
@@ -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;
-22
View File
@@ -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;
});
}
@@ -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;
}
@@ -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<string, string>;
@@ -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<AppState>({});
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<string, ColorPalette>;
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
}));
}
}
@@ -28,67 +28,6 @@
</button>
}
</div>
<div class="surface-alpha-control">
<span class="config-panel-label">Transparency: {{ (1 - surfaceAlphaValue).toFixed(2) }}</span>
<p-slider
[(ngModel)]="surfaceAlphaValue"
[min]="0.75"
[max]="1"
[step]="0.01"
(onSlideEnd)="updateSurfaceAlpha($event)"
class="alpha-slider">
</p-slider>
</div>
</div>
<div class="config-panel-colors">
<span class="config-panel-label">Background</span>
<div class="background-center-wrapper">
<div class="background-controls">
<div class="background-control">
<label>Show: </label>
<p-toggleswitch
size="small"
[(ngModel)]="backgroundVisible">
</p-toggleswitch>
</div>
@if (backgroundVisible) {
<div class="background-control">
<label for="blurRange">Blur: {{ backgroundBlurValue }}</label>
<p-slider
[(ngModel)]="backgroundBlurValue"
[min]="0"
[max]="30"
[step]="1"
(onSlideEnd)="updateBackgroundBlur($event)"
class="blur-slider">
</p-slider>
</div>
}
</div>
@if (backgroundVisible) {
<div class="background-actions-row">
<p-button
class="upload-bg-btn"
size="small"
outlined
severity="primary"
(click)="openUploadDialog()"
label="Upload Image"
icon="pi pi-upload">
</p-button>
<p-button
class="reset-bg-btn"
size="small"
outlined
severity="secondary"
(click)="resetBackground()"
label="Reset"
icon="pi pi-refresh">
</p-button>
</div>
}
</div>
</div>
</div>
@@ -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;
}
}
}
}
@@ -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<string, string>;
@@ -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<string, ColorPalette>;
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<number>();
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);
}
});
}
}
@@ -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;