From 1d6da3e62cfdccc107ff62972c99be3d8f810b8f Mon Sep 17 00:00:00 2001 From: Matt Worzala Date: Sat, 13 Jul 2019 19:40:44 -0400 Subject: [PATCH] profiles have their flavor displayed. the login page will generate a clientKey if it is missing. --- package.json | 6 ++- src/main/config/config.js | 10 ++-- src/main/launcher/LegacyLauncher.js | 63 ------------------------- src/main/launcher/NativeLauncher.js | 73 ----------------------------- src/main/main.js | 13 ++++- src/main/mojang/accounts.js | 4 ++ src/main/mojang/login.html | 6 ++- src/render/profiles/profiles.less | 3 +- 8 files changed, 30 insertions(+), 148 deletions(-) delete mode 100644 src/main/launcher/LegacyLauncher.js delete mode 100644 src/main/launcher/NativeLauncher.js diff --git a/package.json b/package.json index 38727cf..6568264 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "proton", - "version": "0.2.11", + "version": "0.2.12", "description": "A custom minecraft launcher", "private": false, "author": "Matt Worzala ", @@ -57,6 +57,10 @@ "src/**", "*.js" ], + "protocols": [{ + "name": "Proton Launcher", + "schemes": ["proton"] + }], "extends": null, "directories": { "buildResources": "assets" diff --git a/src/main/config/config.js b/src/main/config/config.js index 73f97e9..7d14898 100644 --- a/src/main/config/config.js +++ b/src/main/config/config.js @@ -106,15 +106,13 @@ exports.loadConfig = async () => { while (maxMem % 128 !== 0) maxMem++; - if (!created) { + if (!created) this.setValue('defaults/maxMemory', maxMem / 2); - this.setValue('clientKey', Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)); - } - if (this.getValue('app/instanceDir').length === 0) { + if (this.getValue('app/instanceDir').length === 0) this.setValue('app/instanceDir', path.join(baseDir, 'Instances')); - this.saveConfig(); - } + + this.saveConfig(); }; exports.addEventListener = (target, callback) => { diff --git a/src/main/launcher/LegacyLauncher.js b/src/main/launcher/LegacyLauncher.js deleted file mode 100644 index 0189d15..0000000 --- a/src/main/launcher/LegacyLauncher.js +++ /dev/null @@ -1,63 +0,0 @@ -/* -Copyright (c) 2019 Matt Worzala - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -const EventEmitter = require('events').EventEmitter; - -const spawn = require('child_process').spawn; -const path = require('path'); - -const installDir = path.join(require('electron').app.getPath('userData'), 'Install'); -const launcherFile = path.join(installDir, 'minecraft.jar'); - -class LegacyLauncher extends EventEmitter { - constructor() { - super(); - - this.process = spawn(`java`, ['-jar', launcherFile, '--workDir', installDir], { - stdio: [ 'ignore', 'pipe', 'pipe' ] - }); - - this.process.stdout.setEncoding('UTF-8'); - this.process.stderr.setEncoding('UTF-8'); - - this.process.stdout.on('data', data => { - this.emit('log', data.trim()); - }); - - this.process.stderr.on('data', data => { - this.emit('log', data.trim()); - }); - - this.process.on('close', code => this.emit('stop', code)); - } - - unlink() { - this.emit('disconnect'); - this.process.disconnect(); - } - - destroy() { - this.process.abort(); - } -} - -module.exports = LegacyLauncher; \ No newline at end of file diff --git a/src/main/launcher/NativeLauncher.js b/src/main/launcher/NativeLauncher.js deleted file mode 100644 index 7f66291..0000000 --- a/src/main/launcher/NativeLauncher.js +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright (c) 2019 Matt Worzala - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -const EventEmitter = require('events').EventEmitter; - -const spawn = require('child_process').spawn; -const path = require('path'); - -const aliases = { - win32: 'exe', - darwin: '', - linux: '', - sunos: '', - openbsd: '', - android: '', - aix: '', -}; - -const installDir = path.join(require('electron').app.getPath('userData'), 'Install'); -const launcherFile = path.join(installDir, `minecraft.${aliases[process.platform]}`); - -class NativeLauncher extends EventEmitter { - constructor() { - super(); - - this.process = spawn(launcherFile, ['--workDir', installDir], { - stdio: [ 'ignore', 'pipe', 'pipe' ] - }); - - this.process.stdout.setEncoding('UTF-8'); - this.process.stderr.setEncoding('UTF-8'); - - this.process.stdout.on('data', data => { - this.emit('log', data.trim()); - }); - - this.process.stderr.on('data', data => { - this.emit('log', data.trim()); - }); - - this.process.on('close', code => this.emit('stop', code)); - } - - unlink() { - this.emit('disconnect'); - this.process.disconnect(); - } - - destroy() { - this.process.abort(); - } -} - -module.exports = NativeLauncher; diff --git a/src/main/main.js b/src/main/main.js index 803841e..e6d6338 100644 --- a/src/main/main.js +++ b/src/main/main.js @@ -132,10 +132,19 @@ const createContextMenu = () => { ]) }; const registerUriListeners = () => { + app.setAsDefaultProtocolClient('proton'); + const locked = app.requestSingleInstanceLock(); if (!locked) app.quit(); app.on('second-instance', (event, argv, cwd) => { + console.log('WOW A NEW INSTANCE HAS BEEN LAUNCHED'); + console.log(event); + console.log('--------------------------------'); + console.log(argv); + console.log('--------------------------------'); + console.log(cwd); + console.log('--------------------------------'); mainWindow.show(); }) @@ -170,10 +179,10 @@ app.on('ready', async () => { // createTrayMenu(); // if (process.platform === 'win32') // createContextMenu(); - // registerUriListeners(); + registerUriListeners(); // Send warning about not pasting stuff. - mainWindow.webContents.on('devtools-opened', () => mainWindow.webContents.send('devtools-opened')); + // mainWindow.webContents.on('devtools-opened', () => mainWindow.webContents.send('devtools-opened')); }, 100); }); diff --git a/src/main/mojang/accounts.js b/src/main/mojang/accounts.js index 361c1e5..5251ff0 100644 --- a/src/main/mojang/accounts.js +++ b/src/main/mojang/accounts.js @@ -65,6 +65,10 @@ exports.addAccount = () => { } }); window.loadURL(`file://${__dirname}/login.html`).then(() => ipcMain.on('login:complete', async (event, data) => { + if (data.clientKey !== config.getValue('clientKey')) { + config.setValue('clientKey', data.clientKey); + await config.saveConfig(); + } const acc = await this.getAccount(data.uuid); if (acc != null) { acc.token = data.token; diff --git a/src/main/mojang/login.html b/src/main/mojang/login.html index abbdfad..7f848b5 100644 --- a/src/main/mojang/login.html +++ b/src/main/mojang/login.html @@ -9,8 +9,9 @@ const mojang = require('../mojang/mojang'); const login = async () => { - const clientKey = (await require('fs-extra').readJson(require('path').join(require('electron').remote.app.getPath('userData'), 'launcher_config.json'))).clientKey; - console.log(clientKey); + let clientKey = (await require('fs-extra').readJson(require('path').join(require('electron').remote.app.getPath('userData'), 'launcher_config.json'))).clientKey; + if (!clientKey) + clientKey = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); const username = document.getElementById('username').value; const password = document.getElementById('password').value; const resp = await mojang.login(username, password, clientKey, true); @@ -23,6 +24,7 @@ login: resp.user.username, username: resp.availableProfiles[0].name, selected: false, + clientKey }); } diff --git a/src/render/profiles/profiles.less b/src/render/profiles/profiles.less index 693a360..b5024a6 100644 --- a/src/render/profiles/profiles.less +++ b/src/render/profiles/profiles.less @@ -50,12 +50,13 @@ .profile-flavor { position: absolute; - right: 10px; + right: 15px; top: 10px; font-size: 15px; color: @superOffWhite; text-shadow: 2px 2px @offBlack; + z-index: 5; } img {