From e48328aac858537871c29953d9f4f2316e0c39dd Mon Sep 17 00:00:00 2001 From: LawnCable Date: Wed, 23 May 2018 22:08:48 -0400 Subject: - BugFix on open screenshot folder - moved the run function into the cross platform file - when you launch the game, the launcher windows gets closed an appears now as Tray Icon --- src/main/manaplus/manaplus.ts | 61 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 5 deletions(-) (limited to 'src/main/manaplus/manaplus.ts') diff --git a/src/main/manaplus/manaplus.ts b/src/main/manaplus/manaplus.ts index b69190d..da8d6d5 100644 --- a/src/main/manaplus/manaplus.ts +++ b/src/main/manaplus/manaplus.ts @@ -3,11 +3,13 @@ import { ManaPlusAppWindows } from './ManaApp/windows'; import * as os from 'os'; import * as path from 'path'; import * as fs from 'fs-extra'; -import { app, ipcMain } from 'electron'; -import { Status } from '../status'; +import { app, ipcMain, shell } from 'electron'; +import { Status, EventEmitter } from '../status'; let ManaPlusInstance:ManaPlusApp; +let CurrentServer:{serverID:string,address:string}=null; + export namespace ManaPlus{ export const ERRORS = { @@ -29,10 +31,14 @@ export namespace ManaPlus{ - export async function start(server: any,port: any,engine: any,username: any,password: any){ + export async function start(args: any){ + CurrentServer={ + serverID:args.serverID, + address:args.address + }; let params:string[]; try { - params = await makeParams(server,port,engine,username,password); + params = await makeParams(args.address,args.port,args.engine,args.username,args.password); } catch (e){ console.log(e); Status.showError("Launch Preperation Failed", e.message, "Launch preparation failed") @@ -50,8 +56,20 @@ export namespace ManaPlus{ } //IDEA have client data updated here to, if needed - ManaPlusInstance.run(params); + + // Run it + Status.setGameRunning(true); + EventEmitter.emit('closeWindow'); + EventEmitter.emit('openTray'); + await runManaProgram(params,ManaPlusInstance.startCommand); + // On Close + Status.setGameRunning(false); + Status.setPlaying(false); + Status.removeActivity(); + EventEmitter.emit('reopenWindow'); + EventEmitter.emit('closeTray'); + CurrentServer=null; } } @@ -66,6 +84,9 @@ ipcMain.on('getScreenshots', (event:any, arg:string)=> { event.sender.send('getScreenshots', {dir:screenshotsDir, screenshots:screenshots.reverse().slice(0, 24)}); }); }); +EventEmitter.on('Mana:openScreenshotDir', ()=>{ + shell.openItem(path.normalize(app.getPath('userData')+`/screenshots/${CurrentServer.address}/`)); +}); function wasInitilized(){ return typeof(ManaPlusInstance) !== "undefined" && typeof(ManaPlusInstance) !== "undefined"; @@ -102,3 +123,33 @@ async function makeParams(server: any,port: any,engine: any,username?: any,passw return parameters; } + +let manaplusInstance: any=null; + +function runManaProgram(parameters: string[],gameExe:string): Promise { + return new Promise((resolve, reject)=>{ + Status.setActivity(`Starting ManaPlus`); + + console.log(gameExe, parameters); + const child = require('child_process').execFile(gameExe, parameters, function(err:Error, data:any) { + console.log(err); + console.log(data.toString()); + Status.setActivity(`ManaPlus is running`); + }); + child.on('close', ()=>{ + manaplusInstance = null; + resolve(); + }); + child.on('error', ()=>{ + manaplusInstance = null; + resolve(); + //// TODO: Handle Error + }); + manaplusInstance = child; + }); +} + +EventEmitter.on("Mana:killMana",()=>{ + if(manaplusInstance && manaplusInstance !== null) + manaplusInstance.kill('SIGINT'); +}); -- cgit v1.2.3-60-g2f50