import { app , clipboard , ipcMain , nativeImage } from 'electron' ; import * as path from 'path' ; import { writeFile } from '../utils' ; import { GameWindows } from '../windows/game' ; import Utility from './utility' ; class ScreenShot extends Utility { constructor ( ) { super ( ) ; this . name = 'ScreenShot' ; } protected execute ( ) { ipcMain . on ( 'save-screenshot' , ( event , index , buf ) => { const buffer = buf ; const filePath = path . join ( app . getPath ( 'pictures' ) , app . name , Date . now ( ) + '.png' ) ; writeFile ( filePath , buffer ) . then ( ( ) => { GameWindows . get ( index ) . webContents . send ( 'screenshot-saved' , filePath ) ; } ) ; clipboard . writeImage ( nativeImage . createFromBuffer ( buffer ) ) ; } ) ; } } export default new ScreenShot ( ) ;