2018-07-06 20:15:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2019-12-17 23:10:50 +01:00
|
|
|
const constants = require("./constants");
|
|
|
|
|
2020-01-22 17:42:31 +01:00
|
|
|
import "../css/style.css";
|
2021-03-29 04:55:35 +02:00
|
|
|
import {createApp} from "vue";
|
2019-11-16 18:24:03 +01:00
|
|
|
import store from "./store";
|
|
|
|
import App from "../components/App.vue";
|
|
|
|
import storage from "./localStorage";
|
2021-03-29 04:55:35 +02:00
|
|
|
import {router} from "./router";
|
2020-03-16 18:58:40 +01:00
|
|
|
import eventbus from "./eventbus";
|
2018-07-06 20:15:15 +02:00
|
|
|
|
2019-11-16 18:24:03 +01:00
|
|
|
import "./socket-events";
|
|
|
|
import "./webpush";
|
|
|
|
import "./keybinds";
|
2019-11-12 16:51:40 +01:00
|
|
|
|
2019-11-08 01:03:41 +01:00
|
|
|
const favicon = document.getElementById("favicon");
|
|
|
|
const faviconNormal = favicon.getAttribute("href");
|
|
|
|
const faviconAlerted = favicon.dataset.other;
|
|
|
|
|
2021-03-29 04:55:35 +02:00
|
|
|
const vueApp = createApp(App);
|
|
|
|
vueApp.use(store);
|
|
|
|
vueApp.use(router);
|
|
|
|
// https://next.router.vuejs.org/guide/migration/#removal-of-router-app
|
|
|
|
router.app = vueApp;
|
2020-02-25 10:16:05 +01:00
|
|
|
|
2021-03-29 04:55:35 +02:00
|
|
|
vueApp.mount("#viewport-mount");
|
2018-07-06 20:15:15 +02:00
|
|
|
|
2019-11-08 00:47:45 +01:00
|
|
|
store.watch(
|
|
|
|
(state) => state.sidebarOpen,
|
|
|
|
(sidebarOpen) => {
|
2019-12-01 19:20:37 +01:00
|
|
|
if (window.innerWidth > constants.mobileViewportPixels) {
|
2019-11-08 00:47:45 +01:00
|
|
|
storage.set("thelounge.state.sidebar", sidebarOpen);
|
2020-03-16 18:58:40 +01:00
|
|
|
eventbus.emit("resize");
|
2019-11-08 00:47:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-11-08 00:50:51 +01:00
|
|
|
store.watch(
|
|
|
|
(state) => state.userlistOpen,
|
|
|
|
(userlistOpen) => {
|
|
|
|
storage.set("thelounge.state.userlist", userlistOpen);
|
2020-03-16 18:58:40 +01:00
|
|
|
eventbus.emit("resize");
|
2019-11-08 00:50:51 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-11-08 00:53:04 +01:00
|
|
|
store.watch(
|
|
|
|
(_, getters) => getters.title,
|
|
|
|
(title) => {
|
|
|
|
document.title = title;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-11-08 01:03:41 +01:00
|
|
|
// Toggles the favicon to red when there are unread notifications
|
|
|
|
store.watch(
|
|
|
|
(_, getters) => getters.highlightCount,
|
|
|
|
(highlightCount) => {
|
|
|
|
favicon.setAttribute("href", highlightCount > 0 ? faviconAlerted : faviconNormal);
|
2020-04-22 13:16:39 +02:00
|
|
|
|
|
|
|
if (navigator.setAppBadge) {
|
|
|
|
if (highlightCount > 0) {
|
|
|
|
navigator.setAppBadge(highlightCount);
|
|
|
|
} else {
|
|
|
|
navigator.clearAppBadge();
|
|
|
|
}
|
|
|
|
}
|
2019-11-08 01:03:41 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-03-29 04:55:35 +02:00
|
|
|
vueApp.config.errorHandler = function (e) {
|
2019-11-02 20:40:59 +01:00
|
|
|
store.commit("currentUserVisibleError", `Vue error: ${e.message}`);
|
2018-09-14 17:44:26 +02:00
|
|
|
console.error(e); // eslint-disable-line
|
|
|
|
};
|
2021-03-29 04:55:35 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
app: vueApp,
|
|
|
|
};
|