mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-05 13:19:03 +00:00
add store to loader, bugfix homedir with wsl
This commit is contained in:
parent
b7038cda28
commit
75cd042bd5
@ -14,7 +14,7 @@ _and explore the contents of your local extracted `app.asar`._
|
|||||||
_explore [the existing modules](https://github.com/dragonwocky/notion-enhancer/tree/js/mods/)_
|
_explore [the existing modules](https://github.com/dragonwocky/notion-enhancer/tree/js/mods/)_
|
||||||
_for examples of implementing what's described below._
|
_for examples of implementing what's described below._
|
||||||
|
|
||||||
each directory in the `mods` folder is considered a module, with the entry points `mod.js` and `styles.css`
|
each directory in the `mods` folder is considered a module, with the entry points `mod.js` and `styles.css`.
|
||||||
|
|
||||||
| file | description |
|
| file | description |
|
||||||
| ------------ | ---------------------------------------------------------------------------------------------------- |
|
| ------------ | ---------------------------------------------------------------------------------------------------- |
|
||||||
|
@ -8,9 +8,18 @@ module.exports = {
|
|||||||
id: '0f0bf8b6-eae6-4273-b307-8fc43f2ee082',
|
id: '0f0bf8b6-eae6-4273-b307-8fc43f2ee082',
|
||||||
type: 'core',
|
type: 'core',
|
||||||
name: 'notion-enhancer core',
|
name: 'notion-enhancer core',
|
||||||
|
desc:
|
||||||
|
'the modloader itself, including: the CLI, the menu, and enabling/disabling/insertion/updating of mods.',
|
||||||
version: require('../../package.json').version,
|
version: require('../../package.json').version,
|
||||||
author: 'dragonwocky',
|
author: 'dragonwocky',
|
||||||
thumb:
|
thumb:
|
||||||
'https://camo.githubusercontent.com/5c5bca9e987d986b8cc7e51066f90c6f8a84af08/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3733313634373938343332333931393933332f3733313732373235393239353032333132342f494d475f323137302e6a7067',
|
'https://camo.githubusercontent.com/5c5bca9e987d986b8cc7e51066f90c6f8a84af08/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3733313634373938343332333931393933332f3733313732373235393239353032333132342f494d475f323137302e6a7067',
|
||||||
options: [],
|
options: [],
|
||||||
|
hacks: {
|
||||||
|
'renderer/preload.js': function (store) {
|
||||||
|
const data = store({ name: 'dragonwocky' });
|
||||||
|
console.log(data.name);
|
||||||
|
data.name = 'tom';
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
const fs = require('fs-extra'),
|
const fs = require('fs-extra'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
{ readdirIterator } = require('readdir-enhanced'),
|
{ readdirIterator } = require('readdir-enhanced'),
|
||||||
|
{ promisify } = require('util'),
|
||||||
|
{ exec } = require('child_process'),
|
||||||
helpers = require('./helpers.js'),
|
helpers = require('./helpers.js'),
|
||||||
{ version } = require('../package.json');
|
{ version } = require('../package.json');
|
||||||
|
|
||||||
@ -64,7 +66,7 @@ module.exports = async function ({ overwrite_version } = {}) {
|
|||||||
'bin',
|
'bin',
|
||||||
'asar.js'
|
'asar.js'
|
||||||
);
|
);
|
||||||
await helpers.exec(
|
await promisify(exec)(
|
||||||
`"${asar_exec}" extract "${asar_app}" "${path.resolve(__notion, 'app')}"`
|
`"${asar_exec}" extract "${asar_app}" "${path.resolve(__notion, 'app')}"`
|
||||||
);
|
);
|
||||||
fs.move(asar_app, path.resolve(__notion, 'app.asar.bak'));
|
fs.move(asar_app, path.resolve(__notion, 'app.asar.bak'));
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
const os = require('os'),
|
const os = require('os'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
fs = require('fs-extra'),
|
fs = require('fs-extra'),
|
||||||
exec = require('util').promisify(require('child_process').exec);
|
{ exec, execSync } = require('child_process'),
|
||||||
|
{ promisify } = require('util');
|
||||||
|
|
||||||
// used to differentiate between "enhancer failed" and "code broken" errors.
|
// used to differentiate between "enhancer failed" and "code broken" errors.
|
||||||
class EnhancerError extends Error {
|
class EnhancerError extends Error {
|
||||||
@ -24,7 +25,21 @@ const is_wsl =
|
|||||||
process.platform === 'linux' &&
|
process.platform === 'linux' &&
|
||||||
os.release().toLowerCase().includes('microsoft'),
|
os.release().toLowerCase().includes('microsoft'),
|
||||||
// ~/.notion-enhancer absolute path.
|
// ~/.notion-enhancer absolute path.
|
||||||
data_folder = path.resolve(os.homedir(), '.notion-enhancer');
|
data_folder = 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'
|
||||||
|
);
|
||||||
|
|
||||||
// transform a wsl filepath to its relative windows filepath if necessary.
|
// transform a wsl filepath to its relative windows filepath if necessary.
|
||||||
// every file path inserted by hack.js should be put through this.
|
// every file path inserted by hack.js should be put through this.
|
||||||
@ -49,7 +64,9 @@ async function getNotion() {
|
|||||||
break;
|
break;
|
||||||
case 'linux':
|
case 'linux':
|
||||||
if (is_wsl) {
|
if (is_wsl) {
|
||||||
const { stdout } = await exec('cmd.exe /c echo %localappdata%'),
|
const { stdout } = await promisify(exec)(
|
||||||
|
'cmd.exe /c echo %localappdata%'
|
||||||
|
),
|
||||||
drive = stdout[0];
|
drive = stdout[0];
|
||||||
folder = `/mnt/${drive.toLowerCase()}${stdout
|
folder = `/mnt/${drive.toLowerCase()}${stdout
|
||||||
.replace(/\\/g, '/')
|
.replace(/\\/g, '/')
|
||||||
@ -121,5 +138,4 @@ module.exports = {
|
|||||||
getNotion,
|
getNotion,
|
||||||
getJSON,
|
getJSON,
|
||||||
readline,
|
readline,
|
||||||
exec,
|
|
||||||
};
|
};
|
||||||
|
@ -107,17 +107,3 @@ if (overwrite) {
|
|||||||
// do stuff
|
// do stuff
|
||||||
} else console.info(' -- keeping file: skipping step.');
|
} else console.info(' -- keeping file: skipping step.');
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
```js
|
|
||||||
async function exec(command[, options]) {
|
|
||||||
return child_process;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
use `helpers.exec()` to execute shell commands. it is a promisified version of node.js's
|
|
||||||
[child_process.exec(command[, options][, callback])](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback).
|
|
||||||
|
|
||||||
primarily used for internal processes (e.g. unpacking asar, fetching windows app path from the wsl).
|
|
||||||
for security reasons this should not be used by modules.
|
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const fs = require('fs-extra'),
|
const fs = require('fs-extra'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
helpers = require('./helpers.js');
|
helpers = require('./helpers.js'),
|
||||||
|
store = require('./store.js');
|
||||||
|
|
||||||
let __notion = helpers.getNotion();
|
let __notion = helpers.getNotion();
|
||||||
module.exports = async function (__file) {
|
module.exports = async function (__file) {
|
||||||
@ -30,6 +31,8 @@ module.exports = async function (__file) {
|
|||||||
!['extension', 'theme', 'core'].includes(mod.type)
|
!['extension', 'theme', 'core'].includes(mod.type)
|
||||||
)
|
)
|
||||||
throw Error;
|
throw Error;
|
||||||
|
if (mod.hacks && mod.hacks[__file])
|
||||||
|
mod.hacks[__file]((defaults) => store(mod.id, defaults));
|
||||||
loaded_mods.push(mod.name);
|
loaded_mods.push(mod.name);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
invalid_mods.push(dir);
|
invalid_mods.push(dir);
|
||||||
|
Loading…
Reference in New Issue
Block a user