Scope localStorage keys per app directory
localStorage is scoped per origin, not per path. Multiple jitsi-launch instances on one origin (e.g. meet.bnvb.eu/i and /p) therefore shared one language and one theme setting, and changing it in one instance changed it in all others. Prefix the language and theme keys with the app directory derived from the page path. Each instance keeps its own state; a root deployment gets the "/" prefix and behaves as before. Previously saved choices reset once because the key names change.
This commit is contained in:
1 parent
0e4ba86c38
commit
49a3d90dc5
1 file changed
+16
-4
+16
-4
@@ -12,6 +12,20 @@
|
|||||||
let CONFIG = {};
|
let CONFIG = {};
|
||||||
const CONFIG_URL = "assets/config.json";
|
const CONFIG_URL = "assets/config.json";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* localStorage is scoped per origin, not per path.
|
||||||
|
* Prefix keys with the app directory so parallel
|
||||||
|
* instances (e.g. meet.bnvb.eu/i and /p) stay
|
||||||
|
* independent.
|
||||||
|
*
|
||||||
|
* "/p/launch.html" becomes "/p/"
|
||||||
|
*/
|
||||||
|
const STORAGE_PREFIX =
|
||||||
|
window.location.pathname.replace(/[^/]*$/, "");
|
||||||
|
|
||||||
|
const LANGUAGE_KEY = STORAGE_PREFIX + "jitsiLauncherLanguage";
|
||||||
|
const THEME_KEY = STORAGE_PREFIX + "jitsiLauncherTheme";
|
||||||
|
|
||||||
/* ============================================================
|
/* ============================================================
|
||||||
* Translations
|
* Translations
|
||||||
* ============================================================
|
* ============================================================
|
||||||
@@ -34,7 +48,7 @@ function detectLanguage() {
|
|||||||
* Saved language choice takes precedence.
|
* Saved language choice takes precedence.
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
const saved = localStorage.getItem("jitsiLauncherLanguage");
|
const saved = localStorage.getItem(LANGUAGE_KEY);
|
||||||
|
|
||||||
if (saved && TRANSLATIONS[saved]) {
|
if (saved && TRANSLATIONS[saved]) {
|
||||||
return saved;
|
return saved;
|
||||||
@@ -179,7 +193,7 @@ function setLanguage(language) {
|
|||||||
translation = TRANSLATIONS[language];
|
translation = TRANSLATIONS[language];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
localStorage.setItem("jitsiLauncherLanguage", language);
|
localStorage.setItem(LANGUAGE_KEY, language);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
/*
|
/*
|
||||||
* localStorage can be blocked, e.g. in private mode.
|
* localStorage can be blocked, e.g. in private mode.
|
||||||
@@ -225,8 +239,6 @@ function closeNavMenu() {
|
|||||||
* ============================================================
|
* ============================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const THEME_KEY = "jitsiLauncherTheme";
|
|
||||||
|
|
||||||
function savedTheme() {
|
function savedTheme() {
|
||||||
try {
|
try {
|
||||||
const saved = localStorage.getItem(THEME_KEY);
|
const saved = localStorage.getItem(THEME_KEY);
|
||||||
|
|||||||
Reference in new issue
Block a user