Skip to content

Commit

Permalink
Added file chooser dialog for the game binary
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepycrow committed Aug 2, 2018
1 parent 1649624 commit 9b6afbd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
23 changes: 22 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, ipcMain } = require('electron');
const { app, ipcMain, dialog } = require('electron');
const ConfigManager = require('./configManager.js');
const MainWindow = require('./mainWindow.js');
const ClientLauncher = require('./clientLauncher.js');
Expand Down Expand Up @@ -34,6 +34,27 @@ ipcMain.on("change-config", (event, data) => {
event.sender.send("config", configManager.config);
});

ipcMain.on("binary-path-change-request", (event, data) => {
console.log("Binary path change request recieved.");

var files = dialog.showOpenDialog({
properties: ["openFile"],
filters: [
{name: "*.exe", extensions: ["exe"]}
],
defaultPath: data.defaultPath || configManager.config.binaryPath
});

console.log("Files selected:", files);

if(typeof files != "undefined"){
configManager.config.binaryPath = files[0];
configManager.save();

event.sender.send("config", configManager.config);
}
});

// Client Launching
ipcMain.on("launch-request", (event, data) => {
console.log("Launch request recieved.");
Expand Down
9 changes: 9 additions & 0 deletions pages/css/css.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ button:hover{
background-color: #ED8C42;
}

.mini{
padding: 4px;
font-size: 16px;
}

.checkbox{
display: inline-block;
width: auto;
Expand Down Expand Up @@ -97,6 +102,10 @@ main{
text-align: center;
}

.config-header{
font-weight: bold;
}

/* loading overlay */
.loading-overlay{
position: fixed;
Expand Down
11 changes: 7 additions & 4 deletions pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</header>

<main id="main-pages">

<input type="text" placeholder="Nickname" name="nickname" id="nickname" />

<section data-tab="join">
Expand Down Expand Up @@ -60,15 +61,17 @@

<section data-tab="config" class="hidden">
<form data-action="config" id="config-form">
<div>Game Binary Location:</div>
<input type="text" id="binary-location" data-index="binaryPath" />
<div class="config-header">Game Binary Location:</div>
<div id="binary-path-preview"></div>
<button id="binary-path-button" class="mini" data-index="binaryPath">Change</button>

<div>Server Port:</div>
<input type="number" data-index="port" id="port" placeholder="Port" value="7777" min="1" max="65535" />
<div class="config-header">Server Port:</div>
<input type="number" data-index="port" id="port" placeholder="7777" min="1" max="65535" />

<button>Save</button>
</form>
</section>

</main>

<script>
Expand Down
18 changes: 15 additions & 3 deletions pages/js/index-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,22 @@ function updateConfig(config){
}

// Add the game's binary to the config tab
var binaryPathInput = document.getElementById("binary-location");
var binaryPathButton = document.getElementById("binary-path-button");
var binaryPathPreview = document.getElementById("binary-path-preview");

if(typeof config.binaryPath == "string" && binaryPathInput != null){
binaryPathInput.value = config.binaryPath;
if(typeof config.binaryPath == "string" && binaryPathButton != null && binaryPathPreview != null){
binaryPathButton.value = config.binaryPath;
binaryPathPreview.innerText = config.binaryPath;
}

// Make the "change binary path" button request a file dialog
if(binaryPathButton != null){
binaryPathButton.onclick = function(e){
e.preventDefault();
ipcRenderer.send("binary-path-change-request", {
defaultPath: config.binaryPath
});
}
}

//Add the port
Expand Down

0 comments on commit 9b6afbd

Please sign in to comment.