Compare commits

..

No commits in common. "dae9700b0b762dfb63fc7f5f9b4d42d2b37f2ae1" and "e4d335919d5fc2ce4255ac8a57a75fb418335009" have entirely different histories.

5 changed files with 84 additions and 104 deletions

View File

@ -93,42 +93,27 @@ const backupApp = async () => {
await fsp.rename(archive + ".bak", archive); await fsp.rename(archive + ".bak", archive);
return true; return true;
}, },
enhanceApp = async (debug = false, directoryMode = false) => { enhanceApp = async (debug = false) => {
const app = getResourcePath("app"), const app = getResourcePath("app"),
archive = getResourcePath("app.asar"); archive = getResourcePath("app.asar");
// directory mode acts on pre-extracted sources if (!existsSync(archive)) return false;
// as part of the notion-repackaged build process if (existsSync(app)) await fsp.rm(app, { recursive: true, force: true });
if (directoryMode) { await fsp.mkdir(app);
if (!existsSync(app)) return false; // extract archive to folder and apply patches
for (let file of await fsp.readdir(app, { recursive: true })) { for (let file of asar.listPackage(archive)) {
file = file.replace(/^\//g, ""); file = file.replace(/^\//g, "");
const appPath = resolve(app, file), const stat = asar.statFile(archive, file),
stat = await fsp.stat(appPath); isFolder = !!stat.files,
if (stat.isFile()) { isSymlink = !!stat.link,
const content = await fsp.readFile(appPath); isExecutable = stat.executable,
await fsp.writeFile(appPath, patch(file, content)); appPath = resolve(app, file);
} if (isFolder) {
} await fsp.mkdir(appPath);
} else { } else if (isSymlink) {
if (!existsSync(archive)) return false; await fsp.symlink(appPath, resolve(app, link));
if (existsSync(app)) await fsp.rm(app, { recursive: true, force: true }); } else {
await fsp.mkdir(app); await fsp.writeFile(appPath, patch(file, extractFile(file)));
// extract archive to folder and apply patches if (isExecutable) await fsp.chmod(appPath, "755");
for (let file of asar.listPackage(archive)) {
file = file.replace(/^\//g, "");
const stat = asar.statFile(archive, file),
isFolder = !!stat.files,
isSymlink = !!stat.link,
isExecutable = stat.executable,
appPath = resolve(app, file);
if (isFolder) {
await fsp.mkdir(appPath);
} else if (isSymlink) {
await fsp.symlink(appPath, resolve(app, link));
} else {
await fsp.writeFile(appPath, patch(file, extractFile(file)));
if (isExecutable) await fsp.chmod(appPath, "755");
}
} }
} }
// insert the notion-enhancer/src folder into notion's node_modules // insert the notion-enhancer/src folder into notion's node_modules
@ -141,12 +126,10 @@ const backupApp = async () => {
excludes = ["bin", "type", "scripts", "engines", "dependencies"]; excludes = ["bin", "type", "scripts", "engines", "dependencies"];
for (const key of excludes) delete manifest[key]; for (const key of excludes) delete manifest[key];
await fsp.writeFile(insertManifest, JSON.stringify(manifest)); await fsp.writeFile(insertManifest, JSON.stringify(manifest));
if (!directoryMode) { // re-package enhanced sources into executable archive
// re-package enhanced sources into executable archive await asar.createPackage(app, archive);
await asar.createPackage(app, archive); // cleanup extracted files unless in debug mode
// cleanup extracted files unless in debug mode if (!debug) await fsp.rm(app, { recursive: true });
if (!debug) await fsp.rm(app, { recursive: true });
}
return true; return true;
}; };

View File

@ -37,11 +37,9 @@ const shouldLoadThemeOverrides = async (api, db) => {
const { html } = api, const { html } = api,
customStyles = (await db.get("customStyles"))?.content; customStyles = (await db.get("customStyles"))?.content;
if (!customStyles) return; if (!customStyles) return;
const $customStyles = html`<style return document.head.append(html`<style>
id="__custom" ${customStyles}
innerHTML=${customStyles} </style>`);
></style>`;
return document.head.append($customStyles);
}; };
const insertMenu = async (api, db) => { const insertMenu = async (api, db) => {

View File

@ -8,7 +8,6 @@
body { body {
--guide--style: solid; --guide--style: solid;
--guide--color: var(--theme--fg-border); --guide--color: var(--theme--fg-border);
--guide--opacity: 0;
} }
/* add indent guides to nested blocks */ /* add indent guides to nested blocks */
@ -29,7 +28,6 @@ body {
top: var(--guide--offset); top: var(--guide--offset);
margin-inline-start: var(--guide--indent); margin-inline-start: var(--guide--indent);
border-left: 1px var(--guide--style) var(--guide--color); border-left: 1px var(--guide--style) var(--guide--color);
opacity: var(--guide--opacity);
} }
} }
@ -61,7 +59,6 @@ body {
height: 100%; height: 100%;
margin-inline-start: var(--guide--indent); margin-inline-start: var(--guide--indent);
border-left: 1px var(--guide--style) var(--guide--color); border-left: 1px var(--guide--style) var(--guide--color);
opacity: var(--guide--opacity);
} }
} }

