#97, #98, and small alterations.

(removed platform support requests, replaced getNotion() with __notion)
This commit is contained in:
dragonwocky 2020-09-17 13:06:49 +10:00
parent 211b24d2d7
commit 2303783319
Signed by: dragonwocky
GPG Key ID: C7A48B7846AA706D
16 changed files with 126 additions and 163 deletions

View File

@ -1,27 +0,0 @@
---
name: platform support
about: the enhancer doesn't know how to modify your notion installation?
title: ''
labels: enhancement
assignees: ''
---
FILL OUT THIS TEMPLATE, REMOVING/REPLACING EVERYTHING HERE WITH YOUR OWN INFORMATION.
BE AS CLEAR AND CONCISE AS POSSIBLE.
**platform**
what system are you on? (e.g. windows, macOS, raspbian, xfce)
**installation steps**
how did you install notion?
please link me to the download/installer/wrapper you used.
**filepaths**
- where is notion installed
- what file structure does it have
- in particular, where is the `app.asar` file
**why?**
what's so special about this way of installing notion?
is there any particular reason why you can't use one of the already-supported clients?

View File

@ -20,6 +20,8 @@ a feature and cleanup update.
- improved: extensions menu filters shown either a ✓ or × to help understand the current state.
- improved: added individual text-colour rules for different background colours.
- improved: added variables for callout colouring.
- improved: replaced with `helpers.getNotion()` with the constant `helpers.__notion` to reduce
repeated function calls.
- bugfix: enhancer settings should no longer reset on update (though this will not have
effect until the release after this one).
- bugfix: blue select tags are no longer purple.
@ -30,12 +32,14 @@ a feature and cleanup update.
- bugfix: update property-layout to match notion changes again.
- bugfix: updated some of the tweak styling to match notion changes.
- bugfix: block-level text colours are now changed properly.
- bugfix: do not require data folder during installation, to prevent `sudo` attempting to
create it in `/var/root/`.
- themes: "littlepig" (light + dark) = monospaced themes using emojis and colourful text.
- extension: "font chooser" = customize fonts. for each option, type in the name of the font you would like to use,
or leave it blank to not change anything.
- extension: "always on top" = add an arrow/button to show the notion window on top of other windows
even if it's not focused.
- extension: "calendar scroll" = add a button to scroll down to the current week for you.
- extension: "calendar scroll" = add a button to scroll down to the current week in fullpage/infinite-scroll calendars.
- extension: "hide help button" = hide the help button if you don't need it.
- extension: "bypass preview" = go straight to the normal full view when opening a page.
@ -100,7 +104,7 @@ complete rewrite with node.js.
- bugfix: non-reproducable errors with python.
- bugfix: better launcher patching on linux.
- bugfix: fix frameless window issue introduced by notion desktop 2.0.9.
- extension: "custom inserts" = link files for small client-side tweaks..
- extension: "custom inserts" = link files for small client-side tweaks.
- extension: "bracketed links" = render links surrounded with \[\[brackets]] instead of underlined.
- extension: "focus mode" = hide the titlebar/menubar if the sidebar is closed (will be shown on hover).
- theme: "dark+" = a vivid-colour near-black theme.

View File

