diff options
Diffstat (limited to 'src/main.ts')
-rw-r--r-- | src/main.ts | 86 |
1 files changed, 81 insertions, 5 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(); + } +}); |