hardlounge/client/js/socket-events/configuration.ts

38 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2019-11-16 17:24:03 +00:00
import socket from "../socket";
import upload from "../upload";
import {store} from "../store";
socket.once("configuration", function (data) {
store.commit("serverConfiguration", data);
// 'theme' setting depends on serverConfiguration.themes so
// settings cannot be applied before this point
void store.dispatch("settings/applyAll");
if (data.fileUpload) {
2019-11-12 11:09:12 +00:00
upload.initialize();
}
// If localStorage contains a theme that does not exist on this server, switch
// back to its default theme.
const currentTheme = data.themes.find((t) => t.name === store.state.settings.theme);
2019-07-22 16:50:04 +00:00
if (currentTheme === undefined) {
void store.dispatch("settings/update", {
name: "theme",
value: data.defaultTheme,
sync: true,
});
2019-07-22 16:50:04 +00:00
} else if (currentTheme.themeColor) {
(document.querySelector('meta[name="theme-color"]') as HTMLMetaElement).content =
currentTheme.themeColor;
}
2019-11-12 11:09:12 +00:00
if (document.body.classList.contains("public")) {
2019-12-18 09:28:39 +00:00
window.addEventListener("beforeunload", (e) => {
e.preventDefault();
e.returnValue = "Are you sure you want to navigate away from this page?";
});
2018-06-19 15:00:07 +00:00
}
});