PDA

View Full Version : Handler to pick up URL clicks



mattekure
January 25th, 2020, 15:56
Is it possible to have a handler that reacts when a URL is clicked? In the code, it seems that the way a URL is triggered is using an Interface.openWindow("url", "https://blah") call, but when when I register an onWindowOpened handler, these dont trigger. I assume because they are not opening windows within FG, but triggering something outside. Is there a way to set up a handler that will pick up when the URL is opened and allow modifications to it before triggering?

Reason:
Syrinscape Online uses URL links to trigger its online player, but it requires a unique authentication code to be included in the URL. This means I can make a module of soundlinks for just me, but it wouldnt work for anyone else. I am building an extension with the goal of being able to take a URL being triggered, checking if its a syrinscape online URL, and appending the authentication code. This would then make it possible to design a generic module with all the syrinscape online links and the auth code would be stored in the DB.

The other alternative I've thought of is to test for the Syrinscape Online module being loaded, then having it go through the db and rewrite all the links. This would require upfront processing, but would only need to be done once.

mattekure
January 25th, 2020, 22:38
hmm, my first idea doesnt seem like it will work, and my second idea may also not be possible. I've figured out how to get the text from the module entries, but I cant get the actual url values contained within the link tag, it just returns the text of the name.

Trenloe
January 26th, 2020, 04:44
Based off your posts in the Syrinscape module thread it sounds like you got this working?

mattekure
January 26th, 2020, 12:59
Sort of. I'm still learning my way around the code, but I am making progress. Its certainly making me think through the issues in different ways as I learn what is and isnt possible to do.

Trenloe
January 26th, 2020, 13:27
...but I cant get the actual url values contained within the link tag, it just returns the text of the name.
How are you trying to do this? At the database level or within text?

mattekure
January 26th, 2020, 13:38
My attempts to get the URL were at the module DB level. I have a module with all of the links stored in story entries using the <link class="url" recordname="actual URL I need">Name of sound linked</link>. When I drill down through the DB nodes, I can get access to the final formatted text node, but any attempt to get at the info within just returns the text of the Name of the sounds. getValue and getText dont return the xml, they just return the actual text. But what I need access to is the contents of the recordname within the link tag.

This type of link works fine for the older syrinscape players as they will trigger when the link is clicked. But this doesnt work for the newer Syrinscape Online player because each URI has to have a unique authentication code appended. Its easy enough to make a module for myself with the authentication code included, but making it so others can use it requires me to manipulate the URI so that it contains the authentication code when triggered.

So my process that sort of works is to not include the data within the module as story entries. Instead, I crafted my own xml structure within the modules db.xml which I can access programatically with the values stored as strings. Then I can append the authentication code, and generate a clickable trigger.

Trenloe
January 26th, 2020, 14:29
getValue and getText dont return the xml, they just return the actual text. But what I need access to is the contents of the recordname within the link tag.
Something MW put me onto recently - have you tried something like the following: sClassName, sRecordName = DB.getValue(dbnode, "link", "", ""); or sClassName, sRecordName = DB.getValue(dbnode, "shortcut", "", "");

mattekure
January 26th, 2020, 14:43
neither of those return anything. I think its because the <text type=formattedtext"> is the final node in that path. It has no children nodes. Instead, its value contains multiple linklists and links, but they are not uniquely identified.

mattekure
January 27th, 2020, 18:25
Ooh, Celestian got me straightened out on getting the raw xml from the formatted text. now I can see about my original idea.

Trenloe
January 27th, 2020, 20:54
Ooh, Celestian got me straightened out on getting the raw xml from the formatted text.
How did he do it?

mattekure
January 27th, 2020, 21:02
I was being stupid, and got the DB.getValue() and DB.getText() messed up in my head. Once I took a step back and rewent over it I realized I was calling the wrong one. the DB.getValue() got me exactly what I want. and I actually got the entire extension working the way I want it to. I am doing some final testing on it now, but it seems to work great.

mattekure
January 27th, 2020, 21:09
And I really did try the code you included. I dont know if I was tired or what, but up until 30 mins ago, I would swear it wasnt returning the xml.

Trenloe
January 27th, 2020, 21:14
And I really did try the code you included. I dont know if I was tired or what, but up until 30 mins ago, I would swear it wasnt returning the xml.
I didn't understand exactly what you were trying to do - I thought (mistakenly) that the link details you were after were stored directly in a database node and not in a formattedtext field. Sorry I misled you.
Hopefully what I posted might be useful for when you do want data directly from a the database! :)

mattekure
January 27th, 2020, 22:12
I appreciate the help. I am still fairly new to LUA and programming with Fantasy Grounds. But I think this piece is finally coming together.

for a better explanation of I was trying to do, I have a module with a list of story entries. Each story entry has a bunch of links in the form of:

<link class="url" recordname="http:/abc.com">Name</link>

I wanted to go through the links and convert them into the form

<link class="url" recordname="http:/abc.com?authentication_code=123445">Name</link>

So initially I was trying to get the text from the formatted text field, but obviously I was going about it the wrong way. now with a simple nNode.getValue() I can get the data I need to make the changes.