2018-07-06 18:15:15 +00:00
|
|
|
"use strict";
|
|
|
|
|
2019-12-17 22:10:50 +00:00
|
|
|
const constants = require("./constants");
|
|
|
|
|
2020-01-22 16:42:31 +00:00
|
|
|
import "../css/style.css";
|
2019-11-16 17:24:03 +00:00
|
|
|
import Vue from "vue";
|
|
|
|
import store from "./store";
|
|
|
|
import App from "../components/App.vue";
|
|
|
|
import storage from "./localStorage";
|
|
|
|
import {router, navigate} from "./router";
|
|
|
|
import socket from "./socket";
|
2018-07-06 18:15:15 +00:00
|
|
|
|
2019-11-16 17:24:03 +00:00
|
|
|
import "./socket-events";
|
|
|
|
import "./webpush";
|
|
|
|
import "./keybinds";
|
2019-11-12 15:51:40 +00:00
|
|
|
|
2019-11-08 00:03:41 +00:00
|
|
|
const favicon = document.getElementById("favicon");
|
|
|
|
const faviconNormal = favicon.getAttribute("href");
|
|
|
|
const faviconAlerted = favicon.dataset.other;
|
|
|
|
|
2018-07-06 18:15:15 +00:00
|
|
|
const vueApp = new Vue({
|
|
|
|
el: "#viewport",
|
2019-10-17 16:56:44 +00:00
|
|
|
router,
|
2018-07-10 09:40:55 +00:00
|
|
|
mounted() {
|
2019-11-12 15:51:40 +00:00
|
|
|
socket.open();
|
2018-07-10 09:40:55 +00:00
|
|
|
},
|
2019-04-13 20:44:04 +00:00
|
|
|
methods: {
|
2019-10-25 21:37:40 +00:00
|
|
|
switchToChannel(channel) {
|
2019-11-11 19:18:55 +00:00
|
|
|
navigate("RoutedChat", {id: channel.id});
|
2019-10-17 16:56:44 +00:00
|
|
|
},
|
2019-11-23 16:44:23 +00:00
|
|
|
closeChannel(channel) {
|
2019-11-23 19:53:33 +00:00
|
|
|
if (channel.type === "lobby") {
|
|
|
|
const el = document.querySelector(
|
2019-12-04 06:58:23 +00:00
|
|
|
`#sidebar .channel-list-item[aria-controls="#chan-${channel.id}"]`
|
2019-11-23 19:53:33 +00:00
|
|
|
);
|
|
|
|
const rect = el.getBoundingClientRect();
|
|
|
|
const event = new MouseEvent("click", {
|
|
|
|
view: window,
|
2020-01-24 14:55:29 +00:00
|
|
|
clientX: rect.left + 10,
|
|
|
|
clientY: rect.top,
|
2019-11-23 19:53:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.$root.$emit("contextmenu:removenetwork", {
|
|
|
|
event: event,
|
|
|
|
lobby: channel,
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
2019-11-23 16:44:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
channel.closed = true;
|
|
|
|
|
|
|
|
socket.emit("input", {
|
|
|
|
target: Number(channel.id),
|
2019-11-23 19:53:33 +00:00
|
|
|
text: "/close",
|
2019-11-23 16:44:23 +00:00
|
|
|
});
|
|
|
|
},
|
2019-04-13 20:44:04 +00:00
|
|
|
},
|
2018-07-06 18:15:15 +00:00
|
|
|
render(createElement) {
|
|
|
|
return createElement(App, {
|
2019-02-18 09:18:32 +00:00
|
|
|
ref: "app",
|
2018-07-06 18:15:15 +00:00
|
|
|
props: this,
|
|
|
|
});
|
|
|
|
},
|
2019-02-26 20:23:41 +00:00
|
|
|
store,
|
2018-07-06 18:15:15 +00:00
|
|
|
});
|
|
|
|
|
2019-11-07 23:47:45 +00:00
|
|
|
store.watch(
|
|
|
|
(state) => state.sidebarOpen,
|
|
|
|
(sidebarOpen) => {
|
2019-12-01 18:20:37 +00:00
|
|
|
if (window.innerWidth > constants.mobileViewportPixels) {
|
2019-11-07 23:47:45 +00:00
|
|
|
storage.set("thelounge.state.sidebar", sidebarOpen);
|
2019-11-24 13:54:24 +00:00
|
|
|
vueApp.$emit("resize");
|
2019-11-07 23:47:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-11-07 23:50:51 +00:00
|
|
|
store.watch(
|
|
|
|
(state) => state.userlistOpen,
|
|
|
|
(userlistOpen) => {
|
|
|
|
storage.set("thelounge.state.userlist", userlistOpen);
|
|
|
|
vueApp.$emit("resize");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-11-07 23:53:04 +00:00
|
|
|
store.watch(
|
|
|
|
(_, getters) => getters.title,
|
|
|
|
(title) => {
|
|
|
|
document.title = title;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-11-08 00:03:41 +00:00
|
|
|
// Toggles the favicon to red when there are unread notifications
|
|
|
|
store.watch(
|
|
|
|
(_, getters) => getters.highlightCount,
|
|
|
|
(highlightCount) => {
|
|
|
|
favicon.setAttribute("href", highlightCount > 0 ? faviconAlerted : faviconNormal);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-09-14 15:44:26 +00:00
|
|
|
Vue.config.errorHandler = function(e) {
|
2019-11-02 19:40:59 +00:00
|
|
|
store.commit("currentUserVisibleError", `Vue error: ${e.message}`);
|
2018-09-14 15:44:26 +00:00
|
|
|
console.error(e); // eslint-disable-line
|
|
|
|
};
|