Templater icon indicating copy to clipboard operation
Templater copied to clipboard

Allow User Scripts on Mobile

Open pjkaufman opened this issue 2 years ago • 4 comments

There was an issue where if you tried to use user scripts on mobile devices, it would throw an error saying that your script did not exist. It would still detect your user scripts in the settings, but you would not be able to generate any templates. Removing the check to only allow user scripts for desktop seems to have resolved the issue.

This is working for me on my personal Android phone. I am not sure which mobile device caused this to be solely allowed for desktop prior, but it may be that Obsidian has been updated in such a way that the issue has gone away.

fix #586

Changes Made:

  • Removed Platform import from Obsidian and using it to check if the current platform is desktop in UserFunctions.ts

pjkaufman avatar Apr 17 '22 17:04 pjkaufman

@SilentVoid13 , I will await your review. I am not sure how we are supposed to run the UTs since I was unable to do so by running any of the npm run ... commands. Please let me know if you would like changes or anything like that.

pjkaufman avatar Apr 17 '22 17:04 pjkaufman

Hi, I've applied this in a very sketchy way in my own Vault. I don't recommend trying this at home, cause why would you choose to patch plugins in your own Vault, it could break everything, don't do this, I will not provide support if you do this...

But, if you know what you're doing, you have backups, and your Templater version is 1.12.0, you can copy my bad idea.

Save this file as templaterUserScripts.patch:

--- .obsidian/plugins/templater-obsidian/main.js	2022-07-12 11:33:23.000000000 +0200
+++ .obsidian/plugins/templater-obsidian/main.js	2022-07-12 11:36:19.000000000 +0200
@@ -3062,7 +3062,7 @@
       if (this.plugin.settings.enable_system_commands) {
         user_system_functions = yield this.user_system_functions.generate_object(config2);
       }
-      if (import_obsidian13.Platform.isDesktopApp && this.plugin.settings.user_scripts_folder) {
+      if (this.plugin.settings.user_scripts_folder) {
         user_script_functions = yield this.user_script_functions.generate_object(config2);
       }
       return __spreadValues(__spreadValues({}, user_system_functions), user_script_functions);

And then run patch .obsidian/plugins/templater-obsidian/main.js < templaterUserScripts.patch in your Vault's root directory.

martijnarts avatar Jul 12 '22 09:07 martijnarts

Can confirm this edit works on an iPad.

I can also check on other platforms if needed.

Could we possibly get a link to the initial issue and why this was disabled?

It seems that it may have not worked in a few cases with imports or something but for things like utility functions which just wrap checking dates and most of what I use it for it works perfect.

Id rather this be enabled with the error messages than entirely remove it for those who don't need whatever cases it was erroring in. Unless it was possibly causing larger data loss somehow.

sekwah41 avatar Aug 05 '22 23:08 sekwah41

I believe this also relates to issue #550 too

sekwah41 avatar Aug 05 '22 23:08 sekwah41

merging

shabegom avatar Sep 01 '22 22:09 shabegom

Thanks @shabegom!

martijnarts avatar Sep 02 '22 09:09 martijnarts