summaryrefslogtreecommitdiff
path: root/src/main/manaplus
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/manaplus')
-rw-r--r--src/main/manaplus/manaplus.ts45
1 files changed, 38 insertions, 7 deletions
diff --git a/src/main/manaplus/manaplus.ts b/src/main/manaplus/manaplus.ts
index da8d6d5..590b9f4 100644
--- a/src/main/manaplus/manaplus.ts
+++ b/src/main/manaplus/manaplus.ts
@@ -3,7 +3,7 @@ import { ManaPlusAppWindows } from './ManaApp/windows';
import * as os from 'os';
import * as path from 'path';
import * as fs from 'fs-extra';
-import { app, ipcMain, shell } from 'electron';
+import { app, ipcMain, shell, dialog } from 'electron';
import { Status, EventEmitter } from '../status';
let ManaPlusInstance:ManaPlusApp;
@@ -39,6 +39,7 @@ export namespace ManaPlus{
let params:string[];
try {
params = await makeParams(args.address,args.port,args.engine,args.username,args.password);
+ //params = ['-v'];// DEBUG: This option is to disable manaplus for testing (open it just for getting the version)
} catch (e){
console.log(e);
Status.showError("Launch Preperation Failed", e.message, "Launch preparation failed")
@@ -46,10 +47,20 @@ export namespace ManaPlus{
}
let willUpdate:boolean=false;
// check if it is installed
- willUpdate = !ManaPlusInstance.isInstalled();
- //Check if update is availible and ask if the user wants to update
- //TODO
-
+ if(ManaPlusInstance.isInstalled()){
+ // Check if update is available and ask if the user wants to update
+ try {
+ let version = await ManaPlusInstance.updateAvailable();
+ willUpdate = (version.isNewVersion && await updateDialog(version.newestVersion));
+ } catch (e){
+ console.log(e);
+ Status.showError("Launch Preperation Failed", e.message, "Launch preparation failed")
+ return;
+ }
+ } else {
+ // Not installed will install it
+ willUpdate = true;
+ }
// Install/Update the gameclient if needed
if(willUpdate){
await update();
@@ -119,7 +130,7 @@ async function makeParams(server: any,port: any,engine: any,username?: any,passw
"-L", localDataDir,
"--screenshot-dir", screenshotsDir
]);
- console.log(parameters);
+ //console.log(parameters);
return parameters;
}
@@ -130,7 +141,7 @@ function runManaProgram(parameters: string[],gameExe:string): Promise<any> {
return new Promise((resolve, reject)=>{
Status.setActivity(`Starting ManaPlus`);
- console.log(gameExe, parameters);
+ //console.log(gameExe, parameters);
const child = require('child_process').execFile(gameExe, parameters, function(err:Error, data:any) {
console.log(err);
console.log(data.toString());
@@ -153,3 +164,23 @@ EventEmitter.on("Mana:killMana",()=>{
if(manaplusInstance && manaplusInstance !== null)
manaplusInstance.kill('SIGINT');
});
+
+async function updateDialog(newestVersion:string):Promise<boolean>{
+ const options = {
+ type: 'info',
+ title: `ManaPlus Update available: ${newestVersion}`,
+ message: "Do you want to update now? Please note that you'll have to update eventually to ensure further compability with the servers",
+ buttons: ['Nah, LATER', 'Update NOW']
+ }
+ let dialog = await dialogPromiseWrapper(options);
+ console.log("....",dialog);
+ return dialog === 1;
+}
+
+function dialogPromiseWrapper(options:any):Promise<number>{
+ return new Promise((res, rej) => {
+ dialog.showMessageBox(options, (index) => {
+ res(index);
+ })
+ });
+}