diff --git a/pkg/apply.js b/pkg/apply.js index 63132a8..7147563 100644 --- a/pkg/apply.js +++ b/pkg/apply.js @@ -10,7 +10,7 @@ const fs = require('fs-extra'), path = require('path'), { readdirIterator } = require('readdir-enhanced'), { extractAll } = require('asar'), - { readline, realpath, getNotionResources } = require('./helpers.js'), + { readline, getNotionResources } = require('./helpers.js'), { version } = require('../package.json'); // === title === diff --git a/pkg/helpers.js b/pkg/helpers.js index e87a4ee..d83044b 100644 --- a/pkg/helpers.js +++ b/pkg/helpers.js @@ -8,8 +8,7 @@ const os = require('os'), path = require('path'), - fs = require('fs-extra'), - { execSync } = require('child_process'); + fs = require('fs-extra'); // used to differentiate between "enhancer failed" and "code broken" errors. class EnhancerError extends Error { @@ -22,35 +21,26 @@ class EnhancerError extends Error { // checks if being run on the windows subsystem for linux: // used to modify windows notion app. const is_wsl = - process.platform === 'linux' && - os.release().toLowerCase().includes('microsoft'), - // ~/.notion-enhancer absolute path. - __data = path.resolve( - `${ - is_wsl - ? (() => { - const stdout = execSync('cmd.exe /c echo %systemdrive%%homepath%', { - encoding: 'utf8', - }), - drive = stdout[0]; - return `/mnt/${drive.toLowerCase()}${stdout - .replace(/\\/g, '/') - .slice(2) - .trim()}`; - })() - : os.homedir() - }/.notion-enhancer` - ); + process.platform === 'linux' && + os.release().toLowerCase().includes('microsoft'); -// transform a wsl filepath to its relative windows filepath if necessary. -function realpath(hack_path) { - if (!is_wsl) return hack_path.replace(/\\/g, '/'); - hack_path = fs.realpathSync(hack_path); - if (hack_path.startsWith('/mnt/')) { - hack_path = `${hack_path[5].toUpperCase()}:${hack_path.slice(6)}`; - } else hack_path = `//wsl$/${process.env.WSL_DISTRO_NAME}${hack_path}`; - return hack_path; -} +// ~/.notion-enhancer absolute path. +const __data = path.resolve( + `${ + is_wsl + ? (() => { + const stdout = execSync('cmd.exe /c echo %systemdrive%%homepath%', { + encoding: 'utf8', + }), + drive = stdout[0]; + return `/mnt/${drive.toLowerCase()}${stdout + .replace(/\\/g, '/') + .slice(2) + .trim()}`; + })() + : os.homedir() + }/.notion-enhancer` +); // gets system notion app filepath. function getNotionResources() { @@ -159,9 +149,7 @@ function createElement(html) { module.exports = { EnhancerError, - is_wsl, __data, - realpath, getNotionResources, getEnhancements, getJSON, diff --git a/pkg/helpers.md b/pkg/helpers.md index 2e60e8a..d4b7919 100644 --- a/pkg/helpers.md +++ b/pkg/helpers.md @@ -19,16 +19,6 @@ but is not caused by faulty programming: e.g. if a file that is known to exist c --- -```js -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` function). - ---- - ```js const __data; ``` @@ -36,24 +26,6 @@ const __data; 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 -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; -} -``` - -use `helpers.realpath(hack_path)` to transform a path valid at enhancement time into one valid when the app is opened. -this is particularly useful for wsl compatibility, so every filepath that is fetched during enhancement -and then inserted into something that will not be executed until the app is opened should be put through this. - -primarily used for internal handling of filepaths (e.g. for the modloader). - --- ```js @@ -66,10 +38,6 @@ use `helpers.getNotionResources()` to get the absolute path of the notion app pa 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