Skip to content

Commit c696c2f

Browse files
committed
Merge pull request JessW#3 from RavetcoFX/patch-3
Cleaned up some stuff
2 parents ea0edc2 + 2c4baf6 commit c696c2f

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

desklet.js

+36-34
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,26 @@ MyDesklet.prototype = {
2121

2222
try {
2323
this.settings = new Settings.DeskletSettings(
24-
this, this.metadata["uuid"], this.instance_id);
25-
26-
this.settings.bindProperty(Settings.BindingDirection.IN,
27-
"file",
28-
"file",
29-
this.on_setting_changed,
30-
null);
31-
this.settings.bindProperty(Settings.BindingDirection.IN,
32-
"delay",
33-
"delay",
34-
this.on_setting_changed,
35-
null);
36-
} catch (e) {
24+
this, this.metadata["uuid"], this.instance_id);
25+
26+
this.settings.bindProperty(Settings.BindingDirection.IN, "file", "file", this.on_setting_changed, null);
27+
this.settings.bindProperty(Settings.BindingDirection.IN, "delay", "delay", this.on_setting_changed, null);
28+
}
29+
catch (e) {
3730
global.logError(e);
3831
}
3932

40-
this.sep = "%";
41-
this.maxSize = 7000; // Many more characters, and Cinnamon crashes
33+
this.sep = "%"; // SPACE
34+
this.maxSize = 7000; // Cinnamon can crash if this int is too high
4235

43-
this.setHeader(_("Quote"));
44-
this.setup_display();
36+
this.setHeader(_("Quote of the day"));
37+
this.setup_display();
4538
},
4639

4740
on_setting_changed: function() {
48-
if (this.update_id > 0)
41+
if (this.update_id > 0) {
4942
Mainloop.source_remove(this.update_id);
43+
}
5044
this.update_id = null;
5145
this.setup_display();
5246
},
@@ -57,31 +51,38 @@ MyDesklet.prototype = {
5751

5852
setup_display: function() {
5953
this._quoteContainer =
60-
new St.BoxLayout({vertical:true, style_class: 'quote-container'});
54+
new St.BoxLayout({vertical:true, style_class: 'quote-container'});
6155
this._quote = new St.Label();
6256

63-
this._quoteContainer.add(this._quote);
57+
this._quoteContainer.add(this._quote);
6458
this.setContent(this._quoteContainer);
6559

66-
this.updateInProgress = false;
60+
this.updateInProgress = false;
6761
this.file = this.file.replace('~', GLib.get_home_dir());
6862

69-
this._update_loop();
63+
this._update_loop();
7064
},
7165

66+
/**
67+
* Updates every user set secconds?
68+
**/
7269
_update_loop: function(){
7370
this._update();
7471
this.update_id = Mainloop.timeout_add_seconds(
75-
this.delay*60, Lang.bind(this, this._update_loop));
72+
this.delay*60, Lang.bind(this, this._update_loop));
7673
},
7774

75+
/**
76+
* Method to update the text/reading of the file
77+
**/
7878
_update: function(){
7979
if (this.updateInProgress) {
80-
return;
80+
return;
8181
}
8282
this.updateInProgress = true;
8383

84-
try {
84+
try {
85+
8586
// Since we update infrequently, reread the file in case it has changed
8687
if (!GLib.file_test(this.file, GLib.FileTest.EXISTS))
8788
return;
@@ -110,7 +111,7 @@ MyDesklet.prototype = {
110111
this._quote.set_text(currentQuote);
111112

112113
} catch (e) {
113-
global.logError(e);
114+
global.logError(e);
114115
} finally {
115116
this.updateInProgress = false;
116117
}
@@ -124,14 +125,15 @@ MyDesklet.prototype = {
124125
this.separators = [];
125126
let index = 0;
126127

127-
while (index < allQuotes.length) {
128-
index = allQuotes.indexOf(this.sep, index);
129-
if (index === -1)
130-
break; // no more separators
131-
this.separators.push(index);
132-
index++;
133-
}
134-
}
128+
while (index < allQuotes.length) {
129+
index = allQuotes.indexOf(this.sep, index);
130+
if (index === -1) {
131+
break; // no more separator
132+
}
133+
this.separators.push(index);
134+
index++;
135+
}
136+
}
135137
}
136138

137139
function main(metadata, desklet_id){

0 commit comments

Comments
 (0)