Skip to content
This repository has been archived by the owner on May 8, 2021. It is now read-only.

Commit

Permalink
Info functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
antsif-a committed Jul 17, 2020
1 parent 9c0028e commit 8b639a1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 9 additions & 1 deletion src/app/components/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/app/window.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@
</div>
<div class="menu-info-card">
<span class="language-depend" translation="menu-maps"></span>
:&ensp;
:&nbsp;
<span id="menu-info-maps-value">0</span>
</div>
<div class="menu-info-card">
<span class="language-depend" translation="menu-mods"></span>
:&ensp;
:&nbsp;
<span id="menu-info-mods-value">0</span>
</div>
<div class="menu-info-card">
<span class="language-depend" translation="menu-plugins"></span>
:&ensp;
:&nbsp;
<span id="menu-info-plugins-value">0</span>
</div>
</div>
Expand Down
32 changes: 32 additions & 0 deletions src/main-process/server.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
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');

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

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

0 comments on commit 8b639a1

Please sign in to comment.