From 11fea7badc7b3545c2e428dddcebe1aabfd40562 Mon Sep 17 00:00:00 2001 From: ck <21735205+cyperdark@users.noreply.github.com> Date: Thu, 22 Feb 2024 15:20:51 +0300 Subject: [PATCH] feat: Show `config reloaded` message only on if settings was updated --- packages/common/utils/config.ts | 40 ++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/packages/common/utils/config.ts b/packages/common/utils/config.ts index b2bb11ce..cd30c704 100644 --- a/packages/common/utils/config.ts +++ b/packages/common/utils/config.ts @@ -45,7 +45,8 @@ SERVER_IP=127.0.0.1 # The port on which the websocket api server will run SERVER_PORT=24050 # The folder from which the overlays will be taken. -STATIC_FOLDER_PATH=./static` +STATIC_FOLDER_PATH=./static`, + 'utf8' ); } @@ -107,7 +108,7 @@ export const updateConfigFile = () => { } if (!process.env.ENABLE_GOSU_OVERLAY) { - newOptions += 'nENABLE_GOSU_OVERLAY, '; + newOptions += 'ENABLE_GOSU_OVERLAY, '; fs.appendFileSync(configPath, '\nENABLE_GOSU_OVERLAY=false', 'utf8'); } @@ -127,6 +128,7 @@ export const watchConfigFile = ({ httpServer }: { httpServer: any }) => { }; export const refreshConfig = (httpServer: any, refresh: boolean) => { + let updated = false; const status = refresh == true ? 'reload' : 'load'; const { parsed, error } = dotenv.config({ path: configPath }); @@ -136,9 +138,26 @@ export const refreshConfig = (httpServer: any, refresh: boolean) => { } const debugLogging = (parsed.DEBUG_LOG || '') === 'true'; - const serverIP = parsed.SERVER_IP || '127.0.0.1'; const serverPort = Number(parsed.SERVER_PORT || '24050'); + const calculatePP = (parsed.CALCULATE_PP || '') === 'true'; + const enableKeyOverlay = (parsed.ENABLE_KEY_OVERLAY || '') === 'true'; + const pollRate = Number(parsed.POLL_RATE || '500'); + const keyOverlayPollRate = Number(parsed.KEYOVERLAY_POLL_RATE || '100'); + const staticFolderPath = parsed.STATIC_FOLDER_PATH || './static'; + const enableGosuOverlay = (parsed.ENABLE_GOSU_OVERLAY || '') === 'true'; + + // determine whether config actually was updated or not + updated = + config.debugLogging != debugLogging || + config.calculatePP != calculatePP || + config.enableKeyOverlay != enableKeyOverlay || + config.pollRate != pollRate || + config.keyOverlayPollRate != keyOverlayPollRate || + config.staticFolderPath != staticFolderPath || + config.enableGosuOverlay != enableGosuOverlay || + config.serverIP != serverIP || + config.serverPort != serverPort; if (config.serverIP != serverIP || config.serverPort != serverPort) { config.serverIP = serverIP; @@ -148,12 +167,13 @@ export const refreshConfig = (httpServer: any, refresh: boolean) => { } config.debugLogging = debugLogging; - config.calculatePP = (parsed.CALCULATE_PP || '') === 'true'; - config.enableKeyOverlay = (parsed.ENABLE_KEY_OVERLAY || '') === 'true'; - config.pollRate = Number(parsed.POLL_RATE || '500'); - config.keyOverlayPollRate = Number(parsed.KEYOVERLAY_POLL_RATE || '100'); - config.staticFolderPath = parsed.STATIC_FOLDER_PATH || './static'; - config.enableGosuOverlay = (parsed.ENABLE_GOSU_OVERLAY || '') === 'true'; + config.calculatePP = calculatePP; + config.enableKeyOverlay = enableKeyOverlay; + config.pollRate = pollRate >= 0 ? pollRate : 100; + config.keyOverlayPollRate = + keyOverlayPollRate >= 0 ? keyOverlayPollRate : 100; + config.staticFolderPath = staticFolderPath; + config.enableGosuOverlay = enableGosuOverlay; if ( config.staticFolderPath == './static' && @@ -162,6 +182,6 @@ export const refreshConfig = (httpServer: any, refresh: boolean) => { fs.mkdirSync(path.join(process.cwd(), 'static')); } - wLogger.info(`Config ${status}ed`); + if (updated) wLogger.info(`Config ${status}ed`); configureLogger(); };