Skip to content

Commit

Permalink
Remove redundant Logger service and update controllers for PWA.
Browse files Browse the repository at this point in the history
Deleted the custom Logger service as it was unnecessary. Introduced preloads for PWA pages in multiple controllers for better page readiness. Also updated dependencies, disabled XSS protection settings, and replaced DeviceMotion component with a simplified version.
  • Loading branch information
Spomky committed Dec 15, 2024
1 parent bdcf1c2 commit 4f3ed57
Show file tree
Hide file tree
Showing 111 changed files with 2,000 additions and 416 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@
###> liip/imagine-bundle ###
/public/media/cache/
###< liip/imagine-bundle ###

###> phpstan/phpstan ###
phpstan.neon
###< phpstan/phpstan ###

/.castor.stub.php
1 change: 0 additions & 1 deletion assets/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ import './bootstrap.js';
import './styles/app.css';
import 'flowbite';
import 'flowbite/dist/flowbite.min.css';
import 'highlight.js/styles/nord.min.css';
1 change: 0 additions & 1 deletion assets/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { startStimulusApp } from '@symfony/stimulus-bundle';
import Timeago from 'stimulus-timeago'

const app = startStimulusApp();
// register any custom, 3rd party controllers here
18 changes: 8 additions & 10 deletions assets/controllers.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"enabled": true,
"fetch": "eager"
},
"device-motion": {
"enabled": true,
"fetch": "eager"
},
"device-orientation": {
"enabled": true,
"fetch": "eager"
Expand Down Expand Up @@ -53,6 +57,10 @@
"enabled": true,
"fetch": "eager"
},
"touch": {
"enabled": true,
"fetch": "eager"
},
"vibration": {
"enabled": true,
"fetch": "eager"
Expand All @@ -72,16 +80,6 @@
"@symfony/ux-live-component/dist/live.min.css": true
}
}
},
"@symfony/ux-turbo": {
"turbo-core": {
"enabled": true,
"fetch": "eager"
},
"mercure-turbo-stream": {
"enabled": false,
"fetch": "eager"
}
}
},
"entrypoints": []
Expand Down
11 changes: 11 additions & 0 deletions assets/controllers/code_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

import { Controller } from '@hotwired/stimulus';
import hljs from 'highlight.js';
import 'highlight.js/styles/nord.min.css';

export default class extends Controller {
connect() {
hljs.highlightElement(this.element);
}
}
34 changes: 34 additions & 0 deletions assets/controllers/network-information_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

import { Controller } from '@hotwired/stimulus';

export default class extends Controller {
static targets = [
'downlink', 'downlinkMax', 'effectiveType', 'rtt', 'saveData', 'type',
'downlinkContent', 'downlinkMaxContent', 'effectiveTypeContent', 'rttContent', 'saveDataContent', 'typeContent',
];

connect() {
const connection = navigator.connection;
connection.addEventListener('change', this.updateConnectionStatus);
this.updateConnectionStatus();
}

updateConnectionStatus = () => {
const connection = navigator.connection;
console.log({bubble: true, details: connection});
this.dispatch('network-information:change', {bubble: true, details: {connection}});
this.downlinkTargets.forEach((element) => element.setAttribute('data-network-information-downlink-value', connection.downlink));
this.downlinkContentTargets.forEach((element) => element.textContent = connection.downlink);
this.downlinkMaxTargets.forEach((element) => element.setAttribute('data-network-information-downlink-max-value', connection.downlinkMax));
this.downlinkMaxContentTargets.forEach((element) => element.textContent = connection.downlinkMax ?? '...');
this.effectiveTypeTargets.forEach((element) => element.setAttribute('data-network-information-effective-type-value', connection.effectiveType));
this.effectiveTypeContentTargets.forEach((element) => element.textContent = connection.effectiveType);
this.rttTargets.forEach((element) => element.setAttribute('data-network-information-rtt-value', connection.rtt));
this.rttContentTargets.forEach((element) => element.textContent = connection.rtt);
this.saveDataTargets.forEach((element) => element.setAttribute('data-network-information-save-data-value', connection.saveData));
this.saveDataContentTargets.forEach((element) => element.textContent = connection.saveData ? 'Yes' : 'No');
this.typeTargets.forEach((element) => element.setAttribute('data-network-information-type-value', connection.type));
this.typeContentTargets.forEach((element) => element.textContent = connection.type ?? '...');
}
}
35 changes: 35 additions & 0 deletions assets/controllers/reveal_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

