catch EBUSY, potential csp fix for #66

This commit is contained in:
dragonwocky 2020-10-06 10:15:30 +11:00
parent ecdae521b4
commit 7a6411ad23
2 changed files with 51 additions and 24 deletions

View File

@ -52,6 +52,20 @@ module.exports = (store, __exports) => {
}, },
...rect, ...rect,
}); });
electron.session
.fromPartition('persist:notion')
.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: Object.assign(
{
'Content-Security-Policy': [
"script-src 'self' 'unsafe-inline' 'unsafe-eval' enhancement: https://gist.github.com https://apis.google.com https://api.amplitude.com https://widget.intercom.io https://js.intercomcdn.com https://logs-01.loggly.com https://cdn.segment.com https://analytics.pgncs.notion.so https://checkout.stripe.com https://embed.typeform.com https://admin.typeform.com https://platform.twitter.com https://cdn.syndication.twimg.com; connect-src 'self' https://msgstore.www.notion.so wss://msgstore.www.notion.so https://notion-emojis.s3-us-west-2.amazonaws.com https://s3-us-west-2.amazonaws.com https://s3.us-west-2.amazonaws.com https://notion-production-snapshots-2.s3.us-west-2.amazonaws.com https: http: https://api.amplitude.com https://api.embed.ly https://js.intercomcdn.com https://api-iam.intercom.io wss://nexus-websocket-a.intercom.io https://logs-01.loggly.com https://api.segment.io https://api.pgncs.notion.so https://checkout.stripe.com https://cdn.contentful.com https://preview.contentful.com https://images.ctfassets.net https://api.unsplash.com https://boards-api.greenhouse.io; font-src 'self' data: https://cdnjs.cloudflare.com https://js.intercomcdn.com; img-src 'self' data: blob: https: https://platform.twitter.com https://syndication.twitter.com https://pbs.twimg.com https://ton.twimg.com; style-src 'self' 'unsafe-inline' enhancement: https://cdnjs.cloudflare.com https://github.githubassets.com https://platform.twitter.com https://ton.twimg.com; frame-src https: http:; media-src https: http:",
],
},
details.responseHeaders
),
});
});
window.once('ready-to-show', function () { window.once('ready-to-show', function () {
if ( if (
!store().openhidden || !store().openhidden ||

View File

@ -21,6 +21,7 @@ const url = require('url'),
module.exports = (store, __exports) => { module.exports = (store, __exports) => {
if (store().tabs) { if (store().tabs) {
let $currentTab;
class Index extends React.PureComponent { class Index extends React.PureComponent {
constructor() { constructor() {
super(...arguments); super(...arguments);
@ -29,11 +30,11 @@ module.exports = (store, __exports) => {
searching: false, searching: false,
searchingPeekView: false, searchingPeekView: false,
zoomFactor: 1, zoomFactor: 1,
tabs: 2, tabs: [],
}; };
this.notionElm = []; this.notionElm = [];
this.loadedElms = []; this.loadedElms = [];
this.reactTabs = []; this.reactTabs = {};
this.handleNotionRef = (notionElm) => { this.handleNotionRef = (notionElm) => {
this.notionElm.push(notionElm); this.notionElm.push(notionElm);
}; };
@ -51,13 +52,26 @@ module.exports = (store, __exports) => {
} }
}, 50); }, 50);
}; };
window['newtab'] = () => { window['tab'] = (id) => {
this.setState({ tabs: this.state.tabs + 1 }); if (!id) return;
setTimeout(() => this.addListeners(), 100); this.setState({ tabs: [...new Set([...this.state.tabs, id])] });
setTimeout(() => {
this.addListeners();
if (document.querySelector(`#tab-${id}`)) {
$currentTab = document.querySelector(`#tab-${id}`);
$currentTab.focus();
}
}, 100);
}; };
} }
componentDidMount() { componentDidMount() {
this.addListeners(); this.addListeners();
try {
electron.remote.getCurrentWindow().on('focus', (e) => {
$notion.focus();
});
} catch {}
} }
addListeners() { addListeners() {
const searchElm = this.searchElm; const searchElm = this.searchElm;
@ -214,10 +228,8 @@ module.exports = (store, __exports) => {
this.handleReload(); this.handleReload();
return; return;
} }
electronWindow.on('focus', (e) => {
$notion.focus();
});
$notion.addEventListener('dom-ready', function () { $notion.addEventListener('dom-ready', function () {
if ($notion !== $currentTab) return;
if (document.activeElement instanceof HTMLElement) { if (document.activeElement instanceof HTMLElement) {
document.activeElement.blur(); document.activeElement.blur();
} }
@ -286,25 +298,26 @@ module.exports = (store, __exports) => {
); );
} }
renderNotionContainer() { renderNotionContainer() {
this.reactTabs = [ this.reactTabs = Object.fromEntries(
...this.reactTabs, this.state.tabs.map((id) => {
...new Array(this.state.tabs - this.reactTabs.length) return [
.fill(0) id,
.map((i) => this.reactTabs[id] ||
React.createElement('webview', { React.createElement('webview', {
className: 'notion', className: 'notion',
style: Index.notionWebviewStyle, style: Index.notionWebviewStyle,
ref: this.handleNotionRef, ref: this.handleNotionRef,
partition: constants.electronSessionPartition, partition: constants.electronSessionPartition,
preload: path.resolve(`${__notion}/app/renderer/preload.js`), preload: path.resolve(`${__notion}/app/renderer/preload.js`),
src: this.props.notionUrl, src: this.props.notionUrl,
}) }),
), ];
]; })
);
return React.createElement( return React.createElement(
'div', 'div',
{ style: this.getNotionContainerStyle() }, { style: this.getNotionContainerStyle() },
...this.reactTabs ...Object.values(this.reactTabs)
); );
} }
renderErrorContainer() { renderErrorContainer() {