Build TW with a syncadaptor that uses non available functions

58 views
Skip to first unread message

Danielo Rodríguez

unread,
Apr 5, 2015, 12:42:08 PM4/5/15
to tiddly...@googlegroups.com
Hello,

I'm trying to write a syncadaptor to use Tasker as a backend. The problem is that there are a couple of functions that are not available on TW environment but on tasker environment. I though this would not be a problem while building the wiki, but I'm getting errors about  functions not defined when I try to build the index.html file.

How can I then create the basic wiki to then copy to my phone?
Thanks in advance.

Jeremy Ruston

unread,
Apr 6, 2015, 1:59:33 PM4/6/15
to TiddlyWikiDev
Hi Danielo

This sounds interesting. What is Tasker? Can you provide a link to what you've got so far? And perhaps you could copy and paste the error messages?

Best wishes

Jeremy

--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/ea2a2628-7f01-4c24-8e86-16d176d99bd1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

Danielo Rodríguez

unread,
Apr 7, 2015, 2:23:10 PM4/7/15
to tiddly...@googlegroups.com, jeremy...@gmail.com
Hello Jeremy,

Tasker is an android application that allows you to control your phone progragmatically: 

It is based on profiles (basically states and events), tasks and user interaction. The cool thing is that it not only provides a "background" control, it also allows you to create user interfaces to allow the user to interact with your profiles. At some point the app developer decided to also include the possibility to display web-views with the content of your choice. This content can be a remote webpage or an html file stored on your phone. Recently the developer have included javascript support for some of Tasker capabilities. This includes access to the sd-card storage, and this is the fun part.

Here you can see what is supported for javascript so far: http://tasker.dinglisch.net/userguide/en/javascript.html [1]

Here is the syncadaptor that I have created: 

I just copied it into an empty tw5 file and I have uploaded it to my phone. It want to focus first on saving tiddlers. It works just partially: the storyList tiddler is saved to the sdcard, and the first draft I create is saved also, but after that nothing else is working, and no error is displayed. Could you let me know why?

Regarding the error I get when I try to build the wiki file using node js, is basically that the functions defined at  [1] are not available. Seems that node tries to "execute" or use the syncadaptor even when I just try to "build" the offline file.

Jeremy Ruston

unread,
Apr 7, 2015, 3:27:09 PM4/7/15
to Danielo Rodríguez, TiddlyWikiDev
Hi Danielo

Tasker is an android application that allows you to control your phone progragmatically: 

Great stuff, thanks for the explanation. This is a wonderful area for experimentation and I shall be very interested to see what you come up with. 
 
Here is the syncadaptor that I have created: 

I just copied it into an empty tw5 file and I have uploaded it to my phone. It want to focus first on saving tiddlers. It works just partially: the storyList tiddler is saved to the sdcard, and the first draft I create is saved also, but after that nothing else is working, and no error is displayed. Could you let me know why?

Reading the code I don't see anything obviously wrong, I'm afraid. A likely cause would be that one of the functions in your syncadaptor isn't correctly calling the appropriate callback function, but I don't see any obvious signs of that. I'd suggest adding a console.log to the top of each of your functions so that you can see what is being called. I notice that the deleteTiddler() method is commented out, and that it doesn't call the callback; if it is in fact being called by the syncer then that would be a problem.
 
Regarding the error I get when I try to build the wiki file using node js, is basically that the functions defined at  [1] are not available. Seems that node tries to "execute" or use the syncadaptor even when I just try to "build" the offline file.

I suspect that will be because TW is attempting to run the syncadaptor on the server as well as in the browser. The fix is to only export your syncadaptor in the browser:

if($tw.browser) {
exports.adaptorClass = FileSystemAdaptor;
}

Best wishes

Jeremy.

Danielo Rodríguez

unread,
Apr 7, 2015, 4:06:45 PM4/7/15
to tiddly...@googlegroups.com, rdan...@gmail.com, jeremy...@gmail.com
 
Great stuff, thanks for the explanation. This is a wonderful area for experimentation and I shall be very interested to see what you come up with. 

Me too :P
 

Reading the code I don't see anything obviously wrong, I'm afraid.
Oops, this is going to be tricky.
 
I'd suggest adding a console.log to the top of each of your functions so that you can see what is being called.
The problem is that I can't open a console in Tasker's webview. I should log it to a file. It's enough to write a function that writes to the file or should I use some kind of logger?
 
