Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auto open pdf reader #168

Merged
merged 5 commits into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,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 };