import { Controller } from '@hotwired/stimulus';
import Reveal from 'reveal.js';
import Markdown from 'reveal.js/plugin/markdown/markdown.esm.js';
import 'reveal.js/dist/reveal.css';
import 'reveal.js/dist/theme/serif.css';

export default class extends Controller {
deck = null;
connect() {
this.deck = new Reveal({
plugins: [Markdown],
});
this.deck.initialize();
}

message({detail}) {
const {data} = detail;
if (data.message === 'next') {
this.next();
}
if (data.message === 'previous') {
this.previous();
}
}

next() {
this.deck.next();
}

previous() {
this.deck.prev();
}
}
92 changes: 92 additions & 0 deletions assets/controllers/speech-recognition_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
'use strict';

import { Controller } from '@hotwired/stimulus';

export default class extends Controller {
static values = {
continuous: { type: Boolean, default: false },
grammarString: { type: String, default: null },
//grammarUri: { type: String, default: null },
grammarWeight: { type: Number, default: 1 },
interimResults: { type: Boolean, default: false },
lang: { type: String, default: 'en-US' },
maxAlternatives: { type: Number, default: 1 },
};
static targets = ['attributeOutput', 'contentOutput'];

recognition = null;

connect() {
const supported = 'webkitSpeechRecognition' in window || 'SpeechRecognition' in window;
if (!supported) {
return;
}

this.recognition = new webkitSpeechRecognition() || new SpeechRecognition();
if (this.grammarStringValue) {
const speechRecognitionList = new webkitSpeechGrammarList() || new SpeechGrammarList();
speechRecognitionList.addFromString(this.grammarValue, this.grammarWeightValue);
this.recognition.grammars = speechRecognitionList;
}
this.recognition.continuous = this.continuousValue;
this.recognition.lang = this.langValue;
this.recognition.interimResults = this.interimResultsValue;
this.recognition.maxAlternatives = this.maxAlternativesValue;
this.recognition.addEventListener('result', this.onResult);
this.recognition.addEventListener('audiostart', () => {
this.dispatch('speech-recognition:audiostart');
});
this.recognition.addEventListener('audioend', () => {
this.dispatch('speech-recognition:audioend');
});
this.recognition.addEventListener('start', () => {
this.dispatch('speech-recognition:start');
});
this.recognition.addEventListener('end', () => {
this.dispatch('speech-recognition:end');
});
this.recognition.addEventListener('error', (event) => {
this.dispatch('speech-recognition:error', { error: event.error });
});
this.recognition.addEventListener('nomatch', () => {
this.dispatch('speech-recognition:nomatch');
});
this.recognition.addEventListener('soundstart', () => {
this.dispatch('speech-recognition:soundstart');
});
this.recognition.addEventListener('soundend', () => {
this.dispatch('speech-recognition:soundend');
});
this.recognition.addEventListener('speechstart', () => {
this.dispatch('speech-recognition:speechstart');
});
this.recognition.addEventListener('speechend', () => {
this.dispatch('speech-recognition:speechend');
});
}

start() {
this.recognition.start();
}

stop() {
this.recognition.stop();
}

onResult = (event) => {
const length = event.results.length;
for (let i = event.resultIndex; i < length; i++) {
const speechRecognitionResult = event.results[i];
const alternatives = speechRecognitionResult.length;
for (let j = 0; j < alternatives; j++) {
const transcript = speechRecognitionResult[j].transcript.trim();
if (transcript === '') {
continue;
}
this.dispatch('speech-recognition:result', { transcript: transcript, isFinal: speechRecognitionResult.isFinal, confidence: speechRecognitionResult[j].confidence });
this.attributeOutputTargets.forEach((element) => element.setAttribute('data-speech-recognition', transcript));
this.contentOutputTargets.forEach((element) => element.textContent += transcript+'\n');
}
}
}
}
40 changes: 40 additions & 0 deletions assets/controllers/speech_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

import { Controller } from '@hotwired/stimulus';

