Help with Cinnamon applet dev

Chat about anything related to Linux Mint
Level 1
Level 1
Posts: 4
Joined: Sat Nov 03, 2012 5:39 am

Help with Cinnamon applet dev

Postby nabsha » Sat Nov 03, 2012 5:48 am

Hi All,

I am new to Cinnamon development and this forum.

I have been trying to write an applet for Cinnamon but have struck rock and need some advise.

The applet I am trying to build should show me the time of any given location.

Since there is no real documentation I could find, I started my work from netspeed@adec applet. Everything went smooth until I started to add menu to add location to the settings.json. Somehow I am not able to add menu until now.

I would really appreciate if someone can help me with that please.

Here is the code of applet.js

Code: Select all

const Applet = imports.ui.applet;
const Cinnamon =;
const GLib =;
const GTop =;
const Gio =;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const PopupMenu = imports.ui.popupMenu;
const St =;
const Main = imports.ui.main;

function MyMenu(launcher, orientation) {
    this._init(launcher, orientation);
MyMenu.prototype = {
    __proto__: PopupMenu.PopupMenu.prototype,
    _init: function(launcher, orientation) {
        this._launcher = launcher;,, 0.0, orientation, 0);

function MyApplet(orientation) {
MyApplet.prototype = {
    __proto__: Applet.TextApplet.prototype,

   _init: function(metadata, orientation) {, orientation);
      this.metadata = metadata;
      this.path = this.metadata.path;
      this.settingsFile = "settings.json";

      try {
         this.menuManager = new PopupMenu.PopupMenuManager(this); = new MyMenu(this, orientation);

      catch (e) {

   makeMenu: function() {
      //this.menuitemInfo = new PopupMenu.PopupMenuItem("This is test Message", { reactive: false }); PopupMenu.PopupMenuItem("Test Message", { reactive: false }));

   buildContextMenu: function() {
      this._applet_context_menu.addMenuItem(new PopupMenu.PopupMenuItem("Select the interface to be monitored:", { reactive: false }));

   on_applet_clicked: function(event) {
      if(! {

    update:function () {
        var d_now = new Date();
        var d_offset = new Date(d_now);
        d_offset.setHours(d_now.getHours() + this.settings.HoursOffset);
        this.set_applet_label(this.settings.Location + ":" + d_offset.getDate()+"/"+(d_offset.getMonth()+1)+" "+d_offset.getHours()+":"+
        Mainloop.timeout_add(1000, Lang.bind(this, this.update));

    loadSettings: function() {
        try {
            global.logError("Setting path: " + this.path);
            var dir = Gio.file_new_for_path(this.path);
            global.logError("Setting filepath: " + this.settingsFile);
            var prefsFile = dir.get_child(this.settingsFile);

            global.logError("Reading File" + prefsFile.get_path());
            var settingData = Cinnamon.get_file_contents_utf8_sync(prefsFile.get_path());
            global.logError("PArsing JSON");
            this.settings = JSON.parse(settingData);
        } catch(e) {
            global.logError("Settings file not found. Using default values.");
            this.settings = JSON.parse('{"Location":"Sydney","HoursOffset":8,"MinutesOffset":0}');
function main(metadata, orientation) {
    let myApplet = new MyApplet(metadata,orientation);
    return myApplet;

Level 17
Level 17
Posts: 7645
Joined: Fri May 09, 2008 1:14 pm

Re: Help with Cinnamon applet dev

Postby remoulder » Sat Nov 03, 2012 6:01 pm

This is not a developers forum, I suggest you try
[Edit] your original post and add [SOLVED] once your question is resolved.

“The people are my God” stressing the factor determining man’s destiny lies within man not in anything outside man, and thereby defining man as the dominator and remoulder of the world.

Level 1
Level 1
Posts: 4
Joined: Sat Nov 03, 2012 5:39 am

Re: Help with Cinnamon applet dev

Postby nabsha » Sat Nov 03, 2012 8:24 pm

Hi All,

Just wanted to update that I kinnda rewrote the thing and it worked.

You can get the working applet via github.

I tried to upload it on cinnamon-spices but I could not find the link so if someone can help me to get it on cinnamon-spices, that would be great.

It was a good experiment and I am sure that a lot more can be done for cinnamon applets.


Level 1
Level 1
Posts: 2
Joined: Wed Nov 07, 2012 8:42 pm

Re: Help with Cinnamon applet dev

Postby Kamikaze » Thu Nov 15, 2012 8:58 pm

Hi Nabsha,

I, like you, recently developed my first Cinnamon applet. Sounds like you had the same troubles I did (lack of doco mainly, and difficulty finding how to upload the applet to spices).
I still haven't found great doco, though am now a bit more familiar with translating some of the API doco available from the GNOME site for use via the gjs bindings which helped when I was recently looking into using GSettings schemas.

Anyway, I can help you with uploading the applet to the spices site - here's how you do it:
* On visiting the page you'll see 'Sign In' text in the very top right of the page
* Register an account and then log-in (note that it appears to send your p/w over straight HTTP so don't use any password you care about)
* Once you've logged in, you should see new text in the very top LEFT of the page, called '+ New'.
* Highlight the '+ New' and it should drop down so you can select the relevant thing you've made be it an applet/extension/theme
* Fill out the details required in the form and submit.

Note that it's very picky on wanting PNGs for pics and a ZIP of the applet, nothing else was accepted for me (I originally tried a .tar.gz I think).
Hope this helps.


Return to “Chat about Linux Mint”