moyicat / inkdrop-code-fold

Code fold plugin for Inkdrop
MIT License
5 stars 6 forks source link

Inkdrop 5.6.0 breaks plugin #11

Open marksweiss opened 1 year ago

marksweiss commented 1 year ago

After the upgrade, this error message upon launch or re-install of plugin:

image
marksweiss commented 10 months ago

Dug into this more. The failing line is here. The issue appears to be that app.getAppPath() returns Applications/Inkdrop.app/Contents/Resources/app.asar/... whereas the actual path where node_modules is present does not have the app.asar portion. I looked in Applications/Inkdrop.app/Contents/Resource and there is an app.asar there but it is not a directory. So this dependency on getAppPath() appears to the be issue. I don't know enough about node or Electron to identify the correct solution without more digging but hopefully this is helpful.

Keisir commented 5 months ago

The error (loading of codemirror addons) can be fixed with this patch. (See mravenel/inkdrop-rulers#1)

diff --git a/lib/code-fold.js b/lib/code-fold.js
index ed1613e..409eb0b 100644
--- a/lib/code-fold.js
+++ b/lib/code-fold.js
@@ -1,5 +1,6 @@
+const path = require('node:path');
 const app = require('@electron/remote').app;
-const modulePath = app.getAppPath() + '/node_modules/'
+const modulePath = path.dirname(app.getAppPath()) + '/node_modules/'
 require(modulePath + 'codemirror/addon/fold/foldcode.js');
 require(modulePath + 'codemirror/addon/fold/foldgutter.js');
 require(modulePath + 'codemirror/addon/fold/markdown-fold.js');

With this patch I am again able to expand and collapse sections with the corresponding keybindings. The UI (the small arrow icons) are broken. (are not displayed)

It seems like this plugin is not maintained for a while now, so I didn't create a PR as it possibly wouldn't be merged. But if anyone wants to use this, you can just apply the patch locally.

/cc @marksweiss

Edit: I have also pushed the code to my fork. (Keisir/inkdrop-code-fold@44d834b292295e6ca8e867f99821762670c9651f)

Keisir commented 1 week ago

The code fold plugin in the inkdrop plugin registry will be updated from now on through a fork of this repo. This issue has been fixed there.