canti primo tag

This commit is contained in:
David Frassi
2026-05-16 17:24:59 +02:00
commit 0c33fc6fcf
106 changed files with 28210 additions and 0 deletions
+138
View File
@@ -0,0 +1,138 @@
import { Injectable, signal, effect } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class SettingsService {
/** Default mode for viewing songs: true = chords, false = text only */
public showChordsDefault = signal<boolean>(false);
/** UI Fullscreen mode (lyrics only): true = active */
public fullscreenMode = signal<boolean>(false);
/** Browser Fullscreen state: true = fullscreen active */
public browserFullscreen = signal<boolean>(!!document.fullscreenElement);
/** Avanzamento automatico: true = passa al brano successivo automaticamente */
public autoAdvance = signal<boolean>(true);
/** Editor e Canti Personali: true = mostra funzioni aggiunta e lista "Miei" */
public showEditor = signal<boolean>(false);
/** Schermo sempre acceso: true = attiva Screen Wake Lock */
public keepScreenOn = signal<boolean>(false);
private wakeLock: any = null;
constructor() {
const savedChords = localStorage.getItem('show-chords-default');
if (savedChords !== null) {
this.showChordsDefault.set(savedChords === 'true');
}
const savedFullscreen = localStorage.getItem('fullscreen-mode');
if (savedFullscreen !== null) {
this.fullscreenMode.set(savedFullscreen === 'true');
}
const savedEditor = localStorage.getItem('show-editor');
if (savedEditor !== null) {
this.showEditor.set(savedEditor === 'true');
}
const savedAutoAdvance = localStorage.getItem('auto-advance');
if (savedAutoAdvance !== null) {
this.autoAdvance.set(savedAutoAdvance === 'true');
}
const savedKeepScreenOn = localStorage.getItem('keep-screen-on');
if (savedKeepScreenOn !== null) {
this.keepScreenOn.set(savedKeepScreenOn === 'true');
}
// Sync browser fullscreen state with listeners
document.addEventListener('fullscreenchange', () => {
this.browserFullscreen.set(!!document.fullscreenElement);
});
effect(() => {
localStorage.setItem('show-chords-default', this.showChordsDefault().toString());
});
effect(() => {
localStorage.setItem('fullscreen-mode', this.fullscreenMode().toString());
});
effect(() => {
localStorage.setItem('auto-advance', this.autoAdvance().toString());
});
effect(() => {
const active = this.keepScreenOn();
localStorage.setItem('keep-screen-on', active.toString());
if (active) {
this.requestWakeLock();
} else {
this.releaseWakeLock();
}
});
// Re-request on visibility change
document.addEventListener('visibilitychange', () => {
if (this.keepScreenOn() && document.visibilityState === 'visible') {
this.requestWakeLock();
}
});
}
setShowChordsDefault(val: boolean) {
this.showChordsDefault.set(val);
}
toggleFullscreenMode() {
this.fullscreenMode.update(v => !v);
}
toggleAutoAdvance() {
this.autoAdvance.update(v => !v);
}
toggleEditor() {
const newValue = !this.showEditor();
this.showEditor.set(newValue);
localStorage.setItem('show-editor', newValue.toString());
}
toggleKeepScreenOn() {
this.keepScreenOn.update(v => !v);
}
private async requestWakeLock() {
if ('wakeLock' in navigator) {
try {
this.wakeLock = await (navigator as any).wakeLock.request('screen');
} catch (err: any) {
console.error(`Wake Lock error: ${err.name}, ${err.message}`);
}
}
}
private releaseWakeLock() {
if (this.wakeLock) {
this.wakeLock.release();
this.wakeLock = null;
}
}
toggleBrowserFullscreen() {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen().catch(err => {
console.error(`Error attempting to enable full-screen mode: ${err.message}`);
});
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
}
}
}
}