diff --git a/bin.js b/bin.js index b037028..1242a91 100755 --- a/bin.js +++ b/bin.js @@ -50,7 +50,9 @@ cli const status = await require('./pkg/check.js')(); console.info(options.dev ? status : status.msg); } catch (err) { - console.error(err instanceof EnhancerError ? err.message : err); + console.error( + err instanceof EnhancerError && !options.dev ? err.message : err + ); } }); diff --git a/pkg/apply.js b/pkg/apply.js index 80dd730..ebfa5cb 100644 --- a/pkg/apply.js +++ b/pkg/apply.js @@ -28,9 +28,11 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) { const check_app = await require('./check.js')(); switch (check_app.code) { case 1: + throw Error(check_app.msg); + case 2: console.info(`~~ notion-enhancer v${version} already applied.`); return true; - case 2: + case 3: console.warn(` * ${check_app.msg}`); const valid = () => typeof overwrite_version === 'string' && @@ -60,12 +62,16 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) { return false; } } - console.info(' ...unpacking app.asar.'); - const asar_app = path.resolve(`${__notion}/app.asar`), - asar_bak = path.resolve(`${__notion}/app.asar.bak`); - extractAll(asar_app, `${path.resolve(`${__notion}/app`)}`); - if (await fs.pathExists(asar_bak)) fs.remove(asar_bak); - await fs.move(asar_app, asar_bak); + if (check_app.executable.endsWith('app.asar')) { + console.info(' ...unpacking app.asar.'); + const asar_bak = path.resolve(`${__notion}/app.asar.bak`); + extractAll(check_app.executable, `${path.resolve(`${__notion}/app`)}`); + if (await fs.pathExists(asar_bak)) fs.remove(asar_bak); + await fs.move(check_app.executable, asar_bak); + } else { + console.info(' ...backing up default app.'); + await fs.copy(check_app.executable, check_app.executable + '.bak'); + } // patching launch script target of custom wrappers if ( @@ -149,7 +155,7 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) { } } - // not resolved, nothing else in application depends on it + // not resolved, nothing else in apply process depends on it // so it's just a "let it do its thing" console.info(' ...recording enhancement version.'); fs.outputFile( @@ -177,7 +183,7 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) { )}"` : '' }` - }` + }, and make sure path(s) are not open.` ); } else if (['EIO', 'EBUSY'].includes(err.code) && friendly_errors) { console.error("file access failed: make sure notion isn't running!"); diff --git a/pkg/check.js b/pkg/check.js index d57d93e..6a19fde 100644 --- a/pkg/check.js +++ b/pkg/check.js @@ -34,7 +34,7 @@ module.exports = async function () { backup = resolvePath(backup); executable = backup.replace(/\.bak$/, ''); await fs.move(backup, executable); - } else executable = resolvePath(executable); + } else executable = executable ? resolvePath(executable) : ''; return executable ? { code: 0, diff --git a/pkg/remove.js b/pkg/remove.js index ee1e871..b6e301c 100644 --- a/pkg/remove.js +++ b/pkg/remove.js @@ -19,26 +19,20 @@ const fs = require('fs-extra'), // ### error ### module.exports = async function ({ delete_data, friendly_errors } = {}) { - const __notion = getNotionResources(); try { + const __notion = getNotionResources(), + check_app = await require('./check.js')(); // extracted asar: modded - const app_folder = path.resolve(`${__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.`); + if (check_app.code > 1 && check_app.executable) { + console.info(` ...removing enhancements`); + await fs.remove(check_app.executable); + } else console.warn(` * enhancements not found: step skipped.`); // restoring original asar - const asar_bak = path.resolve(`${__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`))) { - console.warn(' * app.asar already exists!'); - console.info(' -- removing app.asar.bak'); - fs.remove(asar_bak); - } else await fs.move(asar_bak, path.resolve(`${__notion}/app.asar`)); - } else console.warn(` * ${asar_bak} not found: step skipped.`); + if (check_app.backup) { + console.info(' ...restoring backup'); + await fs.move(check_app.backup, check_app.backup.replace(/\.bak$/, '')); + } else console.warn(` * backup not found: step skipped.`); // cleaning data folder: ~/.notion-enhancer if (await fs.pathExists(__data)) { @@ -107,7 +101,7 @@ module.exports = async function ({ delete_data, friendly_errors } = {}) { )}"` : '' }` - }` + }, and make sure path(s) are not open.` ); } else if (['EIO', 'EBUSY'].includes(err.code) && friendly_errors) { console.error("file access failed: make sure notion isn't running!");