mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-05 05:09:03 +00:00
refactor __notion back to a function for error handling, replace missing executables with backups in check
This commit is contained in:
parent
e91a363b08
commit
eadbec249b
3
bin.js
3
bin.js
@ -47,7 +47,8 @@ cli
|
||||
.command('check', ': check the current state of the notion app')
|
||||
.action(async (options) => {
|
||||
try {
|
||||
console.info((await require('./pkg/check.js')()).msg);
|
||||
const status = await require('./pkg/check.js')();
|
||||
console.info(options.dev ? status : status.msg);
|
||||
} catch (err) {
|
||||
console.error(err instanceof EnhancerError ? err.message : err);
|
||||
}
|
||||
|
@ -10,10 +10,9 @@
|
||||
module.exports = (store, __exports) => {
|
||||
const electron = require('electron'),
|
||||
helpers = require('../../pkg/helpers.js'),
|
||||
notionIpc = require(`${helpers.__notion.replace(
|
||||
/\\/g,
|
||||
'/'
|
||||
)}/app/helpers/notionIpc.js`),
|
||||
notionIpc = require(`${helpers
|
||||
.getNotionResources()
|
||||
.replace(/\\/g, '/')}/app/helpers/notionIpc.js`),
|
||||
{ toKeyEvent } = require('keyboardevent-from-electron-accelerator'),
|
||||
tabsEnabled = (store('mods')['e1692c29-475e-437b-b7ff-3eee872e1a42'] || {})
|
||||
.enabled;
|
||||
|
@ -19,13 +19,14 @@ module.exports = (store, __exports) => {
|
||||
|
||||
__exports.createWindow = function (relativeUrl, focused_window) {
|
||||
if (!relativeUrl) relativeUrl = '';
|
||||
const window_state = require(`${helpers.__notion.replace(
|
||||
/\\/g,
|
||||
'/'
|
||||
)}/app/node_modules/electron-window-state/index.js`)({
|
||||
defaultWidth: 1320,
|
||||
defaultHeight: 860,
|
||||
}),
|
||||
const window_state = require(`${helpers
|
||||
.getNotionResources()
|
||||
.replace(/\\/g, '/')}/app/node_modules/electron-window-state/index.js`)(
|
||||
{
|
||||
defaultWidth: 1320,
|
||||
defaultHeight: 860,
|
||||
}
|
||||
),
|
||||
rect = {
|
||||
x: window_state.x,
|
||||
y: window_state.y,
|
||||
@ -46,7 +47,9 @@ module.exports = (store, __exports) => {
|
||||
titleBarStyle: 'hiddenInset',
|
||||
frame: !store().frameless,
|
||||
webPreferences: {
|
||||
preload: path.resolve(`${helpers.__notion}/app/renderer/index.js`),
|
||||
preload: path.resolve(
|
||||
`${helpers.getNotionResources()}/app/renderer/index.js`
|
||||
),
|
||||
webviewTag: true,
|
||||
session: electron.session.fromPartition('persist:notion'),
|
||||
enableRemoteModule: true,
|
||||
|
@ -11,10 +11,11 @@ const url = require('url'),
|
||||
electron = require('electron'),
|
||||
fs = require('fs-extra'),
|
||||
{
|
||||
__notion,
|
||||
getNotionResources,
|
||||
getEnhancements,
|
||||
createElement,
|
||||
} = require('../../pkg/helpers.js'),
|
||||
__notion = getNotionResources(),
|
||||
config = require(`${__notion}/app/config.js`),
|
||||
constants = require(`${__notion}/app/shared/constants.js`),
|
||||
notion_intl = require(`${__notion}/app/shared/notion-intl/index.js`),
|
||||
|
@ -9,7 +9,8 @@
|
||||
module.exports = (store, __exports) => {
|
||||
const electron = require('electron'),
|
||||
fs = require('fs-extra'),
|
||||
{ __notion } = require('../../pkg/helpers.js'),
|
||||
{ getNotionResources } = require('../../pkg/helpers.js'),
|
||||
__notion = getNotionResources(),
|
||||
createWindow = require(`${__notion}/app/main/createWindow.js`),
|
||||
config = require(`${__notion}/app/config.js`),
|
||||
notion_intl = require(`${__notion}/app/shared/notion-intl/index.js`),
|
||||
|
@ -20,7 +20,9 @@ module.exports = (store, __exports) => {
|
||||
function newWindow() {
|
||||
require('./createWindow.js')(
|
||||
store,
|
||||
require(path.resolve(`${helpers.__notion}/app/main/createWindow.js`))
|
||||
require(path.resolve(
|
||||
`${helpers.getNotionResources()}/app/main/createWindow.js`
|
||||
))
|
||||
)(
|
||||
'',
|
||||
getAllWindows().find((win) => win !== enhancer_menu)
|
||||
@ -113,15 +115,16 @@ module.exports = (store, __exports) => {
|
||||
|
||||
function openEnhancerMenu() {
|
||||
if (enhancer_menu) return enhancer_menu.show();
|
||||
const window_state = require(`${helpers.__notion.replace(
|
||||
/\\/g,
|
||||
'/'
|
||||
)}/app/node_modules/electron-window-state/index.js`)({
|
||||
file: 'menu.windowstate.json',
|
||||
path: helpers.__data,
|
||||
defaultWidth: 275,
|
||||
defaultHeight: 600,
|
||||
});
|
||||
const window_state = require(`${helpers
|
||||
.getNotionResources()
|
||||
.replace(/\\/g, '/')}/app/node_modules/electron-window-state/index.js`)(
|
||||
{
|
||||
file: 'menu.windowstate.json',
|
||||
path: helpers.__data,
|
||||
defaultWidth: 275,
|
||||
defaultHeight: 600,
|
||||
}
|
||||
);
|
||||
enhancer_menu = new electron.BrowserWindow({
|
||||
show: true,
|
||||
frame: !store().frameless,
|
||||
|
31
pkg/apply.js
31
pkg/apply.js
@ -10,7 +10,7 @@ const fs = require('fs-extra'),
|
||||
path = require('path'),
|
||||
{ readdirIterator } = require('readdir-enhanced'),
|
||||
{ extractAll } = require('asar'),
|
||||
helpers = require('./helpers.js'),
|
||||
{ readline, realpath, getNotionResources } = require('./helpers.js'),
|
||||
{ version } = require('../package.json');
|
||||
|
||||
// === title ===
|
||||
@ -22,6 +22,7 @@ const fs = require('fs-extra'),
|
||||
// ### error ###
|
||||
|
||||
module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
|
||||
const __notion = getNotionResources();
|
||||
try {
|
||||
// handle pre-existing installations: app.asar present? version set in data folder? overwrite?
|
||||
const check_app = await require('./check.js')();
|
||||
@ -41,7 +42,7 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
|
||||
}
|
||||
while (!valid()) {
|
||||
process.stdout.write(' > overwrite? [Y/n]: ');
|
||||
overwrite_version = await helpers.readline();
|
||||
overwrite_version = await readline();
|
||||
}
|
||||
if (overwrite_version.toLowerCase() === 'n') {
|
||||
console.info(' ~~ keeping previous version: exiting.');
|
||||
@ -60,9 +61,9 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
|
||||
}
|
||||
}
|
||||
console.info(' ...unpacking app.asar.');
|
||||
const asar_app = path.resolve(`${helpers.__notion}/app.asar`),
|
||||
asar_bak = path.resolve(`${helpers.__notion}/app.asar.bak`);
|
||||
extractAll(asar_app, `${path.resolve(`${helpers.__notion}/app`)}`);
|
||||
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);
|
||||
|
||||
@ -71,14 +72,14 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
|
||||
[
|
||||
'/opt/notion-app', // https://aur.archlinux.org/packages/notion-app/
|
||||
'/opt/notion', // https://github.com/jaredallard/notion-app
|
||||
].includes(helpers.__notion)
|
||||
].includes(__notion)
|
||||
) {
|
||||
console.info(
|
||||
' ...patching app launcher (notion-app linux wrappers only).'
|
||||
);
|
||||
for (let bin_path of [
|
||||
`/usr/bin/${helpers.__notion.split('/')[2]}`,
|
||||
`${helpers.__notion}/${helpers.__notion.split('/')[2]}`,
|
||||
`/usr/bin/${__notion.split('/')[2]}`,
|
||||
`${__notion}/${__notion.split('/')[2]}`,
|
||||
]) {
|
||||
const bin_script = await fs.readFile(bin_path, 'utf8');
|
||||
if (bin_script.includes('app.asar')) {
|
||||
@ -95,24 +96,24 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
|
||||
// patching app properties so dark/light mode can be detected
|
||||
if (
|
||||
process.platform === 'darwin' &&
|
||||
(await fs.pathExists(path.resolve(`${helpers.__notion}/../Info.plist`)))
|
||||
(await fs.pathExists(path.resolve(`${__notion}/../Info.plist`)))
|
||||
) {
|
||||
fs.copy(
|
||||
path.resolve(`${__dirname}/Info.plist`),
|
||||
path.resolve(`${helpers.__notion}/../Info.plist`),
|
||||
path.resolve(`${__notion}/../Info.plist`),
|
||||
{ overwrite: true }
|
||||
);
|
||||
}
|
||||
|
||||
for await (let insertion_target of readdirIterator(
|
||||
path.resolve(`${helpers.__notion}/app`),
|
||||
path.resolve(`${__notion}/app`),
|
||||
{
|
||||
deep: (stats) => stats.path.indexOf('node_modules') === -1,
|
||||
filter: (stats) => stats.isFile() && stats.path.endsWith('.js'),
|
||||
}
|
||||
)) {
|
||||
const insertion_file = path.resolve(
|
||||
`${helpers.__notion}/app/${insertion_target}`
|
||||
`${__notion}/app/${insertion_target}`
|
||||
);
|
||||
if (insertion_target === 'main/main.js') {
|
||||
// https://github.com/notion-enhancer/notion-enhancer/issues/160
|
||||
@ -129,7 +130,7 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
|
||||
.replace(
|
||||
/else \{[\s\n]+const win = createWindow_1\.createWindow\(relativeUrl\);/g,
|
||||
'else if (relativeUrl) { const win = createWindow_1.createWindow(relativeUrl);'
|
||||
)}\n\n//notion-enhancer\nrequire('${helpers.realpath(
|
||||
)}\n\n//notion-enhancer\nrequire('${realpath(
|
||||
__dirname
|
||||
)}/loader.js')(__filename, exports);`,
|
||||
'utf8',
|
||||
@ -141,7 +142,7 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
|
||||
} else {
|
||||
fs.appendFile(
|
||||
insertion_file,
|
||||
`\n\n//notion-enhancer\nrequire('${helpers.realpath(
|
||||
`\n\n//notion-enhancer\nrequire('${realpath(
|
||||
__dirname
|
||||
)}/loader.js')(__filename, exports);`
|
||||
);
|
||||
@ -152,7 +153,7 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
|
||||
// so it's just a "let it do its thing"
|
||||
console.info(' ...recording enhancement version.');
|
||||
fs.outputFile(
|
||||
path.resolve(`${helpers.__notion}/app/ENHANCER_VERSION.txt`),
|
||||
path.resolve(`${__notion}/app/ENHANCER_VERSION.txt`),
|
||||
version
|
||||
);
|
||||
|
||||
|
73
pkg/check.js
73
pkg/check.js
@ -8,40 +8,63 @@
|
||||
|
||||
const fs = require('fs-extra'),
|
||||
path = require('path'),
|
||||
helpers = require('./helpers.js'),
|
||||
{ version } = require('../package.json'),
|
||||
pathExists = (filepath) => fs.pathExists(path.resolve(filepath));
|
||||
{ getNotionResources } = require('./helpers.js'),
|
||||
{ version } = require('../package.json');
|
||||
|
||||
module.exports = async function () {
|
||||
const version_path = `${helpers.__notion}/app/ENHANCER_VERSION.txt`;
|
||||
const __notion = getNotionResources(),
|
||||
resolvePath = (filepath) => path.resolve(`${__notion}/${filepath}`),
|
||||
pathExists = (filepath) => fs.pathExists(resolvePath(filepath)),
|
||||
version_path = 'app/ENHANCER_VERSION.txt',
|
||||
packed = await pathExists('app.asar.bak');
|
||||
let backup = packed
|
||||
? (await pathExists('app.asar.bak'))
|
||||
? `app.asar.bak`
|
||||
: undefined
|
||||
: (await pathExists('app.bak'))
|
||||
? 'app.bak'
|
||||
: undefined;
|
||||
if (!(await pathExists(version_path))) {
|
||||
return {
|
||||
msg: `notion-enhancer has not been applied.`,
|
||||
code: 0,
|
||||
};
|
||||
}
|
||||
const installed_version = await fs.readFile(version_path, 'utf8'),
|
||||
packed = await pathExists(`${helpers.__notion}/app.asar`),
|
||||
backup = packed
|
||||
? (await pathExists(`${helpers.__notion}/app.asar.bak`))
|
||||
? `${helpers.__notion}/app.asar.bak`
|
||||
: undefined
|
||||
: (await pathExists(`${helpers.__notion}/app.bak`))
|
||||
? `${helpers.__notion}/app.bak`
|
||||
let executable = (await pathExists('app'))
|
||||
? 'app'
|
||||
: (await pathExists('app.asar'))
|
||||
? 'app.asar'
|
||||
: undefined;
|
||||
if (!executable && backup) {
|
||||
backup = resolvePath(backup);
|
||||
executable = backup.replace(/\.bak$/, '');
|
||||
await fs.move(backup, executable);
|
||||
} else executable = resolvePath(executable);
|
||||
return executable
|
||||
? {
|
||||
code: 0,
|
||||
msg: `notion-enhancer has not been applied.`,
|
||||
executable,
|
||||
}
|
||||
: {
|
||||
code: 1,
|
||||
msg: `notion installation has been corrupted: no executable found.`,
|
||||
};
|
||||
}
|
||||
const installed_version = await fs.readFile(
|
||||
resolvePath(version_path),
|
||||
'utf8'
|
||||
),
|
||||
meta = {
|
||||
version: installed_version,
|
||||
executable: resolvePath('app'),
|
||||
packed: resolvePath(packed),
|
||||
backup: resolvePath(backup),
|
||||
};
|
||||
return installed_version === version
|
||||
? {
|
||||
code: 2,
|
||||
msg: `notion-enhancer v${version} applied.`,
|
||||
version: installed_version,
|
||||
packed,
|
||||
backup,
|
||||
code: 1,
|
||||
...meta,
|
||||
}
|
||||
: {
|
||||
code: 3,
|
||||
msg: `notion-enhancer v${installed_version} found applied != v${version} package.`,
|
||||
version: installed_version,
|
||||
packed,
|
||||
backup,
|
||||
code: 2,
|
||||
...meta,
|
||||
};
|
||||
};
|
||||
|
@ -40,62 +40,7 @@ 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/haydn/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;
|
||||
})();
|
||||
|
||||
// safely backup & transform either an app folder or an app.asar file into a folder
|
||||
function enhanceableApp() {}
|
||||
);
|
||||
|
||||
// transform a wsl filepath to its relative windows filepath if necessary.
|
||||
function realpath(hack_path) {
|
||||
@ -107,6 +52,41 @@ function realpath(hack_path) {
|
||||
return hack_path;
|
||||
}
|
||||
|
||||
// gets possible system notion app filepaths.
|
||||
function getNotionResources() {
|
||||
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/haydn/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.');
|
||||
return folder;
|
||||
}
|
||||
|
||||
// lists/fetches all available extensions + themes
|
||||
function getEnhancements() {
|
||||
const modules = {
|
||||
@ -206,8 +186,8 @@ module.exports = {
|
||||
EnhancerError,
|
||||
is_wsl,
|
||||
__data,
|
||||
__notion,
|
||||
realpath,
|
||||
getNotionResources,
|
||||
getEnhancements,
|
||||
getJSON,
|
||||
readline,
|
||||
|
@ -42,20 +42,6 @@ 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;
|
||||
@ -70,6 +56,22 @@ primarily used for internal handling of filepaths (e.g. for the modloader).
|
||||
|
||||
---
|
||||
|
||||
```js
|
||||
function getNotionResources() {
|
||||
return __notionResourcesFolder;
|
||||
}
|
||||
```
|
||||
|
||||
use `helpers.getNotionResources()` 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 getEnhancements() {
|
||||
return { loaded, invalid, dirs, IDs };
|
||||
|
@ -8,12 +8,16 @@
|
||||
|
||||
const fs = require('fs-extra'),
|
||||
path = require('path'),
|
||||
{ __notion, getEnhancements, createElement } = require('./helpers.js'),
|
||||
{
|
||||
getNotionResources,
|
||||
getEnhancements,
|
||||
createElement,
|
||||
} = require('./helpers.js'),
|
||||
store = require('./store.js');
|
||||
|
||||
module.exports = function (__file, __exports) {
|
||||
__file = __file
|
||||
.slice(path.resolve(`${__notion}/app`).length + 1)
|
||||
.slice(path.resolve(`${getNotionResources()}/app`).length + 1)
|
||||
.replace(/\\/g, '/');
|
||||
|
||||
if (__file === 'main/security.js') {
|
||||
@ -64,12 +68,10 @@ module.exports = function (__file, __exports) {
|
||||
if (document.readyState !== 'complete') return false;
|
||||
for (let mod of modules) {
|
||||
if (
|
||||
(mod.alwaysActive ||
|
||||
store('mods', { [mod.id]: { enabled: false } })[mod.id].enabled)
|
||||
mod.alwaysActive ||
|
||||
store('mods', { [mod.id]: { enabled: false } })[mod.id].enabled
|
||||
) {
|
||||
const fileExists = (file) => fs.pathExistsSync(
|
||||
path.resolve(file)
|
||||
)
|
||||
const fileExists = (file) => fs.pathExistsSync(path.resolve(file));
|
||||
for (let sheet of ['app', 'variables']) {
|
||||
if (fileExists(`${__dirname}/../mods/${mod.dir}/${sheet}.css`)) {
|
||||
document.head.appendChild(
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
const fs = require('fs-extra'),
|
||||
path = require('path'),
|
||||
helpers = require('./helpers.js');
|
||||
{ readline, getNotionResources, __data } = require('./helpers.js');
|
||||
|
||||
// === title ===
|
||||
// ...information
|
||||
@ -19,30 +19,30 @@ const fs = require('fs-extra'),
|
||||
// ### error ###
|
||||
|
||||
module.exports = async function ({ delete_data, friendly_errors } = {}) {
|
||||
const __notion = getNotionResources();
|
||||
try {
|
||||
// extracted asar: modded
|
||||
const app_folder = path.resolve(`${helpers.__notion}/app`);
|
||||
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.`);
|
||||
|
||||
// restoring original asar
|
||||
const asar_bak = path.resolve(`${helpers.__notion}/app.asar.bak`);
|
||||
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(`${helpers.__notion}/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(`${helpers.__notion}/app.asar`));
|
||||
} else await fs.move(asar_bak, path.resolve(`${__notion}/app.asar`));
|
||||
} else console.warn(` * ${asar_bak} not found: step skipped.`);
|
||||
|
||||
// cleaning data folder: ~/.notion-enhancer
|
||||
if (await fs.pathExists(helpers.__data)) {
|
||||
console.info(` ...data folder ${helpers.__data} found.`);
|
||||
if (await fs.pathExists(__data)) {
|
||||
console.info(` ...data folder ${__data} found.`);
|
||||
const valid = () =>
|
||||
typeof delete_data === 'string' &&
|
||||
['y', 'n', ''].includes(delete_data.toLowerCase());
|
||||
@ -50,29 +50,29 @@ module.exports = async function ({ delete_data, friendly_errors } = {}) {
|
||||
console.info(` > delete? [Y/n]: ${delete_data.toLowerCase()}`);
|
||||
while (!valid()) {
|
||||
process.stdout.write(' > delete? [Y/n]: ');
|
||||
delete_data = await helpers.readline();
|
||||
delete_data = await readline();
|
||||
}
|
||||
console.info(
|
||||
delete_data.toLowerCase() === 'n'
|
||||
? ` -- keeping ${helpers.__data}`
|
||||
: ` -- deleting ${helpers.__data}`
|
||||
? ` -- keeping ${__data}`
|
||||
: ` -- deleting ${__data}`
|
||||
);
|
||||
if (delete_data.toLowerCase() !== 'n') await fs.remove(helpers.__data);
|
||||
} else console.warn(` * ${helpers.__data} not found: step skipped.`);
|
||||
if (delete_data.toLowerCase() !== 'n') await fs.remove(__data);
|
||||
} else console.warn(` * ${__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(helpers.__notion)
|
||||
].includes(__notion)
|
||||
) {
|
||||
console.info(
|
||||
' ...patching app launcher (notion-app linux wrappers only).'
|
||||
);
|
||||
for (let bin_path of [
|
||||
`/usr/bin/${helpers.__notion.split('/')[2]}`,
|
||||
`${helpers.__notion}/${helpers.__notion.split('/')[2]}`,
|
||||
`/usr/bin/${__notion.split('/')[2]}`,
|
||||
`${__notion}/${__notion.split('/')[2]}`,
|
||||
]) {
|
||||
const bin_script = await fs.readFile(bin_path, 'utf8');
|
||||
if (!bin_script.includes('app.asar')) {
|
||||
|
Loading…
Reference in New Issue
Block a user