Skip to content

Commit ec3019b

Browse files
committed
Add patches for asset loading using notion protocol
1 parent ff8065d commit ec3019b

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
diff -ur a/mods/core/enhancerMenu.js b/mods/core/enhancerMenu.js
2+
--- a/mods/core/enhancerMenu.js 2021-08-28 14:28:05.482859666 +0200
3+
+++ b/mods/core/enhancerMenu.js 2021-08-28 14:51:42.253297153 +0200
4+
@@ -520,7 +520,7 @@
5+
if (fileExists(`${__dirname}/../${mod.dir}/${sheet}.css`)) {
6+
document.head.appendChild(
7+
createElement(
8+
- `<link rel="stylesheet" href="enhancement://${mod.dir}/${sheet}.css">`
9+
+ `<link rel="stylesheet" href="notion://www.notion.so/__notion-enhancer/${mod.dir}/${sheet}.css">`
10+
)
11+
);
12+
}
13+
diff -ur a/mods/core/render.js b/mods/core/render.js
14+
--- a/mods/core/render.js 2021-08-28 14:28:05.542859999 +0200
15+
+++ b/mods/core/render.js 2021-08-28 14:53:19.997206456 +0200
16+
@@ -963,7 +963,7 @@
17+
if (fileExists(`${__dirname}/../${mod.dir}/${sheet}.css`)) {
18+
document.head.appendChild(
19+
createElement(
20+
- `<link rel="stylesheet" href="enhancement://${mod.dir}/${sheet}.css">`
21+
+ `<link rel="stylesheet" href="notion://www.notion.so/__notion-enhancer/${mod.dir}/${sheet}.css">`
22+
)
23+
);
24+
}
25+
diff -ur a/mods/core/tabs.css b/mods/core/tabs.css
26+
--- a/mods/core/tabs.css 2021-08-28 14:28:05.489526369 +0200
27+
+++ b/mods/core/tabs.css 2021-08-28 14:51:51.676689282 +0200
28+
@@ -99,7 +99,7 @@
29+
display: inline-block;
30+
margin: auto 1em -0.25em 1em;
31+
background-size: contain;
32+
- background-image: url('enhancement://core/icons/mac+linux.png');
33+
+ background-image: url('notion://www.notion.so/__notion-enhancer/core/icons/mac+linux.png');
34+
background-repeat: no-repeat;
35+
}
36+
#tabs {
37+
diff -ur a/mods/core/tray.js b/mods/core/tray.js
38+
--- a/mods/core/tray.js 2021-08-28 14:28:05.489526369 +0200
39+
+++ b/mods/core/tray.js 2021-08-28 14:53:37.810637211 +0200
40+
@@ -144,7 +144,7 @@
41+
enableRemoteModule: true,
42+
},
43+
});
44+
- enhancer_menu.loadURL('enhancement://core/menu.html');
45+
+ enhancer_menu.loadURL('notion://www.notion.so/__notion-enhancer/core/menu.html');
46+
enhancer_menu.on('close', (e) => {
47+
window_state.saveState(enhancer_menu);
48+
enhancer_menu = null;
49+
diff -ur a/pkg/loader.js b/pkg/loader.js
50+
--- a/pkg/loader.js 2021-08-28 14:28:05.502859777 +0200
51+
+++ b/pkg/loader.js 2021-08-28 14:52:57.387079612 +0200
52+
@@ -20,44 +20,6 @@
53+
.slice(path.resolve(`${getNotionResources()}/app`).length + 1)
54+
.replace(/\\/g, '/');
55+
56+
- if (__file === 'main/security.js') {
57+
- const electron = require('electron');
58+
- electron.app.whenReady().then(() => {
59+
- electron.session
60+
- .fromPartition('persist:notion')
61+
- .protocol.registerFileProtocol('enhancement', (req, callback) => {
62+
- callback({
63+
- path: path.resolve(
64+
- `${__dirname}/../mods/${req.url.slice('enhancement://'.length)}`
65+
- ),
66+
- });
67+
- });
68+
- });
69+
- electron.protocol.registerSchemesAsPrivileged([
70+
- {
71+
- scheme: 'notion',
72+
- privileges: {
73+
- standard: true,
74+
- secure: true,
75+
- allowServiceWorkers: true,
76+
- supportFetchAPI: true,
77+
- corsEnabled: true,
78+
- },
79+
- },
80+
- {
81+
- scheme: 'enhancement',
82+
- privileges: {
83+
- standard: true,
84+
- secure: true,
85+
- allowServiceWorkers: true,
86+
- supportFetchAPI: true,
87+
- corsEnabled: true,
88+
- bypassCSP: true,
89+
- },
90+
- },
91+
- ]);
92+
- }
93+
-
94+
let modules = getEnhancements();
95+
modules = [
96+
...modules.loaded.filter((m) => m.tags.includes('core')),
97+
@@ -76,7 +38,7 @@
98+
if (fileExists(`${__dirname}/../mods/${mod.dir}/${sheet}.css`)) {
99+
document.head.appendChild(
100+
createElement(
101+
- `<link rel="stylesheet" href="enhancement://${mod.dir}/${sheet}.css">`
102+
+ `<link rel="stylesheet" href="notion://www.notion.so/__notion-enhancer/${mod.dir}/${sheet}.css">`
103+
)
104+
);
105+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--- main/schemeHandler.js 2021-08-28 14:28:05.566193462 +0200
2+
+++ main/schemeHandler.new.js 2021-08-28 14:44:37.106271190 +0200
3+
@@ -122,6 +122,16 @@
4+
function registerUrlSchemeProxy() {
5+
const { protocol } = electron_1.session.fromPartition(constants_1.electronSessionPartition);
6+
const success = protocol.registerStreamProtocol(config_1.default.protocol, async (req, callback) => {
7+
+ {
8+
+ const notionEnhancerSchemePrefix = 'notion://www.notion.so/__notion-enhancer/';
9+
+ if (req.url.startsWith(notionEnhancerSchemePrefix)) {
10+
+ const notionEnhancerFilepath = `${__dirname}/../embedded_enhancer/mods/${req.url.slice(
11+
+ notionEnhancerSchemePrefix.length,
12+
+ )}`;
13+
+ callback(require('fs').createReadStream(require('path').resolve(notionEnhancerFilepath)));
14+
+ }
15+
+ }
16+
+
17+
if (config_1.default.isLocalhost && !config_1.default.offline) {
18+
proxyRequest(req, callback);
19+
return;

scripts/enhance-src.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ echo "${PATCHED_PACKAGE_JSON}" > package.json
2525

2626
log "Applying additional notion patches..."
2727
patch -p0 --binary < "${WORKSPACE_DIR}/patches/notion-check-relativeurl.patch"
28+
patch -p0 --binary < "${WORKSPACE_DIR}/patches/notion-protocol-handle-enhancer.patch"
2829

2930
log "Fetching enhancer sources..."
3031

@@ -40,6 +41,7 @@ patch -p0 --binary < "${WORKSPACE_DIR}/patches/enhancer-query-selector-fix.patch
4041
patch -p0 --binary < "${WORKSPACE_DIR}/patches/enhancer-urlhelper-fix.patch"
4142
patch -p0 --binary < "${WORKSPACE_DIR}/patches/enhancer-paths.patch"
4243
patch -p0 --binary < "${WORKSPACE_DIR}/patches/enhancer-titlebar-icons-fix.patch"
44+
patch -p0 --binary < "${WORKSPACE_DIR}/patches/enhancer-assets-use-notion-protocol.patch"
4345
popd > /dev/null
4446

4547
log "Injecting enhancer loader..."

0 commit comments

Comments
 (0)