export default class extends Controller {
connect() {
this.populateVoiceList();
}

locales = () => {
return speechSynthesis.getVoices().map((voice) => voice.lang);
}

voices = ({params}) => {
const voices = speechSynthesis.getVoices()
.filter((voice) => params.locale ? voice.lang === params.locale : true)
.filter((voice) => params.type === 'distant' ? voice.localService === false : true)
.filter((voice) => params.type === 'local' ? voice.localService === true : true)
;
console.log(voices);

return voices;
}

speak = ({params}) => {
const utterance = new SpeechSynthesisUtterance(params.text);
utterance.voice = speechSynthesis.getVoices().find((voice) => voice.name === params.voice);
utterance.lang = params.locale || 'en-US';
utterance.rate = params.rate || 1;
utterance.pitch = params.pitch || 1;
speechSynthesis.speak(utterance);
}

populateVoiceList = () => {
if (typeof speechSynthesis === "undefined") {
return;
}
speechSynthesis.getVoices();
}
}
16 changes: 16 additions & 0 deletions assets/controllers/spotlight_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

import { Controller } from '@hotwired/stimulus';

export default class extends Controller {
connect() {
// Envoie événement au PageDown et au PageUp du clavier
document.addEventListener('keydown', (event) => {
if (event.key === 'PageDown') {
document.getElementById('next').click();
} else if (event.key === 'PageUp') {
document.getElementById('previous').click();
}
});
}
}
1 change: 1 addition & 0 deletions assets/receiver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './bootstrap.js';
26 changes: 21 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@
"nelmio/cors-bundle": "^2.4",
"nelmio/security-bundle": "^3.3",
"phpdocumentor/reflection-docblock": "^5.3",
"phpstan/phpdoc-parser": "^1.25",
"phpstan/phpdoc-parser": "^2.0",
"spomky-labs/pwa-bundle": "1.3.x@dev",
"symfony/asset": "7.2.*",
"symfony/asset-mapper": "7.2.*",
"symfony/console": "7.2.*",
"symfony/dependency-injection": "7.2.*",
"symfony/dotenv": "7.2.*",
"symfony/expression-language": "7.2.*",
"symfony/flex": "^2",
"symfony/form": "7.2.*",
"symfony/framework-bundle": "7.2.*",
"symfony/http-foundation": "7.2.*",
"symfony/http-kernel": "7.2.*",
"symfony/intl": "7.2.*",
"symfony/mime": "7.2.*",
"symfony/monolog-bundle": "^3.0",
"symfony/process": "7.2.*",
"symfony/property-access": "7.2.*",
"symfony/property-info": "7.2.*",
"symfony/routing": "7.2.*",
"symfony/runtime": "7.2.*",
"symfony/security-bundle": "7.2.*",
"symfony/serializer": "7.2.*",
Expand All @@ -41,20 +45,20 @@
"symfony/ux-leaflet-map": "^2.22",
"symfony/ux-live-component": "^2.22",
"symfony/ux-map": "^2.22",
"symfony/ux-turbo": "^2.22",
"symfony/ux-twig-component": "^2.22",
"symfony/validator": "7.2.*",
"symfony/web-link": "7.2.*",
"symfony/yaml": "7.2.*",
"symfonycasts/tailwind-bundle": "^0.5.0",
"symfonycasts/tailwind-bundle": "^0.6",
"twig/extra-bundle": "^2.12|^3.0",
"twig/twig": "^2.12|^3.0"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"symfony/flex": true,
"symfony/runtime": true
"symfony/runtime": true,
"phpstan/extension-installer": true
},
"sort-packages": true
},
Expand Down Expand Up @@ -103,7 +107,19 @@
},
"require-dev": {
"dbrekelmans/bdi": "^1.1",
"phpunit/phpunit": "^10.0|^11.0",
"ekino/phpstan-banned-code": "^3.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-beberlei-assert": "^2.0",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpstan/phpstan-symfony": "^2.0",
"phpunit/phpunit": "^11.0",
"shipmonk/composer-dependency-analyser": "^1.8",
"shipmonk/dead-code-detector": "^0.6.0",
"staabm/phpstan-todo-by": "^0.2.0",
"struggle-for-php/sfp-phpstan-psr-log": "^0.23.0",
"symfony/browser-kit": "7.2.*",
"symfony/css-selector": "7.2.*",
"symfony/debug-bundle": "7.2.*",
Expand Down
Loading

0 comments on commit 4f3ed57

Please sign in to comment.