Skip to content

Commit

Permalink
Added new file protocol for pdf. Causes crash
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyJNewman committed Jul 20, 2022
1 parent 0264eb8 commit c30702a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/main/main.js
@@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain, session } = require('electron')
const { app, BrowserWindow, ipcMain, session, protocol } = require('electron')
const path = require('path')
const fs = require('fs')
const isDev = require('electron-is-dev')
Expand Down Expand Up @@ -48,11 +48,15 @@ app.on('ready', async () => {
await session.defaultSession.loadExtension(
'C:/Users/timot/AppData/Local/Google/Chrome/User Data/Profile 2/Extensions/fmkadmapgofadopljbjfkapdkoienihi/4.25.0_0'
)
protocol.registerFileProtocol('atom', (request, callback) => {
const url = request.url.substr(7)
callback({ path: path.normalize(`${__dirname}/${url}`) })
})
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
'Content-Security-Policy': ['default-src \'self\' \'unsafe-inline\' filesystem:; object-src \'self\' filesystem:;']
'Content-Security-Policy': ['default-src \'self\' \'unsafe-inline\' atom:; object-src \'self\' atom:;']
}
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/main/pdfGenerator/pdfGenerator.js
Expand Up @@ -32,7 +32,7 @@ const pdfGeneratorHandler = async (event, args) => {

return new Promise((resolve, reject) => {
pdf.on('error', (err) => reject(err))
pdf.on('finish', resolve(path.join(app.getPath("userData"), 'output_files/pdf_files', `output${args.id}.pdf`)))
pdf.on('finish', resolve(`atom://${app.getPath("userData")}\\input${args.id}.pdf`))
})
}

Expand Down
5 changes: 3 additions & 2 deletions src/renderer/components/PdfDisplay.js
Expand Up @@ -5,15 +5,16 @@ import React from 'react'
const PdfDisplay = ({ url }) => {
return (
<div className='mx-2'>
{console.log(url)}
<h1 id='cv-pdf-viewer' className='font-bold text-xl'>
CV pdf viewer
</h1>
<embed
{<embed
src={url}
type='application/pdf'
width={'100%'}
style={{ height: 'calc(100vh - 3rem)' }}
/>
/>}
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/index.html
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8" />
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' 'unsafe-inline' filesystem:; object-src 'self' filesystem:;">
content="default-src 'self' 'unsafe-inline' atom:; object-src atom:;">
<title>Job Application Tracker</title>

</head>
Expand Down
5 changes: 2 additions & 3 deletions src/renderer/pages/CvConstructorPage/CvConstructorPage.js
Expand Up @@ -142,9 +142,7 @@ const CvConstructorPage = ({ id, setPdfUrl }) => {
createDatabaseEntry(
'INSERT INTO cv_components (cv_section, cv_component_text, date_created) VALUES (?,?,?)',
[sectionObj.section, JSON.stringify(sectionObj), new Date().toISOString()],
(url) => {
console.log(url)
}
() => { }
)
setNoElementsAdded(noElementsAdded + 1)
toggleCvBuilder(false)
Expand All @@ -170,6 +168,7 @@ const CvConstructorPage = ({ id, setPdfUrl }) => {
'UPDATE applications SET is_cv_ready=true, cv_url=? WHERE id=?',
[result, id],
(e) => {
console.log(result)
setPdfUrl({ isReady: true, url: result })
}
)
Expand Down
1 change: 0 additions & 1 deletion src/renderer/pages/CvConstructorPage/CvSectionBuilder.js
Expand Up @@ -13,7 +13,6 @@ const reducer = (state, action) => {
if (index) {
let newInputArray = [...state[name]]
newInputArray[index] = action.value
console.log('new action', action)
newState[name] = newInputArray
}
// for non-array inputs
Expand Down

0 comments on commit c30702a

Please sign in to comment.