marlConsole
This commit is contained in:
@@ -18,7 +18,7 @@ document.addEventListener("alpine:init", () => {
|
|||||||
"Bonjour!",
|
"Bonjour!",
|
||||||
"Oh hey!",
|
"Oh hey!",
|
||||||
];
|
];
|
||||||
Alpine.store("ui").logMsg(`MARL loaded. ${salutations[Math.floor(Math.random() * salutations.length)]} 😊`);
|
marlConsole(`MARL loaded. ${salutations[Math.floor(Math.random() * salutations.length)]} 😊`);
|
||||||
|
|
||||||
resetStores();
|
resetStores();
|
||||||
});
|
});
|
||||||
|
@@ -3,7 +3,7 @@ const userPrefsStore = {
|
|||||||
|
|
||||||
save(pref, value) {
|
save(pref, value) {
|
||||||
const msg = `Saving user preference <b>(${pref}: ${value})</b>`;
|
const msg = `Saving user preference <b>(${pref}: ${value})</b>`;
|
||||||
Alpine.store("ui").logMsg(msg, "info");
|
marlConsole(msg, "info");
|
||||||
localStorage.setItem(this.prefix + pref, value);
|
localStorage.setItem(this.prefix + pref, value);
|
||||||
},
|
},
|
||||||
load(pref) {
|
load(pref) {
|
||||||
@@ -41,7 +41,7 @@ const userPrefsStore = {
|
|||||||
if (value) {
|
if (value) {
|
||||||
const msg = `<b>Unrecognized language</b> in user preferences: ${value}`;
|
const msg = `<b>Unrecognized language</b> in user preferences: ${value}`;
|
||||||
console.warn(msg);
|
console.warn(msg);
|
||||||
Alpine.store("ui").logMsg(msg, "warn");
|
marlConsole(msg, "warn");
|
||||||
}
|
}
|
||||||
value = "en";
|
value = "en";
|
||||||
this.save("lang", value);
|
this.save("lang", value);
|
||||||
|
@@ -1,3 +1,7 @@
|
|||||||
|
function marlConsole(msg, cls = "info") {
|
||||||
|
Alpine.store("ui").logMsg(msg, cls);
|
||||||
|
}
|
||||||
|
|
||||||
function resetStores() {
|
function resetStores() {
|
||||||
Alpine.store("files").resetState();
|
Alpine.store("files").resetState();
|
||||||
Alpine.store("lightbox").resetState();
|
Alpine.store("lightbox").resetState();
|
||||||
@@ -25,11 +29,11 @@ function unZip(files) {
|
|||||||
) {
|
) {
|
||||||
const msg = `File already loaded: <b>${file.name}</b>`;
|
const msg = `File already loaded: <b>${file.name}</b>`;
|
||||||
console.warn(msg);
|
console.warn(msg);
|
||||||
Alpine.store("ui").logMsg(msg, "warn");
|
marlConsole(msg, "warn");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Alpine.store("ui").logMsg(`Loading file: <b>${file.name}</b>`, "info");
|
marlConsole(`Loading file: <b>${file.name}</b>`, "info");
|
||||||
|
|
||||||
JSZip.loadAsync(file).then(
|
JSZip.loadAsync(file).then(
|
||||||
(content) => {
|
(content) => {
|
||||||
@@ -72,7 +76,7 @@ function unZip(files) {
|
|||||||
(error) => {
|
(error) => {
|
||||||
const msg = `Error loading <b>${file.name}</b>: ${error.message}`;
|
const msg = `Error loading <b>${file.name}</b>: ${error.message}`;
|
||||||
console.error(msg);
|
console.error(msg);
|
||||||
Alpine.store("ui").logMsg(msg, "error");
|
marlConsole(msg, "error");
|
||||||
abortLoading();
|
abortLoading();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -91,13 +95,13 @@ function loadJsonFile(name, index, fileInfos) {
|
|||||||
// we can still run the app without those files
|
// we can still run the app without those files
|
||||||
const msg = `<b>${fileInfos.name}</b>: File ${name}.json not found in archive.`;
|
const msg = `<b>${fileInfos.name}</b>: File ${name}.json not found in archive.`;
|
||||||
console.warn(msg);
|
console.warn(msg);
|
||||||
Alpine.store("ui").logMsg(msg, "warn");
|
marlConsole(msg, "warn");
|
||||||
Alpine.store("files").sources[index].loaded[name] = true;
|
Alpine.store("files").sources[index].loaded[name] = true;
|
||||||
} else {
|
} else {
|
||||||
// this should NOT happen and will prevent the app from running
|
// this should NOT happen and will prevent the app from running
|
||||||
const msg = `<b>Critical error - ${fileInfos.name}</b>: File ${name}.json not found in archive.`;
|
const msg = `<b>Critical error - ${fileInfos.name}</b>: File ${name}.json not found in archive.`;
|
||||||
console.error(msg);
|
console.error(msg);
|
||||||
Alpine.store("ui").logMsg(msg, "error");
|
marlConsole(msg, "error");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -625,7 +629,7 @@ function detectLangFromBrowser() {
|
|||||||
const msg = `Setting language based on browser preference: <b>'${lang}' (${
|
const msg = `Setting language based on browser preference: <b>'${lang}' (${
|
||||||
Alpine.store("ui").appLangs[lang]
|
Alpine.store("ui").appLangs[lang]
|
||||||
})</b>`;
|
})</b>`;
|
||||||
Alpine.store("ui").logMsg(msg, "info");
|
marlConsole(msg, "info");
|
||||||
return lang;
|
return lang;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -640,7 +644,7 @@ function setLang() {
|
|||||||
document.getElementsByTagName("html")[0].setAttribute("lang", lang);
|
document.getElementsByTagName("html")[0].setAttribute("lang", lang);
|
||||||
|
|
||||||
const msg = `App language set to <b>'${lang}' (${Alpine.store("ui").appLangs[lang]})</b>`;
|
const msg = `App language set to <b>'${lang}' (${Alpine.store("ui").appLangs[lang]})</b>`;
|
||||||
Alpine.store("ui").logMsg(msg);
|
marlConsole(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setTheme(theme) {
|
function setTheme(theme) {
|
||||||
|
Reference in New Issue
Block a user