Skip to content

Commit

Permalink
Merge pull request #168 from hql287/fix-auto-open-pdf-reader
Browse files Browse the repository at this point in the history
Fix auto open pdf reader
  • Loading branch information
hql287 authored Jan 18, 2018
2 parents 93ef227 + 6f29d95 commit 0e56bc8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ function setInitialValues() {
language: 'en',
sound: 'default',
muted: false,
previewPDF: true,
checkUpdate: 'daily',
lastCheck: Date.now(),
},
Expand Down
14 changes: 14 additions & 0 deletions app/components/settings/General.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ class General extends Component {
</select>
</div>
</div>
<div className="col-md-6">
<div className="pageItem">
<label className="itemLabel">Auto Preview PDF</label>
<label className="switch">
<input
name="previewPDF"
type="checkbox"
checked={this.state.previewPDF}
onChange={this.handleInputChange}
/>
<span className="slider round" />
</label>
</div>
</div>
</div>
</div>
);
Expand Down
16 changes: 14 additions & 2 deletions main/save-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,20 @@ ipcMain.on('save-pdf', (event, docId) => {
if (error) {
throw error;
}
shell.openExternal('file://' + pdfPath);
event.sender.send('wrote-pdf', pdfPath);
if (appConfig.get('general.previewPDF')) {
// Open the PDF with default Reader
shell.openExternal('file://' + pdfPath);
}
// Show notification
win.webContents.send('pfd-exported', {
title: 'PDF Exported',
body: 'Click to reveal file.',
location: pdfPath,
});
});
});
});

ipcMain.on('reveal-file', (event, location) => {
shell.showItemInFolder(location);
});
9 changes: 9 additions & 0 deletions preview/containers/MainContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import { connect } from 'react-redux';
const ipc = require('electron').ipcRenderer;

import { Notify } from '../helper/notify';
// Actions
import * as ActionsCreator from '../actions';

Expand Down Expand Up @@ -44,10 +45,18 @@ class MainContent extends PureComponent {
ipc.on('update-preview-window', (event, newConfigs) => {
dispatch(ActionsCreator.reloadConfigs(newConfigs));
});
ipc.on('pfd-exported', (event, options) => {
const noti = Notify(options);
// Handle click on notification
noti.onclick = () => {
ipc.send('reveal-file', options.location);
}
});
}

componentWillUnmount() {
ipc.removeAllListeners([
'pfd-exported',
'update-preview',
'update-preview-window',
]);
Expand Down
9 changes: 9 additions & 0 deletions preview/helper/notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function Notify(options) {
const{ title, body } = options;
return new Notification(title, {
body,
});
}

module.exports = { Notify };

0 comments on commit 0e56bc8

Please sign in to comment.