diff options
| author | Arman <[email protected]> | 2018-08-02 18:58:39 -0700 |
|---|---|---|
| committer | Arman <[email protected]> | 2018-08-02 18:58:39 -0700 |
| commit | eb8d225fe90871bca5431fcede62c942cdfd20ac (patch) | |
| tree | 90e04e518135f0ac1ebcfb504dcef1905249bdee | |
| parent | inital commit (diff) | |
| download | launcher-eb8d225fe90871bca5431fcede62c942cdfd20ac.tar.xz launcher-eb8d225fe90871bca5431fcede62c942cdfd20ac.zip | |
Add custom path
| -rw-r--r-- | .vscode/settings.json | 3 | ||||
| -rw-r--r-- | addWindow.html | 77 | ||||
| -rw-r--r-- | config.json | 1 | ||||
| -rw-r--r-- | login.css | 77 | ||||
| -rw-r--r-- | trumagic.js | 86 |
5 files changed, 229 insertions, 15 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3b66410 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "git.ignoreLimitWarning": true +}
\ No newline at end of file diff --git a/addWindow.html b/addWindow.html index 747c53c..12a26b8 100644 --- a/addWindow.html +++ b/addWindow.html @@ -1,23 +1,82 @@ <!DOCTYPE html> <html lang="en"> <head> - <title>Add Shopping List Item</title> + <title>Specify Path</title> + <link rel="stylesheet" href="login.css"> + <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg"> </head> <body> - <div class="container"> - <form> - <div> - <label>Enter Item</label> - <input type="text" id="item" autofocus> - </div> - <button class="btn waves-effect waves-light" type="submit">Add Item</button> - </form> + <div class="controls"></div> + <div class="path-container"> + <h1>Game Path</h1> + <p>Specify the path to your 'Wizard101' folder</p> + <input type="text" id="game-path" class="keyBox"/> + <button id="browse">Browse</button> + <div class="buttons"> + <div class="roundBtn is-light-gray" id="save"><i class="far fa-save"></i> +Save</div> + <div class="roundBtn is-red" id="reset"><i class="fas fa-sync-alt"></i> +Reset</div> + </div> + + </div> <script> const electron = require('electron'); const {ipcRenderer} = electron; + const { remote } = require('electron') + + const browseBtn = document.getElementById('browse'); + const pathInput = document.getElementById('game-path'); + const save = document.getElementById('save'); + const reset = document.getElementById('reset'); + + let resetPath = "N/A"; + let currentPath = "N/A"; + + // Request some stuff from the main process when window loads + document.addEventListener('DOMContentLoaded', function () { + ipcRenderer.send('request:reset'); + ipcRenderer.send('request:current'); + }); + + // Get original path for reset + ipcRenderer.on('reset:path', function(e, path) { + resetPath = path; + }); + // Get current path + ipcRenderer.on('current:path', function(e, path) { + currentPath = path; + pathInput.value = currentPath; + }); + + browseBtn.addEventListener('click', function(e) { + e.preventDefault(); + const pathArray = remote.dialog.showOpenDialog({ properties: ['openDirectory'] }) + pathInput.value = pathArray; + }); + + save.addEventListener('click', function(e) { + const newPath = pathInput.value; + if (newPath.length == 0) { + alert("Path is empty"); + } + else { + ipcRenderer.send('path:change', newPath); + let notif = new Notification('Configuration Updated', { + body: 'New game path successfully saved', + icon: 'https://i.imgur.com/FQNnvrd.png', + image: 'https://i.imgur.com/FQNnvrd.png' + }); + } + }); + + reset.addEventListener('click', function(e) { + pathInput.value = resetPath; + }); + const form = document.querySelector('form'); form.addEventListener('submit', submitForm); diff --git a/config.json b/config.json new file mode 100644 index 0000000..7aecb97 --- /dev/null +++ b/config.json @@ -0,0 +1 @@ +{"customPath":"~/.wine/drive_c/ProgramData/Kingsisle Entertainment/Wizard101","macDefault":"~/.wine/drive_c/ProgramData/Kingsisle Entertainment/Wizard101","winDefault":"C:\\ProgramData\\KingsIsle Entertainment\\Wizard101"}
\ No newline at end of file @@ -8,7 +8,7 @@ body { margin: 0px; - + font-family: 'Open Sans', sans-serif; background: url("assets/stars.svg"), #4e54c8; /* fallback for old browsers */ background: url("assets/stars.svg"), -webkit-linear-gradient(to right, #6c3fd7, #4e54c8); /* Chrome 10-25, Safari 5.1-6 */ background: url("assets/stars.svg"), linear-gradient(to right, #6c3fd7, #4e54c8); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */ @@ -81,12 +81,11 @@ img { } input[type="text"] { - font: 15px/24px "Open Sans", sans-serif; + font: 12px "Open Sans", sans-serif; text-align: center; color: white; - width: 200px; + width: 300px; box-sizing: border-box; - letter-spacing: 1px; margin-right: auto; margin-left: auto; cursor: default; @@ -176,3 +175,73 @@ a[href^="ftp://"] { -webkit-user-drag: auto; user-drag: auto; /* Technically not supported in Electron yet */ } + +.path-container { + padding: 10px; + text-align: center; +} + +.path-container h1 { + font-family: 'Montserrat', sans-serif; + color: white; + text-align: center; +} + +.path-container p { + text-align: center; +} + +button[id="browse"] { + margin-left: 5px; + outline: none; + border: none; + background: white; + font-family: 'Open Sans', sans-serif; + font-size: 12px; + border-radius: 20px; + cursor: pointer; + width: 60px; + text-align: center; +} + +button[id="browse"]:active { + transform: translateY(.4vw); +} + +.roundBtn { + display: inline-block; + border: none; + text-align: center; + padding: 1.2vw 3vw 1vw; + border-radius: 0.2vw; + margin: 1.3vw; + font-size: 14px; + outline: none; + cursor: pointer; + transition: all .15s; + color: white; + width: 100px; + border-radius: 20px; +} + +.is-light-gray { + background: white; + color: black; +} + +.is-red { + background: #ff6b81; + color: white; +} + +.roundBtn:active { + transform: translateY(.4vw); +} + +.buttons { + margin-top: 25px; +} + +.buttons i { + margin-right: 5px; +}
\ No newline at end of file diff --git a/trumagic.js b/trumagic.js index 8976232..c976c29 100644 --- a/trumagic.js +++ b/trumagic.js @@ -2,6 +2,7 @@ const electron = require('electron'); const url = require('url'); const path = require('path'); const exec = require('child_process').exec; +const fs = require('fs'); const {app, BrowserWindow, Menu, ipcMain} = electron; @@ -34,6 +35,80 @@ app.on('ready', function() { }); +// Handle creating the path window +function createChangeWindow() { + pathWindow = new BrowserWindow({ + width: 400, + height: 280, + frame: false, + titleBarStyle: 'hidden-inset', + resizable: false, + title: 'Specify Path' + }); + // Load html + pathWindow.loadURL(url.format({ + pathname: path.join(__dirname, 'addWindow.html'), + protocol: 'file:', + slashes: true + })); + pathWindow.on('close', function() { + pathWindow = null; + }); +} + +// Path configuration +let config; + +reloadConfig = (callback) => { + fs.readFile('./config.json', 'utf-8', (err, data) => { + if (err) throw err; + config = JSON.parse(data); + if (callback) { + callback(); + } + }); +} + +saveConfig = (configSettings) => { + let content = JSON.stringify(configSettings); + fs.writeFile("./config.json", content, 'utf8', function (err) { + if (err) { + return console.log(err); + } + console.log("Config updated"); + }); + reloadConfig(() => { + console.log("Reloading config"); + }); +} + +// Initially load config +reloadConfig(() => { + if (!config.customPath) { + config.customPath = process.platform == 'darwin' ? config.macDefault : config.winDefault; + saveConfig(config); + } +}); + +// Set custom path to default if nothing set + +// Path change +ipcMain.on('path:change', function(e, newPath) { + config.customPath = newPath; + saveConfig(config); +}); + +// Path request +ipcMain.on('request:reset', function(e) { + let resetPath = process.platform == 'darwin' ? config.macDefault : config.winDefault; + pathWindow.webContents.send('reset:path', resetPath); +}); + +// Path request +ipcMain.on('request:current', function(e) { + let currentPath = config.customPath; + pathWindow.webContents.send('current:path', currentPath); +}); // Catch quit ipcMain.on('app:quit', function(e) { @@ -49,10 +124,10 @@ ipcMain.on('app:minimize', function(e) { ipcMain.on('game:start', function(e) { let command; if (process.platform == 'darwin') { - command = 'wine ~/.wine/drive_c/ProgramData/Kingsisle\\ Entertainment/Wizard101/Bin/WizardGraphicalClient.exe -L login.us.wizard101.com 12000 -A English'; + command = `wine ${config.customPath}/Bin/WizardGraphicalClient.exe -L login.us.wizard101.com 12000 -A English`; } else { - command = 'C:\ProgramData\KingsIsle Entertainment\Wizard101\Bin\WizardGraphicalClient.exe -L login.us.wizard101.com 12000 -A English' + command = `${config.customPath}\Bin\WizardGraphicalClient.exe -L login.us.wizard101.com 12000 -A English` } mainWindow.webContents.send('started'); @@ -74,6 +149,13 @@ const mainMenuTemplate = [ label: 'File', submenu: [ { + label: 'Specify Path', + accelerator: process.platform == 'darwin' ? 'Command+M' : 'Ctrl+M', + click() { + createChangeWindow(); + } + }, + { label: 'Quit', accelerator: process.platform == 'darwin' ? 'Command+Q' : 'Ctrl+Q', click(){ |