diff --git a/CHANGELOG.md b/CHANGELOG.md index dd5768c..a84c6a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ a flexibility update. - bugfix: removed messenger emoji set as the provider no longer supports it. - bugfix: remove shadow around light mode board headers \+ minor text colour fixes for night shift theming. -- bugfix: properly detect/respond to `EACCES` errors. +- bugfix: properly detect/respond to `EACCES`/`EBUSY` errors. - bugfix: night shift checks every interaction, will respond to system changes without any manual changes. - bugfix: toc blocks can have text colours. diff --git a/mods/core/create.js b/mods/core/create.js index fb37b5a..9daff2c 100644 --- a/mods/core/create.js +++ b/mods/core/create.js @@ -52,6 +52,20 @@ module.exports = (store, __exports) => { }, ...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 () { if ( !store().openhidden || diff --git a/mods/core/render.js b/mods/core/render.js index dc94206..3b0b494 100644 --- a/mods/core/render.js +++ b/mods/core/render.js @@ -21,6 +21,7 @@ const url = require('url'), module.exports = (store, __exports) => { if (store().tabs) { + let $currentTab; class Index extends React.PureComponent { constructor() { super(...arguments); @@ -29,11 +30,11 @@ module.exports = (store, __exports) => { searching: false, searchingPeekView: false, zoomFactor: 1, - tabs: 2, + tabs: [], }; this.notionElm = []; this.loadedElms = []; - this.reactTabs = []; + this.reactTabs = {}; this.handleNotionRef = (notionElm) => { this.notionElm.push(notionElm); }; @@ -51,13 +52,26 @@ module.exports = (store, __exports) => { } }, 50); }; - window['newtab'] = () => { - this.setState({ tabs: this.state.tabs + 1 }); - setTimeout(() => this.addListeners(), 100); + window['tab'] = (id) => { + if (!id) return; + 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() { this.addListeners(); + + try { + electron.remote.getCurrentWindow().on('focus', (e) => { + $notion.focus(); + }); + } catch {} } addListeners() { const searchElm = this.searchElm; @@ -214,10 +228,8 @@ module.exports = (store, __exports) => { this.handleReload(); return; } - electronWindow.on('focus', (e) => { - $notion.focus(); - }); $notion.addEventListener('dom-ready', function () { + if ($notion !== $currentTab) return; if (document.activeElement instanceof HTMLElement) { document.activeElement.blur(); } @@ -286,25 +298,26 @@ module.exports = (store, __exports) => { ); } renderNotionContainer() { - this.reactTabs = [ - ...this.reactTabs, - ...new Array(this.state.tabs - this.reactTabs.length) - .fill(0) - .map((i) => - React.createElement('webview', { - className: 'notion', - style: Index.notionWebviewStyle, - ref: this.handleNotionRef, - partition: constants.electronSessionPartition, - preload: path.resolve(`${__notion}/app/renderer/preload.js`), - src: this.props.notionUrl, - }) - ), - ]; + this.reactTabs = Object.fromEntries( + this.state.tabs.map((id) => { + return [ + id, + this.reactTabs[id] || + React.createElement('webview', { + className: 'notion', + style: Index.notionWebviewStyle, + ref: this.handleNotionRef, + partition: constants.electronSessionPartition, + preload: path.resolve(`${__notion}/app/renderer/preload.js`), + src: this.props.notionUrl, + }), + ]; + }) + ); return React.createElement( 'div', { style: this.getNotionContainerStyle() }, - ...this.reactTabs + ...Object.values(this.reactTabs) ); } renderErrorContainer() { diff --git a/pkg/apply.js b/pkg/apply.js index 79308dc..fae2201 100644 --- a/pkg/apply.js +++ b/pkg/apply.js @@ -55,7 +55,7 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) { console.info(' ...unpacking app.asar.'); const asar_app = path.resolve(`${helpers.__notion}/app.asar`); extractAll(asar_app, `${path.resolve(`${helpers.__notion}/app`)}`); - fs.move(asar_app, path.resolve(`${helpers.__notion}/app.asar.bak`)); + await fs.move(asar_app, path.resolve(`${helpers.__notion}/app.asar.bak`)); // patching launch script target of custom wrappers if ( @@ -120,7 +120,7 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) { : `try running "chown -R $USER ${err.path}"` }` ); - } else if (err.code === 'EIO' && friendly_errors) { + } else if (['EIO', 'EBUSY'].includes(err.code) && friendly_errors) { console.error('file access failed: is notion running?'); } else console.error(err); return false; diff --git a/pkg/remove.js b/pkg/remove.js index 865ef36..f003957 100644 --- a/pkg/remove.js +++ b/pkg/remove.js @@ -122,7 +122,7 @@ module.exports = async function ({ : `try running "chown -R $USER ${err.path}"` }` ); - } else if (err.code === 'EIO' && friendly_errors) { + } else if (['EIO', 'EBUSY'].includes(err.code) && friendly_errors) { console.error('file access failed: is notion running?'); } else console.error(err); return false;