Compare commits

...

2 Commits

5 changed files with 104 additions and 84 deletions

View File

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

View File

@ -37,9 +37,11 @@ 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;
return document.head.append(html`<style> const $customStyles = html`<style
${customStyles} id="__custom"
</style>`); innerHTML=${customStyles}
></style>`;
return document.head.append($customStyles);
}; };
const insertMenu = async (api, db) => { const insertMenu = async (api, db) => {

View File

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