Adds settings options and localUser functions

This commit is contained in:
Benedicte Quimbert 2022-03-07 15:43:00 +01:00
parent a10f327f45
commit 453ccb7745
6 changed files with 290 additions and 216 deletions

View File

@ -15,9 +15,12 @@
let valueGame: number = localUserStore.getGameQualityValue(); let valueGame: number = localUserStore.getGameQualityValue();
let valueVideo: number = localUserStore.getVideoQualityValue(); let valueVideo: number = localUserStore.getVideoQualityValue();
let valueLocale: string = $locale; let valueLocale: string = $locale;
let valuePrivacySettings = localUserStore.getPrivacySettings();
let previewValueGame = valueGame; let previewValueGame = valueGame;
let previewValueVideo = valueVideo; let previewValueVideo = valueVideo;
let previewValueLocale = valueLocale; let previewValueLocale = valueLocale;
let previewPrivacySettings = valuePrivacySettings; // TODO: retreive from local storage
function saveSetting() { function saveSetting() {
let change = false; let change = false;
@ -38,6 +41,11 @@
change = true; change = true;
} }
if (valuePrivacySettings !== previewPrivacySettings) {
console.log(`was: ${previewPrivacySettings} | is: ${valuePrivacySettings}`)
localUserStore.setPrivacySettings(valuePrivacySettings);
}
if (change) { if (change) {
window.location.reload(); window.location.reload();
} }
@ -154,6 +162,27 @@
</select> </select>
</div> </div>
</section> </section>
<section>
<h3>{$LL.menu.settings.privacySettings.title()}</h3>
<p>{$LL.menu.settings.privacySettings.explaination()}</p>
<div class="nes-select is-dark">
<select class="privacy-settings-switcher" bind:value={valuePrivacySettings}>
<option value={"allEnabled"}
>{ $LL.menu.settings.privacySettings.allEnabled() }
</option>
<option value={"microphoneEnabled"}
>{ $LL.menu.settings.privacySettings.onlyMicrophoneEnabled() }
</option>
<option value={"cameraEnabled"}
>{ $LL.menu.settings.privacySettings.onlyCameraEnabled() }
</option>
<option value={"noneEnabled"}
>{ $LL.menu.settings.privacySettings.allDisabled() }
</option>
</select>
</div>
</section>
<section class="settings-section-save"> <section class="settings-section-save">
<p>{$LL.menu.settings.save.warning()}</p> <p>{$LL.menu.settings.save.warning()}</p>
<button type="button" class="nes-btn is-primary" on:click|preventDefault={saveSetting} <button type="button" class="nes-btn is-primary" on:click|preventDefault={saveSetting}
@ -217,12 +246,15 @@
outline: none; outline: none;
} }
} }
section.settings-section-save { section.settings-section-save {
text-align: center; text-align: center;
p { p {
margin: 16px 0; margin: 16px 0;
} }
} }
section.settings-section-noSaveOption { section.settings-section-noSaveOption {
display: flex; display: flex;
align-items: center; align-items: center;

View File

@ -24,6 +24,7 @@ const code = "code";
const cameraSetup = "cameraSetup"; const cameraSetup = "cameraSetup";
const cacheAPIIndex = "workavdenture-cache"; const cacheAPIIndex = "workavdenture-cache";
const userProperties = "user-properties"; const userProperties = "user-properties";
const privacySettings = "privacySettings";
class LocalUserStore { class LocalUserStore {
saveUser(localUser: LocalUser) { saveUser(localUser: LocalUser) {
@ -224,6 +225,14 @@ class LocalUserStore {
return cameraSetupValues != undefined ? JSON.parse(cameraSetupValues) : undefined; return cameraSetupValues != undefined ? JSON.parse(cameraSetupValues) : undefined;
} }
setPrivacySettings(option: string) {
localStorage.setItem(privacySettings, option)
}
getPrivacySettings() {
return localStorage.getItem(privacySettings);
}
getAllUserProperties(): Map<string, unknown> { getAllUserProperties(): Map<string, unknown> {
const result = new Map<string, string>(); const result = new Map<string, string>();
for (let i = 0; i < localStorage.length; i++) { for (let i = 0; i < localStorage.length; i++) {

View File

@ -12,6 +12,7 @@ import { privacyShutdownStore } from "./PrivacyShutdownStore";
import { MediaStreamConstraintsError } from "./Errors/MediaStreamConstraintsError"; import { MediaStreamConstraintsError } from "./Errors/MediaStreamConstraintsError";
import { SoundMeter } from "../Phaser/Components/SoundMeter"; import { SoundMeter } from "../Phaser/Components/SoundMeter";
import { AudioContext } from "standardized-audio-context"; import { AudioContext } from "standardized-audio-context";
import { visibilityStore } from "./VisibilityStore";
/** /**
* A store that contains the camera state requested by the user (on or off). * A store that contains the camera state requested by the user (on or off).
@ -242,6 +243,8 @@ export const mediaStreamConstraintsStore = derived(
privacyShutdownStore, privacyShutdownStore,
cameraEnergySavingStore, cameraEnergySavingStore,
isSilentStore, isSilentStore,
visibilityStore,
//TODO: optionState
], ],
( (
[ [
@ -254,6 +257,7 @@ export const mediaStreamConstraintsStore = derived(
$privacyShutdownStore, $privacyShutdownStore,
$cameraEnergySavingStore, $cameraEnergySavingStore,
$isSilentStore, $isSilentStore,
$visibilityStore
], ],
set set
) => { ) => {
@ -308,6 +312,11 @@ export const mediaStreamConstraintsStore = derived(
currentAudioConstraint = false; currentAudioConstraint = false;
} }
// if ($visibilityStore === false && $option) {
//
// }
//TODO
// Let's make the changes only if the new value is different from the old one. // Let's make the changes only if the new value is different from the old one.
if ( if (
previousComputedVideoConstraint != currentVideoConstraint || previousComputedVideoConstraint != currentVideoConstraint ||

View File

@ -57,6 +57,14 @@ const menu: NonNullable<Translation["menu"]> = {
language: { language: {
title: "Sprache", title: "Sprache",
}, },
privacySettings: {
title: "Datenschutzeinstellungen", //TODO: confirm & complete translation
explaination: "",
allEnabled: "",
onlyCameraEnabled: "",
onlyMicrophoneEnabled: "",
allDisabled: ""
},
save: { save: {
warning: "(Das Spiel wird nach dem Speichern neugestartet)", warning: "(Das Spiel wird nach dem Speichern neugestartet)",
button: "Speichern", button: "Speichern",

View File

@ -57,6 +57,14 @@ const menu: BaseTranslation = {
language: { language: {
title: "Language", title: "Language",
}, },
privacySettings: {
title: "Privacy settings",
explaination: "Here you can set an option to keep your microphone/camera enabled when switching active tabs.",
allEnabled: "Camera and microphone always enabled",
onlyCameraEnabled: "Microphone disabled when the WA tab is not focused",
onlyMicrophoneEnabled: "Camera disabled when the WA tab is not focused",
allDisabled: "Both disabled when the WA tab is not focused"
},
save: { save: {
warning: "(Saving these settings will restart the game)", warning: "(Saving these settings will restart the game)",
button: "Save", button: "Save",

View File

@ -57,6 +57,14 @@ const menu: NonNullable<Translation["menu"]> = {
language: { language: {
title: "Langage", title: "Langage",
}, },
privacySettings: {
title: "Paramètres de confidentialité",
explaination: "Vous pouvez définir ici si vous souhaitez conserver ou non l'activation du microphone/de la caméra au passage sur un autre onglet.",
allEnabled: "Camera et microphone toujours actifs",
onlyCameraEnabled: "Seul le microphone est activé quand l'onglet WA n'est pas sélectionné",
onlyMicrophoneEnabled: "Seule la caméra est activé quand l'onglet WA n'est pas sélectionné",
allDisabled: "Tout désactiver quand l'onglet WA n'est pas sélectionné"
},
save: { save: {
warning: "(La sauvegarde de ces paramètres redémarre le jeu)", warning: "(La sauvegarde de ces paramètres redémarre le jeu)",
button: "Sauvegarder", button: "Sauvegarder",