2018-07-06 14:15:15 -04:00
|
|
|
"use strict";
|
|
|
|
|
2019-12-17 17:10:50 -05:00
|
|
|
const constants = require("./constants");
|
|
|
|
|
2020-01-22 11:42:31 -05:00
|
|
|
import "../css/style.css";
|
2019-11-16 12:24:03 -05: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";
|
2020-03-16 13:58:40 -04:00
|
|
|
import eventbus from "./eventbus";
|
2018-07-06 14:15:15 -04:00
|
|
|
|
2019-11-16 12:24:03 -05:00
|
|
|
import "./socket-events";
|
|
|
|
import "./webpush";
|
|
|
|
import "./keybinds";
|
2019-11-12 10:51:40 -05:00
|
|
|
|
2019-11-07 19:03:41 -05:00
|
|
|
const favicon = document.getElementById("favicon");
|
|
|
|
const faviconNormal = favicon.getAttribute("href");
|
|
|
|
const faviconAlerted = favicon.dataset.other;
|
|
|
|
|
2020-03-16 13:58:40 -04:00
|
|
|
new Vue({
|
2018-07-06 14:15:15 -04:00
|
|
|
el: "#viewport",
|
2019-10-17 12:56:44 -04:00
|
|
|
router,
|
2018-07-10 05:40:55 -04:00
|
|
|
mounted() {
|
2019-11-12 10:51:40 -05:00
|
|
|
socket.open();
|
2018-07-10 05:40:55 -04:00
|
|
|
},
|
2019-04-13 16:44:04 -04:00
|
|
|
methods: {
|
2019-10-25 17:37:40 -04:00
|
|
|
switchToChannel(channel) {
|
2019-11-11 14:18:55 -05:00
|
|
|
navigate("RoutedChat", {id: channel.id});
|
2019-10-17 12:56:44 -04:00
|
|
|
},
|
2019-11-23 11:44:23 -05:00
|
|
|
closeChannel(channel) {
|
2019-11-23 14:53:33 -05:00
|
|
|
if (channel.type === "lobby") {
|
2020-03-16 13:58:40 -04:00
|
|
|
eventbus.emit(
|
2020-02-25 04:16:05 -05:00
|
|
|
"confirm-dialog",
|
|
|
|
{
|
|
|
|
title: "Remove network",
|
|
|
|
text: `Are you sure you want to quit and remove ${channel.name}? This cannot be undone.`,
|
|
|
|
button: "Remove network",
|
|
|
|
},
|
|
|
|
(result) => {
|
|
|
|
if (!result) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel.closed = true;
|
|
|
|
socket.emit("input", {
|
|
|
|
target: Number(channel.id),
|
|
|
|
text: "/quit",
|
|
|
|
});
|
|
|
|
}
|
2019-11-23 14:53:33 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
2019-11-23 11:44:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
channel.closed = true;
|
|
|
|
|
|
|
|
socket.emit("input", {
|
|
|
|
target: Number(channel.id),
|
2019-11-23 14:53:33 -05:00
|
|
|
text: "/close",
|
2019-11-23 11:44:23 -05:00
|
|
|
});
|
|
|
|
},
|
2019-04-13 16:44:04 -04:00
|
|
|
},
|
2018-07-06 14:15:15 -04:00
|
|
|
render(createElement) {
|
|
|
|
return createElement(App, {
|
2019-02-18 04:18:32 -05:00
|
|
|
ref: "app",
|
2018-07-06 14:15:15 -04:00
|
|
|
props: this,
|
|
|
|
});
|
|
|
|
},
|
2019-02-26 15:23:41 -05:00
|
|
|
store,
|
2018-07-06 14:15:15 -04:00
|
|
|
});
|
|
|
|
|
2019-11-07 18:47:45 -05:00
|
|
|
store.watch(
|
|
|
|
(state) => state.sidebarOpen,
|
|
|
|
(sidebarOpen) => {
|
2019-12-01 13:20:37 -05:00
|
|
|
if (window.innerWidth > constants.mobileViewportPixels) {
|
2019-11-07 18:47:45 -05:00
|
|
|
storage.set("thelounge.state.sidebar", sidebarOpen);
|
2020-03-16 13:58:40 -04:00
|
|
|
eventbus.emit("resize");
|
2019-11-07 18:47:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-11-07 18:50:51 -05:00
|
|
|
store.watch(
|
|
|
|
(state) => state.userlistOpen,
|
|
|
|
(userlistOpen) => {
|
|
|
|
storage.set("thelounge.state.userlist", userlistOpen);
|
2020-03-16 13:58:40 -04:00
|
|
|
eventbus.emit("resize");
|
2019-11-07 18:50:51 -05:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-11-07 18:53:04 -05:00
|
|
|
store.watch(
|
|
|
|
(_, getters) => getters.title,
|
|
|
|
(title) => {
|
|
|
|
document.title = title;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-11-07 19:03:41 -05: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 07:16:39 -04:00
|
|
|
|
|
|
|
if (navigator.setAppBadge) {
|
|
|
|
if (highlightCount > 0) {
|
|
|
|
navigator.setAppBadge(highlightCount);
|
|
|
|
} else {
|
|
|
|
navigator.clearAppBadge();
|
|
|
|
}
|
|
|
|
}
|
2019-11-07 19:03:41 -05:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-03-21 16:55:36 -04:00
|
|
|
Vue.config.errorHandler = function (e) {
|
2019-11-02 15:40:59 -04:00
|
|
|
store.commit("currentUserVisibleError", `Vue error: ${e.message}`);
|
2018-09-14 11:44:26 -04:00
|
|
|
console.error(e); // eslint-disable-line
|
|
|
|
};
|