I created a tutorial on making a desklet for Cinnamon in JavaScript. I wrote it based on my experience while making the reddit desklet. The tutorial provides plenty of links to documentation or even source code. It requires some knowledge of JavaScript.
http://www.erikedrosa.com/2014/12/31/he ... orial.html
Please tell me what you think, I plan on creating more tutorials on desklets.
Creating a Hello, World! desklet for Cinnamon desktop
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Re: Creating a Hello, World! desklet for Cinnamon desktop
Nice. This is something I have seen quite a few requests for. Hopefully people find it useful and provide you with some good feedback so you feel like doing some more.
When I give opinions, they are my own. Not necessarily those of any other Linux Mint developer or the Linux Mint project as a whole.
Re: Creating a Hello, World! desklet for Cinnamon desktop
I have noticed some of those requests as well when I was looking up how to make desklets. Hopefully the tutorial will help people out.JosephM wrote:Nice. This is something I have seen quite a few requests for. Hopefully people find it useful and provide you with some good feedback so you feel like doing some more.
Re: Creating a Hello, World! desklet for Cinnamon desktop
Thanks for the tutorial!
It's still working fine in 2022.
I wanted to ask for a help with simple modification on it.
Instead of showing Hello World! I would like to get the sunrise and sunset as text.
Sunrise: 7:46
Sunset: 17:31
1) JavaScript code
I'm using API call - 'https://api.sunrise-sunset.org/json?lat ... ormatted=0'
Working with browser the code below is working but not as a desklet.
I found out that XMLHttpRequest is included in browsers only.
2) using - imports.gi.Gio
I was trying to get the logic from the other desklets - without success as well.
Code
JavaScript code:
Desklet code:
P.S. If I need I'll delete my post and will create new theme.
It's still working fine in 2022.
I wanted to ask for a help with simple modification on it.
Instead of showing Hello World! I would like to get the sunrise and sunset as text.
Sunrise: 7:46
Sunset: 17:31
1) JavaScript code
I'm using API call - 'https://api.sunrise-sunset.org/json?lat ... ormatted=0'
Working with browser the code below is working but not as a desklet.
I found out that XMLHttpRequest is included in browsers only.
2) using - imports.gi.Gio
I was trying to get the logic from the other desklets - without success as well.
Code
JavaScript code:
Code: Select all
function Get(yourUrl){
var Httpreq = new XMLHttpRequest(); // a new request
Httpreq.open("GET",yourUrl,false);
Httpreq.send(null);
return Httpreq.responseText;
}
var json_obj = JSON.parse(Get('https://api.sunrise-sunset.org/json?lat=42.6977&lng=23.3219&date=today&formatted=0'));
results = json_obj.results;
var sunrise = new Date(results.sunrise);
var sunset = new Date(results.sunset);
console.log("Sunrise: "+ sunrise.getHours() + ':' + sunrise.getMinutes());
console.log("Sunset: "+ sunset.getHours() + ':' + sunset.getMinutes());
Desklet code:
Code: Select all
const urlcatch = Gio.file_new_for_uri('https://api.sunrise-sunset.org/json?lat=42.6977&lng=23.3219&date=today&formatted=0');
let response;
do {
try {
let [successful, contents, etag_out] = urlcatch.load_contents(null);
if (successful) {
response = contents.toString();
retries = maxRetries;
} else {
response = errorBegin + _(service not available!") + errorEnd;
}
} catch (err) {
response = errorBegin + err + errorEnd;
}
retries++;
} while (retries < 3);
Knowing is not enough, we must apply. Willing is not enough, we must do.
https://softhints.com/ - simple Linux Mint guides
http://datascientyst.com/
https://softhints.com/ - simple Linux Mint guides
http://datascientyst.com/
Re: Creating a Hello, World! desklet for Cinnamon desktop
This may be more than you need: link.
Codeberg repo; old: @GitLab