diff --git a/server/server.js b/server/server.js index cdfe18dec..5e4ff2b96 100644 --- a/server/server.js +++ b/server/server.js @@ -135,6 +135,7 @@ const { cloudflaredSocketHandler, autoStart: cloudflaredAutoStart, stop: cloudfl const { proxySocketHandler } = require("./socket-handlers/proxy-socket-handler"); const { dockerSocketHandler } = require("./socket-handlers/docker-socket-handler"); const { maintenanceSocketHandler } = require("./socket-handlers/maintenance-socket-handler"); +const { generalSocketHandler } = require("./socket-handlers/general-socket-handler"); const { Settings } = require("./settings"); const { CacheableDnsHttpAgent } = require("./cacheable-dns-http-agent"); @@ -1488,6 +1489,7 @@ let needSetup = false; proxySocketHandler(socket); dockerSocketHandler(socket); maintenanceSocketHandler(socket); + generalSocketHandler(socket, server); log.debug("server", "added all socket handlers"); @@ -1610,6 +1612,13 @@ async function afterLogin(socket, user) { for (let monitorID in monitorList) { await Monitor.sendStats(io, monitorID, user.id); } + + // Set server timezone from client browser if not set + // It should be run once only + if (! await Settings.get("initServerTimezone")) { + log.debug("server", "emit initServerTimezone"); + socket.emit("initServerTimezone"); + } } /** diff --git a/server/socket-handlers/general-socket-handler.js b/server/socket-handlers/general-socket-handler.js new file mode 100644 index 000000000..a0239733f --- /dev/null +++ b/server/socket-handlers/general-socket-handler.js @@ -0,0 +1,18 @@ +const { log } = require("../../src/util"); +const { Settings } = require("../settings"); +const { sendInfo } = require("../client"); + +module.exports.generalSocketHandler = (socket, server) => { + + socket.on("initServerTimezone", async (timezone) => { + try { + log.debug("generalSocketHandler", "Timezone: " + timezone); + await Settings.set("initServerTimezone", true); + await server.setTimezone(timezone); + await sendInfo(socket); + } catch (e) { + + } + }); + +}; diff --git a/src/mixins/socket.js b/src/mixins/socket.js index ef18a6e99..7e3be52c2 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -2,6 +2,7 @@ import { io } from "socket.io-client"; import { useToast } from "vue-toastification"; import jwtDecode from "jwt-decode"; import Favico from "favico.js"; +import dayjs from "dayjs"; const toast = useToast(); let socket; @@ -271,6 +272,10 @@ export default { socket.on("cloudflared_message", (res) => this.cloudflared.message = res); socket.on("cloudflared_errorMessage", (res) => this.cloudflared.errorMessage = res); socket.on("cloudflared_token", (res) => this.cloudflared.cloudflareTunnelToken = res); + + socket.on("initServerTimezone", () => { + socket.emit("initServerTimezone", dayjs.tz.guess()); + }); }, /**