-
Notifications
You must be signed in to change notification settings - Fork 17
New 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
widgets/external_ip: port to javaScripCore #27
Conversation
this is the simplest widget we have. @Lokaltog How do you want to do the merge? all the widgets at the same time and you update the theme too or you want to update the theme one by one? |
I think it'll be more practical to update the theme in one go, after porting all the widgets. |
}; | ||
|
||
/* Callback - JavaScript window object has been cleared */ | ||
void add_class_extennal_ip(WebKitWebView *web_view, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: extennal
-> external
fixed typo, what happens when you call an object that it's not defined in js? how are we going to handle not having the widget that exists in the theme? |
With the webview it will only print an error to the console. We can wrap every API call in a try...catch block and it won't be an issue. |
This patch is wrong(i can't add more widgets) im going to have to call each widget in window_object_cleared_cb |
@Lokaltog can you take a look this patch i updated it, now the volume class is also visible. |
I'd still prefer if wkline used threads like they do currently, and provide data updates through JS callbacks. Your JS file asks for C to call the onChange callback, but I can't see it in the C code in the patch. Side note: Is it even possible to have several widgets waiting for system information without using threads? |
the call to onChange should be on the thread i can't create. as it is now none of the widgets locks the program to do anyting even load them. the idea to use jscore is to avoid threads when we dont need them for example the external_ip example and talking to dbus |
I'm sorry, I'm just a bit confused regarding how this is supposed to work. Have I understood it correctly if:
setInterval(function () {
var temp = Weather.get_temperature();
updateWeatherWidget(temp);
}, 600000); // 10 minutes
Volume.onChange(function (volume) {
updateVolumeWidget(volume);
}); // pseudocode
function store_callback(js_function *callback) {
// store ptr to js function here, will be called in the C thread
js_callback volume_change_callback = callback;
}
js_add_method("onChange", store_callback);
// in thread:
function update_volume () {
while (wait_for_change) {
// get new volume
volume_change_callback(volume); // will call the callback function set in .onChange() in the JS file above
}
} This is how I picture stuff to work, but I might have completely misunderstood. Let me know if I'm wrong! I'm calling it a night, I'll see if I can get some work done on this issue tomorrow morning. |
the js update can be something more like this
and in the thread what the C code does is calling the js function assigned to "onChange",
|
corrupted double linked list
i give up alsa is just not for me |
Ah, I think I understand what you mean now. The problem is that there's a pretty strict convention in JS to provide the updated data when a callback is called, so requiring the user to manually do Volume.get_volume() in the callback to actually get the volume isn't ideal. But the part of assigning the callback to a variable like Worst case we could rename onUpdate and wrap the functionality in JS like so: Volume.onDataChanged = function () { // notify event sent to this method
var volume = Volume.get_volume()
if (typeof this.onUpdate === 'function')
this.onUpdate(volume)
} I'll look into the issue and see if I can come up with a solution. |
Looking at the example code from the tutorial it appears it should be fairly simple to pass arguments to an onChange callback function. We just need to provide the volume data as a |
my problem is just with alsa the jscore is working fine (i think), it's just that alsa is not thread safe and even if have it all in the same function (waiting and getting the volume) it crashes anyway. i want to keep the js as simple as possible. please see my code |
I'll look into it, I'll do some experimenting and see if I can get it working tonight. |
@Lokaltog can you take a look at the code i just committed, i finally got volume to work but i can't get it to update the html code. i added a test html file (changed in the last commit) can you take a look? |
this creates a new object "externalIp" with one method "get_address"
witch can be accessed with externalIp.get_address()