-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update theme, fix colors * Fix section rename bug * Add generate buttons and loader * Remove active id listener in paged previewer * Add API framework for generating PDF * Create window for paged renderer * Creating separate page entry for paged renderer * print to pdf once paged renderer is complete * Minor tweaks * update icons * Refactor modals * Switch to using modal for generating book, open pdf file in file explorer/finder when done * Add platforms checkbox to generate book modal * Fix packaged build and bump version Co-authored-by: Zach Hannum <[email protected]>
- Loading branch information
1 parent
637c827
commit 548335c
Showing
72 changed files
with
1,754 additions
and
923 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { BrowserWindow, ipcMain, app, shell } from 'electron'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { resolveHtmlPath } from '../util'; | ||
import { PagedBookContents } from 'types/types'; | ||
|
||
const generatePdf = ( | ||
mainWindow: BrowserWindow, | ||
pdfBookContent: PagedBookContents | ||
) => { | ||
console.log('Creating pdf render window'); | ||
const pdfWindow = new BrowserWindow({ | ||
show: false, | ||
parent: mainWindow, | ||
width: 500, | ||
height: 500, | ||
minWidth: 800, | ||
minHeight: 600, | ||
webPreferences: { | ||
preload: app.isPackaged | ||
? path.join(__dirname, 'preload.js') | ||
: path.join(__dirname, '../../../.erb/dll/preload.js'), | ||
}, | ||
}); | ||
pdfWindow.loadURL(resolveHtmlPath('paged.html')); | ||
pdfWindow.webContents.once('dom-ready', () => { | ||
console.log('sending paged contents'); | ||
pdfWindow.webContents.send('pagedContents', pdfBookContent); | ||
}); | ||
ipcMain.once('pagedRenderComplete', (_event, _arg) => { | ||
pdfWindow.webContents.printToPDF({}).then((buffer: Buffer) => { | ||
const filePath = path.join( | ||
app.getPath('downloads'), | ||
pdfBookContent.title.toLowerCase().trim().replace(/\s+/g, '_') + '.pdf' | ||
); | ||
fs.writeFile(filePath, buffer, (err) => { | ||
if (err) { | ||
console.log(err); | ||
} | ||
}); | ||
pdfWindow.close(); | ||
mainWindow.webContents.send('pdfGenerated', buffer); | ||
shell.showItemInFolder(filePath); | ||
}); | ||
}); | ||
}; | ||
|
||
export default generatePdf; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as setupPdfListeners } from './pdfListeners'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ipcMain } from 'electron'; | ||
import { BrowserWindow } from 'electron'; | ||
import { PagedBookContents } from '../../types/types'; | ||
import generatePdf from './generatePdf'; | ||
|
||
const setupProjectListeners = (mainWindow: BrowserWindow) => { | ||
ipcMain.on('generatePdf', async (_event, arg: PagedBookContents) => { | ||
generatePdf(mainWindow, arg); | ||
}); | ||
}; | ||
|
||
export default setupProjectListeners; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.