Skip to content

Commit

Permalink
feat: Show config reloaded message only on if settings was updated
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark authored and KotRikD committed Feb 28, 2024
1 parent c4cf5e8 commit 11fea7b
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions packages/common/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}

Expand Down Expand Up @@ -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');
}

Expand All @@ -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 });
Expand All @@ -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;
Expand All @@ -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' &&
Expand All @@ -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();
};

0 comments on commit 11fea7b

Please sign in to comment.