From 8b639a1d52040bb9814d6ed48b9611600fc2704c Mon Sep 17 00:00:00 2001 From: Summet-V Date: Fri, 17 Jul 2020 03:02:47 +0300 Subject: [PATCH] Info functionality --- package.json | 1 - src/app/components/menu.js | 10 +++++++++- src/app/window.html | 6 +++--- src/main-process/server.js | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7fe929e..25472df 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,6 @@ "version": "1.0.0", "description": "An advanced control panel for Mindustry server.", "main": "./src/main-process/main.js", - "types": "./src/typings/server-console.d.ts", "license": "GPL-3.0-or-later", "private": true, "author": { diff --git a/src/app/components/menu.js b/src/app/components/menu.js index c6473e6..2ba6494 100644 --- a/src/app/components/menu.js +++ b/src/app/components/menu.js @@ -10,7 +10,7 @@ class Menu { this.playersValue = document.getElementById('menu-info-players-value'); this.mapsValue = document.getElementById('menu-info-maps-value'); - this.modsValue = document.getElementById('menu-info-maps-value'); + this.modsValue = document.getElementById('menu-info-mods-value'); this.pluginsValue = document.getElementById('menu-info-plugins-value'); this.hostButton = document.getElementById('menu-host'); @@ -40,6 +40,14 @@ class Menu { async update() { this.setCpuUsage(await cpuUsagePercent()); this.setRamUsage(await ramUsagePercent()); + + // Get custom maps + 12 default + this.setMaps(ipcRenderer.sendSync('maps').length + 12); + + // TODO: Baaaaad code + const mods = ipcRenderer.sendSync('mods').length; + this.setMods(mods); + this.setPlugins(mods); } setRamUsage(value) { diff --git a/src/app/window.html b/src/app/window.html index b31fd6a..cac817b 100644 --- a/src/app/window.html +++ b/src/app/window.html @@ -52,17 +52,17 @@ diff --git a/src/main-process/server.js b/src/main-process/server.js index 01ec76b..6796f3c 100644 --- a/src/main-process/server.js +++ b/src/main-process/server.js @@ -1,6 +1,7 @@ const { BrowserWindow, shell, ipcMain } = require('electron'); const { EventEmitter } = require('events'); const { spawn } = require('child_process'); +const fs = require('fs'); const path = require('path'); const { playerJoin, playerLeave } = require('../server-messages'); @@ -8,6 +9,10 @@ class Server extends EventEmitter { constructor(options) { super(); this.serverPath = options.serverPath; + this.configPath = path.join(this.serverPath, 'config'); + this.mapsPath = path.join(this.configPath, 'maps'); + this.modsPath = path.join(this.configPath, 'mods'); + this.loaded = false; this.start(); @@ -31,6 +36,16 @@ class Server extends EventEmitter { ipcMain.on('restart', () => this.restart()); ipcMain.on('openFolder', () => this.openFolder()); + ipcMain.on('maps', async (event) => { + // eslint-disable-next-line no-param-reassign + event.returnValue = await this.getMaps(); + }); + + ipcMain.on('mods', async (event) => { + // eslint-disable-next-line no-param-reassign + event.returnValue = await this.getMods(); + }); + this.on('output', (message) => { this.sendToWindow('output', message); @@ -63,6 +78,23 @@ class Server extends EventEmitter { this.write(`${text}\n`); } + readConfigFolder(folder) { + return new Promise((resolve) => { + fs.readdir(folder, (err, files) => { + if (err) throw err; + resolve(files); + }); + }); + } + + getMaps() { + return this.readConfigFolder(this.mapsPath); + } + + getMods() { + return this.readConfigFolder(this.modsPath); + } + openFolder() { shell.openExternal(path.join(this.serverPath, 'config')); }