summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLawnCable <lawncable.tmw2@simonlaux.de>2018-05-23 22:08:48 -0400
committerLawnCable <lawncable.tmw2@simonlaux.de>2018-05-23 22:08:48 -0400
commite48328aac858537871c29953d9f4f2316e0c39dd (patch)
treedd346610d231b68b33b0298da31a214564fe8af9
parent4ace342635861686f16be98e9969c41c42434147 (diff)
downloadelectron-e48328aac858537871c29953d9f4f2316e0c39dd.tar.gz
electron-e48328aac858537871c29953d9f4f2316e0c39dd.tar.bz2
electron-e48328aac858537871c29953d9f4f2316e0c39dd.tar.xz
electron-e48328aac858537871c29953d9f4f2316e0c39dd.zip
- 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
-rw-r--r--src/main.ts86
-rw-r--r--src/main/manaplus/manaApp/manaApp.interface.ts2
-rw-r--r--src/main/manaplus/manaApp/windows.ts21
-rw-r--r--src/main/manaplus/manaplus.ts61
-rw-r--r--src/main/status.ts15
-rw-r--r--src/renderer/gameserver/server.ts2
6 files changed, 156 insertions, 31 deletions
diff --git a/src/main.ts b/src/main.ts
index d90b4b0..7810495 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1,4 +1,4 @@
-import { app, BrowserWindow, ipcMain, remote } from 'electron';
+import { app, BrowserWindow, ipcMain, remote, Tray, Menu, dialog } from 'electron';
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
@@ -45,7 +45,7 @@ app.on('ready', createWindow);
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
- if (process.platform !== 'darwin') {
+ if (process.platform !== 'darwin' && !Status.getStatus().playing) {
app.quit();
}
});
@@ -59,7 +59,7 @@ app.on('activate', () => {
});
ipcMain.on('quit', (event:any, arg:any)=> {
- app.quit();
+ mainWindow.close();
});
ipcMain.on('minimize', (event:any, arg:any)=> {
@@ -75,7 +75,7 @@ ipcMain.on('debug', (event:any, arg:any)=> {
Status.setActivity("Debug menue Toggled")
});
-import {Status} from './main/status';
+import {Status, EventEmitter} from './main/status';
@@ -83,6 +83,70 @@ import {Status} from './main/status';
app.on('quit', () => {
//drpcQuit();
+ if (appIcon) appIcon.destroy()
+});
+
+let appIcon:Tray = null;
+
+EventEmitter.on('openTray',()=>{
+ if(!appIcon){
+ const iconName = "../assets/media/screenshot.png";
+ const iconPath = path.join(__dirname, iconName)
+ appIcon = new Tray(iconPath)
+
+ updateTrayIconMenue();
+}
+});
+
+function updateTrayIconMenue(){
+ if(appIcon && appIcon!==null){
+ let menue:Electron.MenuItemConstructorOptions[] = [];
+ if(Status.getStatus().gameRunning){
+ menue.push({
+ label: 'Open screenshot folder',
+ click: () => {
+ EventEmitter.emit('Mana:openScreenshotDir');
+ }
+ });
+ menue.push({
+ label: 'Kill ManaPlus',
+ click: () => {
+ //TODO Ask the user first to confirm
+ const options = {
+ type: 'warning',
+ title: 'Kill ManaPlus',
+ message: "Are you sure?",
+ buttons: ['Yes', 'No']
+ }
+ dialog.showMessageBox(options, (index) => {
+ if(index===0){
+ EventEmitter.emit('Mana:killMana');
+ }
+ })
+ }
+ });
+ }else{
+ menue.push({
+ label: 'Close Tray Icon',
+ click: () => {
+ EventEmitter.emit('closeTray');
+ }
+ });
+ }
+
+
+ appIcon.setToolTip('LawnCables Mana Launcher');
+ appIcon.setContextMenu(Menu.buildFromTemplate(menue));
+ }
+}
+
+EventEmitter.on('status', updateTrayIconMenue);
+
+EventEmitter.on('closeTray',()=>{
+ if (appIcon) {
+ appIcon.destroy();
+ appIcon = null;
+ }
});
@@ -94,7 +158,7 @@ ipcMain.on('play', async (event:any, arg:any) => {
if(Status.getStatus().playing)return;
console.log("play", arg);
Status.setPlaying(true);
- await ManaPlus.start(arg.address,arg.port,arg.engine,arg.username,arg.password);
+ await ManaPlus.start(arg);
//Status.showError("Failed To Launch Mana Plus","Not implemented yet!","Launch Manaplus faild: Not Implemented");
return false;
});
@@ -107,3 +171,15 @@ ipcMain.on('dragFileOut', (event:any, filepath:any) => {
icon:path.join(__dirname, "../assets/media/screenshot.png")
})
})
+
+EventEmitter.on('reopenWindow',()=>{
+ if (mainWindow === null) {
+ createWindow();
+ }
+});
+
+EventEmitter.on('closeWindow',()=>{
+ if (mainWindow !== null) {
+ mainWindow.close();
+ }
+});
diff --git a/src/main/manaplus/manaApp/manaApp.interface.ts b/src/main/manaplus/manaApp/manaApp.interface.ts
index f70b26a..4db7c15 100644
--- a/src/main/manaplus/manaApp/manaApp.interface.ts
+++ b/src/main/manaplus/manaApp/manaApp.interface.ts
@@ -1,5 +1,5 @@
export interface ManaPlusApp {
- run(parameters:string[]):void,
+ readonly startCommand:string,
getGameDir():string,
getVersion():Promise<string>,
isInstalled():boolean,
diff --git a/src/main/manaplus/manaApp/windows.ts b/src/main/manaplus/manaApp/windows.ts
index b5cde15..92acb7f 100644
--- a/src/main/manaplus/manaApp/windows.ts
+++ b/src/main/manaplus/manaApp/windows.ts
@@ -8,32 +8,15 @@ import * as extract from 'extract-zip';
export class ManaPlusAppWindows implements ManaPlusApp {
private path:string;
-
+ public readonly startCommand:string;
constructor(){
const ManaPath = app.getPath('userData')+"\\manaplus";
fs.existsSync(ManaPath) || fs.mkdirSync(ManaPath);
fs.existsSync(app.getPath('userData')+"\\temp") || fs.mkdirSync(app.getPath('userData')+"\\temp");
this.path = ManaPath;
+ this.startCommand = this.path + "\\Mana\\manaplus.exe"
}
- run(parameters: string[]): void {
- Status.setActivity(`Starting ManaPlus`);
- const gameExe = this.path+"\\Mana\\manaplus.exe";
- 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', ()=>{
- Status.setPlaying(false);
- Status.removeActivity();
- });
- child.on('error', ()=>{
- Status.setPlaying(false);
- //// TODO: Handle Error
- });
- }
getGameDir(): string {
return this.path+"\\Mana\\";
}
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<any> {
+ 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');
+});
diff --git a/src/main/status.ts b/src/main/status.ts
index 18fccd1..fb99b35 100644
--- a/src/main/status.ts
+++ b/src/main/status.ts
@@ -6,6 +6,7 @@ type STATUS = {
activity:string,
ActivityIsError:boolean,
playing:boolean,
+ gameRunning:boolean,
}
const status:STATUS = {
@@ -13,9 +14,14 @@ const status:STATUS = {
activity:null,
playing:false, //Is manaplus starting or started
ActivityIsError:false,
+ gameRunning:false,
}
export namespace Status {
+ export function setGameRunning(value: boolean){
+ status.gameRunning=value;
+ updateStatus();
+ }
export function setProgress(value: number){
status.progress=value;
updateStatus();
@@ -50,6 +56,7 @@ export namespace Status {
}
function updateStatus(){
+ if(mainWindow && mainWindow!== null){
if(status.progress==null || status.progress<0)
mainWindow.setProgressBar(-1);
@@ -59,4 +66,12 @@ function updateStatus(){
mainWindow.setProgressBar(status.progress/100);
mainWindow.webContents.send('status-update', status);
+ }
+ EventEmitter.emit('status', status);
}
+
+import * as events from 'events';
+
+class MyEmitter extends events {}
+
+export const EventEmitter = new MyEmitter();
diff --git a/src/renderer/gameserver/server.ts b/src/renderer/gameserver/server.ts
index e7a1078..d0b4002 100644
--- a/src/renderer/gameserver/server.ts
+++ b/src/renderer/gameserver/server.ts
@@ -271,7 +271,7 @@ ipcRenderer.on('getScreenshots', (event:any, data:{dir:string, screenshots:strin
const openFolderButton = document.createElement('button');
openFolderButton.innerText = "Open folder to see all";
openFolderButton.addEventListener('click', ()=>{
- shell.showItemInFolder(data.dir);
+ shell.openItem(data.dir);
});
screenshots.appendChild(openFolderButton);
}