View File

@ -6,61 +6,63 @@
*/ */
export default async function (api, db) { export default async function (api, db) {
const { html } = api, const lineType = await db.get("lineType"),
guideStyle = await db.get("guideStyle"),
rainbowMode = await db.get("rainbowMode"); rainbowMode = await db.get("rainbowMode");
document.body.style.setProperty("--guide--style", guideStyle.toLowerCase()); document.body.style.setProperty("--guide--style", lineType.toLowerCase());
const nestedTargets = [], // switch (await db.get(["style"])) {
outlineTargets = []; // case "dashed":
for (const [listType, selectors] of [ // style = "dashed";
["to-doList", [".notion-to_do-block"]], // break;
["bulletedList", [".notion-bulleted_list-block"]], // case "dotted":
["numberedList", [".notion-numbered_list-block"]], // style = "dotted";
["toggleList", [".notion-toggle-block"]], // break;
[ // case "soft":
"toggleHeadings", // opacity = 0.25;
[ // break;
".notion-header-block", // case "rainbow":
".notion-sub_header-block", // opacity = 0.7;
".notion-sub_sub_header-block", // rainbow = true;
], // break;
], // }
]) {
if (await db.get(listType)) nestedTargets.push(...selectors);
}
if (await db.get("tableOfContents"))
outlineTargets.push(".notion-table_of_contents-block");
if (await db.get("outliner"))
outlineTargets.push(".notion-enhancer--outliner-heading");
let css = `${[...nestedTargets, ...outlineTargets].join(",")} { // const colors = ['red', 'pink', 'purple', 'blue', 'green', 'yellow'];
--guide--opacity: 1; // colors.push(...colors, ...colors, ...colors, 'gray');
}`;
if (rainbowMode) { // for (const listType of ['bulleted_list', 'numbered_list', 'to_do', 'toggle']) {
const opacity = `--guide--opacity: 0.5;`, // if (!(await db.get([listType]))) continue;
selector = `:is(${nestedTargets.join(",")})`, // css += `
colours = ["green", "blue", "purple", "pink", "red", "orange", "yellow"]; // .notion-page-content .notion-${listType}-block > div > div:last-child::before {
colours.push(...colours, ...colours, ...colours, "gray"); // border-left: 1px ${style} var(--indentation_lines--color, currentColor);
for (let i = 0; i < colours.length; i++) { // opacity: ${opacity};
css += `${(selector + " ").repeat(i + 1)} { // }`;
--guide--color: var(--theme--fg-${colours[i]});
${opacity} // if (rainbow) {
}`; // for (let i = 0; i < colors.length; i++) {
} // css += `
css += ` // .notion-page-content ${`.notion-${listType}-block `.repeat(i + 1)}
.notion-table_of_contents-block [contenteditable="false"] a // > div > div:last-child::before {
> div[style*="margin-left: 24px"], // --indentation_lines--color: var(--theme--text_${colors[i]});
.notion-enhancer--outliner-heading.pl-\\[36px\\] { // }`;
--guide--color: var(--theme--fg-${colours[0]}); // }
${opacity} // }
} // }
.notion-table_of_contents-block [contenteditable="false"] a
> div[style*="margin-left: 48px"], // if (await db.get(['toggle_header'])) {
.notion-enhancer--outliner-heading.pl-\\[54px\\] { // css += `
--guide--color: var(--theme--fg-${colours[1]}); // .notion-page-content [class$=header-block] > div > div > div:last-child::before {
${opacity} // border-left: 1px ${style} var(--indentation_lines--color, currentColor);
}`; // opacity: ${opacity};
} // }`;
document.head.append(html`<style innerHTML=${css}></style>`);
// if (rainbow) {
// for (let i = 0; i < colors.length; i++) {
// css += `
// .notion-page-content ${`[class$=header-block] `.repeat(i + 1)}
// > div > div > div:last-child::before{
// --indentation_lines--color: var(--theme--text_${colors[i]});
// }`;
// }
// }
// }
} }

View File

@ -20,8 +20,8 @@
"options": [ "options": [
{ {
"type": "select", "type": "select",
"key": "guideStyle", "key": "lineType",
"description": "The type of line to use for indent guides.", "description": "The line style to use for indent guides.",
"values": ["Solid", "Dashed", "Dotted"] "values": ["Solid", "Dashed", "Dotted"]
}, },
{ {