@ -20,9 +20,6 @@ for support, join the [discord server](https://discord.gg/sFWPXtA).
(it can also be run from the wsl to apply enhancements to the windows app.)
**using a not-yet-supported operating system or notion installation?** ask for
[platform support](https://github.com/dragonwocky/notion-enhancer/issues/new?labels=enhancement&template=platform-support.md).
mobile clients are not supported and due to system limitations/restrictions cannot be.
a chrome extension may be coming soon for web client support.

View File

@ -33,7 +33,8 @@ if you are attempting to customise the web client, the css previously used for t
### hide discussions (the comment threads at the top of each page)
```css
[style*='env(safe-area-inset-left)'] [style*='width: 100%; height: 1px;'],
[style*='env(safe-area-inset-left)']:not(.notion-page-content)
[style*='width: 100%; height: 1px;'],
.notion-page-view-discussion {
display: none !important;
}

View File

@ -13,7 +13,7 @@ module.exports = {
tags: ['extension'],
name: 'calendar scroll',
desc:
'add a button to scroll down to the current week of a calendar for you.',
'add a button to scroll down to the current week in fullpage/infinite-scroll calendars',
version: '0.1.0',
author: 'dragonwocky',
hacks: {

View File

@ -10,8 +10,7 @@
module.exports = (store, __exports) => {
const electron = require('electron'),
helpers = require('../../pkg/helpers.js'),
__notion = helpers.getNotion(),
notionIpc = require(`${__notion.replace(
notionIpc = require(`${helpers.__notion.replace(
/\\/g,
'/'
)}/app/helpers/notionIpc.js`);

View File

@ -15,12 +15,11 @@ module.exports = (store, __exports) => {
),
// createWindow = __exports.createWindow,
path = require('path'),
helpers = require('../../pkg/helpers.js'),
__notion = helpers.getNotion();
helpers = require('../../pkg/helpers.js');
__exports.createWindow = function (relativeUrl, focused_window) {
if (!relativeUrl) relativeUrl = '';
const window_state = require(`${__notion.replace(
const window_state = require(`${helpers.__notion.replace(
/\\/g,
'/'
)}/app/node_modules/electron-window-state/index.js`)({
@ -47,7 +46,7 @@ module.exports = (store, __exports) => {
titleBarStyle: 'hiddenInset',
frame: !store().frameless,
webPreferences: {
preload: path.resolve(`${__notion}/app/renderer/index.js`),
preload: path.resolve(`${helpers.__notion}/app/renderer/index.js`),
webviewTag: true,
session: electron.session.fromPartition('persist:notion'),
},

View File

@ -14,8 +14,7 @@ module.exports = (store, __exports) => {
path = require('path'),
is_mac = process.platform === 'darwin',
is_win = process.platform === 'win32',
helpers = require('../../pkg/helpers.js'),
__notion = helpers.getNotion();
helpers = require('../../pkg/helpers.js');
electron.app.on('ready', () => {
tray = new electron.Tray(
@ -77,12 +76,12 @@ module.exports = (store, __exports) => {
function openExtensionMenu() {
if (enhancer_menu) return enhancer_menu.show();
const window_state = require(`${__notion.replace(
const window_state = require(`${helpers.__notion.replace(
/\\/g,
'/'
)}/app/node_modules/electron-window-state/index.js`)({
file: 'menu-windowstate.json',
path: helpers.data_folder,
path: helpers.__data,
defaultWidth: 275,
defaultHeight: 600,
});
@ -165,7 +164,9 @@ module.exports = (store, __exports) => {
click: () => {
require('./create.js')(
store,
require(path.resolve(`${__notion}/app/main/createWindow.js`))
require(path.resolve(
`${helpers.__notion}/app/main/createWindow.js`
))
)(
'',
electron.BrowserWindow.getAllWindows().find(

View File

@ -16,8 +16,7 @@ module.exports = {
author: {
name: 'zenith_illinois',
link: 'https://www.reddit.com/user/zenith_illinois/',
avatar:
'https://cdn.discordapp.com/avatars/565182533940150283/54f36546ab586298a5df5c238cbaaa4b.png?size=128',
avatar: 'https://www.redditstatic.com/avatars/avatar_default_18_46A508.png',
},
fonts: ['https://rsms.me/inter/inter.css'],
};

View File

@ -21,11 +21,8 @@ const fs = require('fs-extra'),
// ~~ exit
// ### error ###
let __notion = helpers.getNotion();
module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
try {
await fs.ensureDir(helpers.data_folder);
// handle pre-existing installations: app.asar present? version set in data folder? overwrite?
const check_app = await require('./check.js')();
switch (check_app.code) {
@ -55,24 +52,24 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
delete_data: false,
});
}
console.info(' ...unpacking app.asar');
const asar_app = path.resolve(`${__notion}/app.asar`);
extractAll(asar_app, `${path.resolve(`${__notion}/app`)}`);
fs.move(asar_app, path.resolve(`${__notion}/app.asar.bak`));
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`));
// patching launch script target of custom wrappers
if (
[
'/opt/notion-app', // https://aur.archlinux.org/packages/notion-app/
'/opt/notion', // https://github.com/jaredallard/notion-app
].includes(__notion)
].includes(helpers.__notion)
) {
console.info(
' ...patching app launcher (notion-app linux wrappers only).'
);
for (let bin_path of [
`/usr/bin/${__notion.split('/')[2]}`,
`${__notion}/${__notion.split('/')[2]}`,
`/usr/bin/${helpers.__notion.split('/')[2]}`,
`${helpers.__notion}/${helpers.__notion.split('/')[2]}`,
]) {
const bin_script = await fs.readFile(bin_path, 'utf8');
if (bin_script.includes('app.asar')) {
@ -87,13 +84,15 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
}
for await (let insertion_target of readdirIterator(
path.resolve(`${__notion}/app`),
path.resolve(`${helpers.__notion}/app`),
{
deep: (stats) => stats.path.indexOf('node_modules') === -1,
filter: (stats) => stats.isFile() && stats.path.endsWith('.js'),
}
)) {
insertion_target = path.resolve(`${__notion}/app/${insertion_target}`);
insertion_target = path.resolve(
`${helpers.__notion}/app/${insertion_target}`
);
fs.appendFile(
insertion_target,
`\n\n//notion-enhancer\nrequire('${helpers.realpath(
@ -105,10 +104,9 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
// not resolved, nothing depends on it so it's just a "let it do its thing"
console.info(' ...recording enhancement version.');
fs.outputFile(
path.resolve(`${__notion}/app/ENHANCER_VERSION.txt`),
path.resolve(`${helpers.__notion}/app/ENHANCER_VERSION.txt`),
version
);
fs.outputFile(path.resolve(`${helpers.data_folder}/version.txt`), version);
console.info(' ~~ success.');
return true;

View File

@ -12,14 +12,14 @@ const fs = require('fs-extra'),
{ version } = require('../package.json');
// handle pre-existing installations: app.asar modded? with which enhancer version?
let __notion = helpers.getNotion();
module.exports = async function () {
const version_path = path.resolve(`${__notion}/app/ENHANCER_VERSION.txt`),
const version_path = path.resolve(
`${helpers.__notion}/app/ENHANCER_VERSION.txt`
),
installed_version = (await fs.pathExists(version_path))
? await fs.readFile(version_path, 'utf8')
: '?.?.?';
if (await fs.pathExists(path.resolve(`${__notion}/app.asar`))) {
if (await fs.pathExists(path.resolve(`${helpers.__notion}/app.asar`))) {
return {
msg: `notion-enhancer has not been applied.`,
code: 0,

View File

@ -25,7 +25,7 @@ const is_wsl =
process.platform === 'linux' &&
os.release().toLowerCase().includes('microsoft'),
// ~/.notion-enhancer absolute path.
data_folder = path.resolve(
__data = path.resolve(
`${
is_wsl
? (() => {
@ -40,7 +40,59 @@ const is_wsl =
})()
: os.homedir()
}/.notion-enhancer`
);
),
// gets possible system notion app filepaths.
__notion = (() => {
let folder = '';
switch (process.platform) {
case 'darwin':
folder = '/Applications/Notion.app/Contents/Resources';
break;
case 'win32':
folder = process.env.LOCALAPPDATA + '\\Programs\\Notion\\resources';
break;
case 'linux':
if (is_wsl) {
const stdout = execSync('cmd.exe /c echo %localappdata%', {
encoding: 'utf8',
}),
drive = stdout[0];
folder = `/mnt/${drive.toLowerCase()}${stdout
.replace(/\\/g, '/')
.slice(2)
.trim()}/Programs/Notion/resources`;
} else {
for (let loc of [
'/usr/lib/notion-desktop/resources', // https://github.com/davidbailey00/notion-deb-builder/
'/opt/notion-app', // https://aur.archlinux.org/packages/notion-app/
'/opt/notion', // https://github.com/jaredallard/notion-app
]) {
if (fs.pathExistsSync(loc)) folder = loc;
}
}
}
if (!folder)
throw new EnhancerError('nothing found: platform not supported.');
// check if actual app files are present.
// if app/app.asar are missing but app.asar.bak present it will be moved to app.asar
const app_asar = path.resolve(`${folder}/app.asar`);
if (
!(
fs.pathExistsSync(folder) &&
(fs.pathExistsSync(app_asar) ||
fs.pathExistsSync(path.resolve(`${folder}/app`)))
)
) {
const asar_bak = path.resolve(`${folder}/app.asar.bak`);
if (fs.pathExistsSync(asar_bak)) {
fs.moveSync(asar_bak, app_asar);
} else
throw new EnhancerError(
'nothing found: notion installation is either corrupted or non-existent.'
);
}
return folder;
})();
// transform a wsl filepath to its relative windows filepath if necessary.
function realpath(hack_path) {
@ -52,62 +104,6 @@ function realpath(hack_path) {
return hack_path;
}
// gets possible system notion app filepaths.
function getNotion() {
let folder = '';
switch (process.platform) {
case 'darwin':
folder = '/Applications/Notion.app/Contents/Resources';
break;
case 'win32':
folder = process.env.LOCALAPPDATA + '\\Programs\\Notion\\resources';
break;
case 'linux':
if (is_wsl) {
const stdout = execSync('cmd.exe /c echo %localappdata%', {
encoding: 'utf8',
}),
drive = stdout[0];
folder = `/mnt/${drive.toLowerCase()}${stdout
.replace(/\\/g, '/')
.slice(2)
.trim()}/Programs/Notion/resources`;
} else {
for (let loc of [
'/usr/lib/notion-desktop/resources', // https://github.com/davidbailey00/notion-deb-builder/
'/opt/notion-app', // https://aur.archlinux.org/packages/notion-app/
'/opt/notion', // https://github.com/jaredallard/notion-app
]) {
if (fs.pathExistsSync(loc)) folder = loc;
}
}
}
if (!folder)
throw new EnhancerError(
'platform not supported: open a request in the github repo:\n' +
'https://github.com/dragonwocky/notion-enhancer/issues/new?labels=enhancement&template=platform-support.md'
);
// check if actual app files are present.
// if app/app.asar are missing but app.asar.bak present it will be moved to app.asar
const app_asar = path.resolve(`${folder}/app.asar`);
if (
!(
fs.pathExistsSync(folder) &&
(fs.pathExistsSync(app_asar) ||
fs.pathExistsSync(path.resolve(`${folder}/app`)))
)
) {
const asar_bak = path.resolve(`${folder}/app.asar.bak`);
if (fs.pathExistsSync(asar_bak)) {
fs.moveSync(asar_bak, app_asar);
} else
throw new EnhancerError(
'nothing found: notion installation is either corrupted or non-existent.'
);
}
return folder;
}
// lists/fetches all available extensions + themes
function getEnhancements() {
const modules = {
@ -179,9 +175,9 @@ function createElement(html) {
module.exports = {
EnhancerError,
is_wsl,
data_folder,
__data,
__notion,
realpath,
getNotion,
getEnhancements,
getJSON,
readline,

View File

@ -25,15 +25,15 @@ const is_wsl;
use `helpers.is_wsl` to check if the enhancer was run from the windows subsystem for linux.
primarily used for internal handling of filepaths (e.g. in the `helpers.realpath` and `helpers.getNotion` functions).
primarily used for internal handling of filepaths (e.g. in the `helpers.realpath` function).
---
```js
const data_folder;
const __data;
```
use `helpers.data_folder` to get the absolute path of the directory configuration/version
use `helpers.__data` to get the absolute path of the directory configuration
data is saved to by the enhancer.
if used immediately after being accessed, it should always work. however, if fetching its value during enhancement
@ -42,6 +42,20 @@ and then inserting it into something that will not be executed until the app is
---
```js
const __notion;
```
use `helpers.__notion` to get the absolute path of the notion app parent folder.
primarily used for internal modding of the app (e.g. to apply the modloader and patch launch scripts).
if used immediately after being accessed, it should always work. however, if fetching its value during enhancement
and then inserting it into something that will not be executed until the app is opened, it must be put through
`helpers.realpath` before insertion.
---
```js
function realpath(hack_path) {
return runtime_path;
@ -56,18 +70,6 @@ primarily used for internal handling of filepaths (e.g. for the modloader).
---
```js
function getNotion() {
return notion_app_path;
}
```
use `await helpers.getNotion()` to get the notion app parent folder path.
primarily used for internal modding of the app (e.g. to apply the modloader and patch launch scripts).
---
```js
function getEnhancements() {
return { loaded, invalid, dirs, IDs };

View File

@ -11,10 +11,9 @@ const fs = require('fs-extra'),
helpers = require('./helpers.js'),
store = require('./store.js');
let __notion = helpers.getNotion();
module.exports = function (__file, __exports) {
__file = __file
.slice(path.resolve(`${__notion}/app`).length + 1)
.slice(path.resolve(`${helpers.__notion}/app`).length + 1)
.replace(/\\/g, '/');
if (__file === 'main/security.js') {

View File

@ -18,28 +18,25 @@ const fs = require('fs-extra'),
// ~~ exit
// ### error ###
let __notion = helpers.getNotion();
module.exports = async function ({
overwrite_asar,
delete_data,
friendly_errors,
} = {}) {
try {
const file_operations = [];
// extracted asar: modded
const app_folder = path.resolve(`${__notion}/app`);
const app_folder = path.resolve(`${helpers.__notion}/app`);
if (await fs.pathExists(app_folder)) {
console.info(` ...removing folder ${app_folder}`);
await fs.remove(app_folder);
} else console.warn(` * ${app_folder} not found: step skipped.`);
// restoring original asar
const asar_bak = path.resolve(`${__notion}/app.asar.bak`);
const asar_bak = path.resolve(`${helpers.__notion}/app.asar.bak`);
if (await fs.pathExists(asar_bak)) {
console.info(' ...moving asar.app.bak to app.asar');
if (await fs.pathExists(path.resolve(`${__notion}/app.asar`))) {
if (await fs.pathExists(path.resolve(`${helpers.__notion}/app.asar`))) {
console.warn(' * app.asar already exists!');
if (overwrite_asar === undefined) {
do {
@ -60,15 +57,15 @@ module.exports = async function ({
}
await (overwrite_asar || overwrite_asar === undefined
? fs.move(asar_bak, path.resolve(`${__notion}/app.asar`), {
? fs.move(asar_bak, path.resolve(`${helpers.__notion}/app.asar`), {
overwrite: true,
})
: fs.remove(asar_bak));
} else console.warn(` * ${asar_bak} not found: step skipped.`);
// cleaning data folder: ~/.notion-enhancer
if (await fs.pathExists(helpers.data_folder)) {
console.info(` ...data folder ${helpers.data_folder} found.`);
if (await fs.pathExists(helpers.__data)) {
console.info(` ...data folder ${helpers.__data} found.`);
if (delete_data === undefined) {
do {
process.stdout.write(' > delete? [Y/n]: ');
@ -81,27 +78,25 @@ module.exports = async function ({
}
console.info(
delete_data
? ` -- deleting ${helpers.data_folder}`
: ` -- keeping ${helpers.data_folder}`
? ` -- deleting ${helpers.__data}`
: ` -- keeping ${helpers.__data}`
);
if (delete_data) {
await fs.remove(helpers.data_folder);
} else fs.remove(path.resolve(`${helpers.data_folder}/version.txt`));
} else console.warn(` * ${helpers.data_folder} not found: step skipped.`);
if (delete_data) await fs.remove(helpers.__data);
} else console.warn(` * ${helpers.__data} not found: step skipped.`);
// patching launch script target of custom wrappers
if (
[
'/opt/notion-app', // https://aur.archlinux.org/packages/notion-app/
'/opt/notion', // https://github.com/jaredallard/notion-app
].includes(__notion)
].includes(helpers.__notion)
) {
console.info(
' ...patching app launcher (notion-app linux wrappers only).'
);
for (let bin_path of [
`/usr/bin/${__notion.split('/')[2]}`,
`${__notion}/${__notion.split('/')[2]}`,
`/usr/bin/${helpers.__notion.split('/')[2]}`,
`${helpers.__notion}/${helpers.__notion.split('/')[2]}`,
]) {
const bin_script = await fs.readFile(bin_path, 'utf8');
if (!bin_script.includes('app.asar')) {

View File

@ -8,12 +8,12 @@
const path = require('path'),
fs = require('fs-extra'),
{ getJSON, data_folder } = require('./helpers.js');
{ getJSON, __data } = require('./helpers.js');
// a wrapper for accessing data stored in a JSON file.
module.exports = (namespace, defaults = {}) => {
namespace = path.resolve(`${data_folder}/${namespace}.json`);
fs.ensureDirSync(data_folder);
namespace = path.resolve(`${__data}/${namespace}.json`);
fs.ensureDirSync(__data);
let data;
const saveData = () => fs.writeJsonSync(namespace, data),