From 04c42253eb51deff709ca8fb4e96e414b550b600 Mon Sep 17 00:00:00 2001 From: Raymundo Cassani Date: Fri, 22 May 2020 20:49:37 -0400 Subject: [PATCH] Add settings and pass values to desklet --- .../system-monitor-graph@rcassani/desklet.js | 50 +++++++++++-------- .../settings-schema.json | 31 ++++++++++++ 2 files changed, 61 insertions(+), 20 deletions(-) create mode 100644 files/system-monitor-graph@rcassani/settings-schema.json diff --git a/files/system-monitor-graph@rcassani/desklet.js b/files/system-monitor-graph@rcassani/desklet.js index 07757c6..8fe5399 100644 --- a/files/system-monitor-graph@rcassani/desklet.js +++ b/files/system-monitor-graph@rcassani/desklet.js @@ -1,30 +1,40 @@ const Desklet = imports.ui.desklet; +const Settings = imports.ui.settings; + const St = imports.gi.St; function MyDesklet(metadata, desklet_id) { - this._init(metadata, desklet_id); + this._init(metadata, desklet_id); +} + +function main(metadata, desklet_id) { + return new MyDesklet(metadata, desklet_id); } MyDesklet.prototype = { - __proto__: Desklet.Desklet.prototype, + __proto__: Desklet.Desklet.prototype, - _init: function(metadata, desklet_id) { - Desklet.Desklet.prototype._init.call(this, metadata, desklet_id); - this.setupUI(); - }, + _init: function(metadata, desklet_id) { + Desklet.Desklet.prototype._init.call(this, metadata, desklet_id); - setupUI(){ - // creates container for one child - this.window = new St.Bin(); - // creates a label with text - this.text = new St.Label({text: "Hello Desktop"}); - // adds label to container - this.window.add_actor(this.text); - // Sets the container as content actor of the desklet - this.setContent(this.window); - }, + // initialize settings + this.settings = new Settings.DeskletSettings(this, this.metadata["uuid"], desklet_id); + this.settings.bindProperty(Settings.BindingDirection.IN, "type", "type", this.on_setting_changed); + + // initialize desklet GUI + this.setupUI(); + }, + + setupUI: function(){ + var type = this.type; + + // creates container for one child + this.window = new St.Bin(); + // creates a label with text + this.text = new St.Label({text: "Hello Desktop ".concat(type)}); + // adds label to container + this.window.add_actor(this.text); + // Sets the container as content actor of the desklet + this.setContent(this.window); + }, }; - -function main(metadata, desklet_id) { - return new MyDesklet(metadata, desklet_id); -} diff --git a/files/system-monitor-graph@rcassani/settings-schema.json b/files/system-monitor-graph@rcassani/settings-schema.json new file mode 100644 index 0000000..4a44a19 --- /dev/null +++ b/files/system-monitor-graph@rcassani/settings-schema.json @@ -0,0 +1,31 @@ +{ + "head0": { + "type": "header", + "description": "Settings for system-monitor-graph@rcassani" + }, + + "head1": { + "type": "header", + "description": "General" + }, + "type": { + "type": "combobox", + "default": "cpu", + "description": "System variable for graph", + "tooltip": "Select the system variable to monitor.", + "options" : { + "CPU" : "cpu", + "RAM": "ram" + } + }, + + "head2": { + "type": "header", + "description": "Visual" + }, + "line-color": { + "type": "colorchooser", + "default": "rgba(50,168,82,1.0)", + "description": "Line color" + } +}