import { BrowserWindow , ipcMain , nativeTheme } from "electron" ; import { EventConstants } from "../common/constants/event.constants" ; import { IFileSave } from "../common/interface/IFileSave" ; import { pandoc } from "./features/pandoc" ; import { createSlidePage } from "./pages/silde.page" ; import Phodit from "./phodit" ; export default class PhoditIpc { private app : Phodit ; constructor ( app ) { this . app = app ; } startListener ( ) { ipcMain . on ( EventConstants . PHODIT . OPEN_FILE , ( event , arg ) => { this . app . openFile ( arg ) ; } ) ; ipcMain . on ( EventConstants . PHODIT . SAVE_FILE , ( event , arg ) => { this . app . saveFile ( arg . data , arg . isTempFile ) ; } ) ; ipcMain . on ( EventConstants . PHODIT . OPEN_GUIDE , ( event , arg ) => { this . app . openAboutPage ( ) ; } ) ; ipcMain . on ( EventConstants . PHODIT . SHOW_SLIDES , ( event , arg ) => { createSlidePage ( BrowserWindow , arg ) ; } ) ; ipcMain . on ( EventConstants . PHODIT . FULL_SCREEN , ( event , arg ) => { this . app . mainWindow . setFullScreen ( true ) ; this . app . mainWindow . maximize ( ) ; } ) ; ipcMain . on ( EventConstants . PHODIT . UN_FULL_SCREEN , ( event , arg ) => { this . app . mainWindow . setFullScreen ( false ) ; this . app . mainWindow . unmaximize ( ) ; } ) ; ipcMain . on ( EventConstants . PHODIT . RELOAD_PATH , ( event , arg ) => { this . app . reloadPath ( ) ; } ) ; ipcMain . on ( EventConstants . PHODIT . SET_THEME , ( event , arg ) => { nativeTheme . themeSource = arg . mode ; return nativeTheme . shouldUseDarkColors ; } ) ; ipcMain . on ( EventConstants . PHODIT . TOGGLE_THEME , ( event , arg ) => { if ( nativeTheme . shouldUseDarkColors ) { nativeTheme . themeSource = 'light' ; } else { nativeTheme . themeSource = 'dark' ; } return nativeTheme . shouldUseDarkColors ; } ) ; ipcMain . on ( EventConstants . PHODIT . SHOW_WORD , ( event , arg ) => { pandoc . word ( arg ) ; } ) ; ipcMain . on ( EventConstants . PHODIT . SHOW_PDF , ( event , arg ) => { pandoc . pdf ( arg ) ; } ) ; ipcMain . on ( EventConstants . PHODIT . OPEN_SYSTEM_PATH , ( event , arg ) => { require ( "electron" ) . shell . showItemInFolder ( arg ) ; } ) ; } }