2017-11-04 17:32:18 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const $ = require("jquery");
|
|
|
|
const socket = require("../socket");
|
2017-11-07 20:22:16 +00:00
|
|
|
const webpush = require("../webpush");
|
2018-09-03 07:30:05 +00:00
|
|
|
const upload = require("../upload");
|
2019-11-02 19:40:59 +00:00
|
|
|
const store = require("../store").default;
|
2019-11-12 10:39:46 +00:00
|
|
|
const router = require("../router");
|
2017-11-04 17:32:18 +00:00
|
|
|
|
2018-06-05 12:29:43 +00:00
|
|
|
window.addEventListener("beforeinstallprompt", (installPromptEvent) => {
|
|
|
|
$("#webapp-install-button")
|
|
|
|
.on("click", function() {
|
|
|
|
if (installPromptEvent && installPromptEvent.prompt) {
|
|
|
|
installPromptEvent.prompt();
|
|
|
|
}
|
|
|
|
|
|
|
|
$(this).prop("hidden", true);
|
|
|
|
})
|
|
|
|
.prop("hidden", false);
|
2018-08-18 19:48:58 +00:00
|
|
|
|
|
|
|
$("#native-app").prop("hidden", false);
|
2018-06-05 12:29:43 +00:00
|
|
|
});
|
|
|
|
|
2019-11-05 12:30:45 +00:00
|
|
|
socket.once("configuration", function(data) {
|
2019-11-02 19:40:59 +00:00
|
|
|
store.commit("serverConfiguration", data);
|
2017-11-04 17:32:18 +00:00
|
|
|
|
2019-11-05 20:51:55 +00:00
|
|
|
// 'theme' setting depends on serverConfiguration.themes so
|
|
|
|
// settings cannot be applied before this point
|
|
|
|
store.dispatch("settings/applyAll");
|
2019-11-12 11:09:12 +00:00
|
|
|
socket.emit("setting:get");
|
2019-11-05 20:51:55 +00:00
|
|
|
|
2018-09-03 07:30:05 +00:00
|
|
|
if (data.fileUpload) {
|
2019-11-12 11:09:12 +00:00
|
|
|
upload.initialize();
|
2018-09-03 07:30:05 +00:00
|
|
|
}
|
|
|
|
|
2017-11-07 20:22:16 +00:00
|
|
|
webpush.initialize();
|
2019-11-12 10:39:46 +00:00
|
|
|
router.initialize();
|
2017-11-07 20:22:16 +00:00
|
|
|
|
2018-04-02 04:25:45 +00:00
|
|
|
// If localStorage contains a theme that does not exist on this server, switch
|
|
|
|
// back to its default theme.
|
2019-11-03 18:05:19 +00:00
|
|
|
const currentTheme = data.themes.find((t) => t.name === store.state.settings.theme);
|
2019-07-22 16:50:04 +00:00
|
|
|
|
|
|
|
if (currentTheme === undefined) {
|
2019-11-05 20:51:55 +00:00
|
|
|
store.commit("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"]').content = currentTheme.themeColor;
|
2018-04-02 04:25:45 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 11:09:12 +00:00
|
|
|
if (document.body.classList.contains("public")) {
|
|
|
|
window.addEventListener(
|
|
|
|
"beforeunload",
|
|
|
|
() => "Are you sure you want to navigate away from this page?"
|
|
|
|
);
|
2018-06-19 15:00:07 +00:00
|
|
|
}
|
|
|
|
});
|