I notice that the deleteTiddler() method is commented out, and that it doesn't call the callback; if it is in fact being called by the syncer then that would be a problem.
What kind of problem? What would be the easiest option for this?
 
I suspect that will be because TW is attempting to run the syncadaptor on the server as well as in the browser. The fix is to only export your syncadaptor in the browser:

if($tw.browser) {
exports.adaptorClass = FileSystemAdaptor;
}

I'll try that out! Thank you

Jeremy Ruston

unread,
Apr 7, 2015, 5:35:30 PM4/7/15
to Danielo Rodríguez, TiddlyWikiDev
Hi Danielo
 
I'd suggest adding a console.log to the top of each of your functions so that you can see what is being called.
The problem is that I can't open a console in Tasker's webview. I should log it to a file. It's enough to write a function that writes to the file or should I use some kind of logger?

That's always awkward. A lot of the time one can use alert(), but it doesn't always play well with asynchronous code. Logging to the DOM with something like this can be useful:

document.body.appendChild(document.createTextNode("My message------"))

You won't get line breaks in the output, hence the dashes to separate messages.
 
 
I notice that the deleteTiddler() method is commented out, and that it doesn't call the callback; if it is in fact being called by the syncer then that would be a problem.
What kind of problem? What would be the easiest option for this?

The syncer is calling deleteTiddler() expecting that it will at some point invoke the callback, with either success or failure. If the deleteTiddler method just exits, without calling the callback, the syncer will never get the chance to kick off the next sync task. I'd suggest first adding logging so you can tell whether the method is being called. If necessary, you could mock the function by just calling the callback with the success parameters.

Good luck,

Best wishes

Jeremy

 
I suspect that will be because TW is attempting to run the syncadaptor on the server as well as in the browser. The fix is to only export your syncadaptor in the browser:

if($tw.browser) {
exports.adaptorClass = FileSystemAdaptor;
}

I'll try that out! Thank you
 
Best wishes

Jeremy.

--
Jeremy Ruston
mailto:jeremy...@gmail.com

Danielo Rodríguez

unread,
Apr 7, 2015, 5:47:15 PM4/7/15
to tiddly...@googlegroups.com, rdan...@gmail.com, jeremy...@gmail.com
That's always awkward. A lot of the time one can use alert(), but it doesn't always play well with asynchronous code. Logging to the DOM with something like this can be useful:

document.body.appendChild(document.createTextNode("My message------"))

Hello Jeremy. 
Thank you very much. I'll try that out.
 

The syncer is calling deleteTiddler() expecting that it will at some point invoke the callback, with either success or failure. If the deleteTiddler method just exits, without calling the callback, the syncer will never get the chance to kick off the next sync task. I'd suggest first adding logging so you can tell whether the method is being called. If necessary, you could mock the function by just calling the callback with the success parameters.


I updated the deleteTiddler function, first with a dummy definition and it started to work. But as a side effect the draft tiddlers remained there. I modified the code to do real deletion of tiddlers and it is working perfectly right now. I updated the gist. I have single tiddler files!! hooray! Now the loading part is missing.

What would be the better way to provide skinny tiddlers? Does it makes sense at all? Because I have to read the whole file in order to give the skinny definition there is no advantage of using just a skeleton tiddlers. I worked before with loading tiddlers from the FS and it was a total disaster. Any advice will be very welcome.

Jeremy Ruston

unread,
Apr 7, 2015, 5:54:24 PM4/7/15
to Danielo Rodríguez, TiddlyWikiDev
Hi Danielo

I updated the deleteTiddler function, first with a dummy definition and it started to work. But as a side effect the draft tiddlers remained there. I modified the code to do real deletion of tiddlers and it is working perfectly right now. I updated the gist. I have single tiddler files!! hooray! Now the loading part is missing.

Excellent, well done.
 
What would be the better way to provide skinny tiddlers? Does it makes sense at all? Because I have to read the whole file in order to give the skinny definition there is no advantage of using just a skeleton tiddlers. I worked before with loading tiddlers from the FS and it was a total disaster. Any advice will be very welcome.

The skinny tiddler infrastructure might work well if you use separate .meta files; you ought to be able to just read the .meta files. You'll want .meta file support in any case for saving images in a useful format.

In any event, if you do find yourself able to return a 'text' field in the skinny tiddlers response, you should do so; the client code will be happy.

Best wishes

Jeremy.


 
Reply all
Reply to author
Forward
0 new messages