123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- import { app, BrowserWindow, ipcMain } from 'electron'
- import ipc from 'electron-better-ipc'
- import path from 'path'
- import configFile from './configstore'
- import * as componentCompiler from './rollup'
- import { Repo } from './remote-repos'
- import { is } from 'electron-util'
- import './store'
- const componentsPath = is.development
- ? `${__statics}/plugins`
- : configFile.get('plugins.destination')
- const sahibDocumentsPath = configFile.get('plugins.source')
- if (process.env.PROD) {
- global.__statics = path.join(__dirname, 'statics').replace(/\\/g, '\\\\')
- }
- console.log('Rollup watch starten …')
- componentCompiler.rollupSetup({
- statics: __statics,
- source: sahibDocumentsPath,
- dest: componentsPath,
- is: is
- })
- let mainWindow
- let pdfWindow = null
- function createPDFWindow () {
- pdfWindow = new BrowserWindow({
- show: false,
- parent: mainWindow,
- width: 800,
- height: 600,
- webPreferences: {
- plugins: true
- }
- })
- pdfWindow.on('closed', () => {
- pdfWindow = null
- })
- }
- function createWindow () {
- let { width, height } = configFile.get('windowBounds.main')
- mainWindow = new BrowserWindow({
- title: 'Sahib.js',
- width: width,
- height: height,
- useContentSize: true,
- icon: path.join(__dirname, '../icons/linux-256x256.png')
- })
- mainWindow.loadURL(process.env.APP_URL)
- // mainWindow.openDevTools()
- mainWindow.on('closed', () => {
- mainWindow = null
- })
- mainWindow.on('resize', () => {
- let { width, height } = mainWindow.getBounds()
- configFile.set('windowBounds.main', { width, height })
- })
- mainWindow.webContents.on('did-finish-load', () => {
- const watcher = componentCompiler.rollupWatch()
- watcher.on('event', event => {
- if (event.code === 'END') {
- console.log(
- new Date().toLocaleDateString('de-DE', {
- hour: 'numeric',
- minute: 'numeric',
- second: 'numeric'
- })
- )
- mainWindow.webContents.send('recompile')
- }
- })
- })
- }
- app.on('ready', createWindow)
- app.on('window-all-closed', () => {
- if (process.platform !== 'darwin') {
- app.quit()
- }
- })
- app.on('activate', () => {
- if (mainWindow === null) {
- createWindow()
- }
- })
- ipcMain.on('view-pdf', () => {
- if (pdfWindow === null) {
- createPDFWindow()
- }
- pdfWindow.loadURL(`file://${app.getPath('userData')}/print.pdf`)
- pdfWindow.show()
- })
- ipcMain.on('compileDokumente', () => {
- compileDokumente()
- })
- ipcMain.on('pullDokumente', (event, arg) => {
- configFile.get('plugins.remoteRepos').forEach(repo => {
- const repoPath = `${configFile.get('plugins.source')}/${repo.name}`
- Repo.pull(repoPath)
- })
- compileDokumente()
- })
- async function compileDokumente () {
- await componentCompiler.rollupBuild()
- console.log(
- new Date().toLocaleDateString('de-DE', {
- hour: 'numeric',
- minute: 'numeric',
- second: 'numeric'
- })
- )
- mainWindow.webContents.send('recompile')
- }
- ipc.answerRenderer('getRemoteRepos', async getRemoteRepos => {
- return configFile.get('plugins.remoteRepos') || []
- })
- ipc.answerRenderer('setRemoteRepos', async remoteRepos => {
- configFile.set('plugins.remoteRepos', remoteRepos)
- })
- ipc.answerRenderer('cloneRemoteRepo', async remoteRepo => {
- const pluginsSource = configFile.get('plugins.source')
- const name = await Repo.clone(remoteRepo, pluginsSource)
- compileDokumente()
- return name
- })
- ipc.answerRenderer('setDB', async db => {
- console.log('Verbindungsdaten speichern …')
- configFile.set('db', db)
- })
|