SilentVoid13 / Templater Public
generated from obsidianmd/obsidian-sample-pluginNew issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
user function seems not to work on mobile #223
Comments
|
Hey @ebullient, you are correct user script functions are not working on mobile atm, but that's because I have to use the obsidian API |
|
@SilentVoid13 Is |
|
Hey @ankushg, yes that's literally the only thing that I need but that's only available on desktop. I basically need the full path to the js file to |
|
I did these:
Now I am getting the error: Is import directive even supported on mobile/android? |
You'll want to use the getResourcePath if you want to load it as a URL in the browser; this will get you an URI that is handled by the platform that can load in the WebView. Otherwise, you should rely on |
|
@SilentVoid13 I opened a PR to update the docs (#282) as a temporary measure to let folks know user functions aren't currently available on mobile. |
|
@SilentVoid13 what if we tried something like: Or if we don't have access to the
I'm not near a computer to try this out, but will test next week and open a PR if it works... one problem might be reading the JS file... not sure |
|
Update: I tested it, and believe my approach above will work! Will submit the PR tomorrow for review. |
|
PR #340 submitted |
|
Did this ever get resolved? Will gladly fund development if needed. |
|
As another option: I switched over to using the CustomJS plugin with both Templater and Dataview. It is a slightly different style (uses classes), but does the job. Given ubiquity, I would almost prefer Templater adopted that approach: If you want to use your own script, use CustomJS, and call them as you would anything else.. it reduces the scope of what Templater has to support (while still achieving the goal for users). |
|
@ebullient Are you showing any prompts from your CustomJS scripts? If so, how? |
|
@SilentVoid13 I took a look at how you're loading the script - I see that you're using the absolute path because you're using NodeJS's import function, which is why it'll never work on mobile. The way I recommend you to change this for mobile support, is to load the file into a string using The way we load plugins, for example, is to do this: let js = await adapter.read(file_path);
let require = window.require;
let exports: any = {};
let module = {exports};
window.eval('(function anonymous(require,module,exports){' + js + '\n})');
fn(require, module, exports);
let result = exports['default'] || module.exports; |
I use Templater if/when I need prompts, and CustomJS usually for computation/functions or custom filters, etc. |
This is basically the approach I took in PR #340. I just don't think SV has had time to review/merge the change. CustomJS is a decent workaround for now, it uses a similar approach (vault.read) so works on mobile. |
|
Update: going to revisit my PR and merge if it still is working properly. Stay tuned! |
|
worth considering if CustomJS should just be the way. Scope creep is a thing. ;) (And CustomJS works with dataview, too.. ) |
Yes.. but I pass tp in, and use the existing tp mechanism to do it. Its a very nice mix and match. |
|
Friends! SV has released 1.10.0 which fixes support for user scripts on mobile. Closing this issue! |
|
@ebullient have you had a chance to test this out? |
|
No.. I've moved everything over to CustomJS in the meanwhile ... |
Plugin informations (please complete the following information):
Describe the bug
This will take some explaining. Let's start with what works everywhere. I have a daily template that looks like this:
If I try to break this into a user function, it works on desktop, but not on mobile. Specifically, I tried replacing the template content with this:
(I use those variables elsewhere, which also seems not to work on mobile with the user function in the mix... works fine on desktop).
My user function (in the scripts folder configured above) is in a file called
daily.js, and it looks like this:Expected behavior
would love to be able to simplify my templates and use functions, but it needs to work on mobile, too.
enhancement request: would be lovely to have a debug flag to turn on for mobile that would write a log.. hacking the plugin to spit out log files on mobile isn't my favorite (i worry about making the problem worse). a debug log that captured the information you need could make filing useful bug reports easier in general?)
The text was updated successfully, but these errors were encountered: