'use strict';const electron=require('electron');const{app,globalShortcut}=electron;const{BrowserWindow,ipcMain}=electron;const nativeImage=require('electron').nativeImage;if(process.platform=='linux'){app.disableHardwareAcceleration();}
ipcMain.on('close-main-window',()=>{app.quit();});let iconApp=nativeImage.createFromPath(__dirname+'/app/assets/ico/icon.png')
let splashWindow=null;app.on('window-all-closed',()=>{if(process.platform!='darwin')
app.quit();});app.on('ready',()=>{splashWindow=new BrowserWindow({title:'Yout',icon:iconApp,width:400,height:400,backgroundColor:'#262626',center:true,movable:true,resizable:false,alwaysOnTop:true,toolbar:false,frame:false});var mainWindow=new BrowserWindow({title:'Yout',icon:iconApp,minWidth:266,minHeight:150,backgroundColor:'#000000',center:true,resizable:true,movable:true,alwaysOnTop:true,frame:false,toolbar:false,show:false});splashWindow.setMenu(null);splashWindow.loadURL('file://'+__dirname+'/app/splash.html');ipcMain.on('show-yout-window',()=>{splashWindow.destroy();mainWindow.show();splashWindow=null;});mainWindow.setMenu(null);mainWindow.isResizable(true);mainWindow.loadURL('file://'+__dirname+'/app/index.html');function enterFullScreen(){if(mainWindow.isFullScreen()==false){mainWindow.setFullScreen(true);mainWindow.webContents.send('fullscreen');}}
function exitFullScreen(){if(mainWindow.isFullScreen()){mainWindow.setFullScreen(false);mainWindow.webContents.send('showDecoration');mainWindow.webContents.send('killfullscreen');}}
mainWindow.on('focus',()=>{mainWindow.webContents.send('showDecoration');globalShortcut.register('Esc',()=>{if(mainWindow.isFullScreen()){exitFullScreen();}});globalShortcut.register('Enter',()=>{if(mainWindow.isFullScreen()){exitFullScreen();}else{enterFullScreen();}});});mainWindow.on('blur',()=>{mainWindow.webContents.send('hideDecoration');globalShortcut.unregister('Esc');globalShortcut.unregister('Enter');});ipcMain.on('minimize-main-window',()=>{mainWindow.minimize();});ipcMain.on('exit-fullscreen',()=>{mainWindow.setFullScreen(false);mainWindow.webContents.send('showDecoration');mainWindow.webContents.send('killfullscreen');});ipcMain.on('maximize-main-window',()=>{if(mainWindow.isFullScreen()){exitFullScreen();}else{enterFullScreen();}});mainWindow.on('closed',()=>{mainWindow=null;app.quit();});ipcMain.on('update-playlist',()=>{mainWindow.setSize(800,600);mainWindow.reload();});ipcMain.on('create-about-window',()=>{let aboutWindow=new BrowserWindow({title:'Yout',icon:iconApp,width:400,height:459,backgroundColor:'#262626',center:true,resizable:false,movable:true,alwaysOnTop:true,frame:false,show:false});aboutWindow.setMenu(null);aboutWindow.loadURL('file://'+__dirname+'/app/about.html');aboutWindow.show();});ipcMain.on('create-playlist-window',()=>{let managePlaylistsWindow=new BrowserWindow({title:'Yout',icon:iconApp,width:400,height:400,backgroundColor:'#262626',center:true,resizable:false,movable:true,alwaysOnTop:true,frame:false,show:false});managePlaylistsWindow.setMenu(null);managePlaylistsWindow.loadURL('file://'+__dirname+'/app/managePlaylists.html');managePlaylistsWindow.show();});ipcMain.on('create-help-window',()=>{let helpWindow=new BrowserWindow({title:'Yout',icon:iconApp,width:770,height:500,backgroundColor:'#262626',center:true,resizable:false,movable:true,alwaysOnTop:true,frame:false,show:false});helpWindow.setMenu(null);helpWindow.loadURL('file://'+__dirname+'/app/help.html');helpWindow.show();});});
