Skip to content

Commit

Permalink
fix wrong value type in change icon creation ("value "nan" of type
Browse files Browse the repository at this point in the history
'gfloat' is invalid)
* undo ESR6 method definitions to make it compatible again with jsmoz-24
(Cinnamon 3.2)
  • Loading branch information
thegli committed May 6, 2018
1 parent 4900552 commit 820f2ca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ This repository contains a [desklet for the Cinnamon desktop environment](https:

This desklet is based on the [desklet from fthuin](https://cinnamon-spices.linuxmint.com/desklets/view/23). The data retrieval part is adopted to an alternative service url, after the Yahoo Finance community table got retired in May 2017.

Tested with Linux Mint 18.3 (Cinnamon 3.6) and Manjaro (Cinnamon 3.8).
Tested with Debian 9 (Cinnamon 3.2), Linux Mint 18.3 (Cinnamon 3.6), and Manjaro (Cinnamon 3.8).

## Installation
Download the folder **yfquotes@thegli** and copy it to *~/.local/share/cinnamon/desklets/*.
Check out the desklet configuration settings, and choose the refresh period, the quote details to display, and the list of quotes to show. The default list contains the Dow 30 companies.

## Release Notes

### current

Features:
* none so far...

Bugfix:
* fix "value "nan" of type 'gfloat' is invalid or out of range for property" errors logged in *.xsession-errors*
* works (again) with Cinnamon 3.2

### 0.1.0 - May 4, 2018

Features:
Expand Down
57 changes: 28 additions & 29 deletions files/yfquotes@thegli/desklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* This desklet is based on the work of fthuin's stock desklet.
*
*/
/* jshint esversion : 6 */
const Desklet = imports.ui.desklet; // cinnamon desklet user interface
const St = imports.gi.St; // Shell toolkit library from GNOME
const Gio = imports.gi.Gio; // URL-IO-Operations
Expand All @@ -25,14 +24,14 @@ var YahooQueryStockQuoteReader = function () {
YahooQueryStockQuoteReader.prototype = {
constructor: YahooQueryStockQuoteReader,
yahooQueryBaseUrl: "https://query1.finance.yahoo.com/v7/finance/quote?symbols=",
getStockQuotes(quoteSymbols) {
getStockQuotes: function (quoteSymbols) {
var response = this.getYahooQueryResponse(this.createYahooQueryUrl(quoteSymbols));
return this.fetchStockQuotes(response);
},
createYahooQueryUrl(quoteSymbols) {
createYahooQueryUrl: function (quoteSymbols) {
return this.yahooQueryBaseUrl + quoteSymbols.join(",");
},
getYahooQueryResponse(requestUrl) {
getYahooQueryResponse: function (requestUrl) {
var urlcatch = Gio.file_new_for_uri(requestUrl);
var loaded = false,
content;
Expand All @@ -43,7 +42,7 @@ YahooQueryStockQuoteReader.prototype = {
content = urlcatch.load_contents(null)[1];
return JSON.parse(content.toString());
},
fetchStockQuotes(response) {
fetchStockQuotes: function (response) {
var quotes = [];
var dataRows = response.quoteResponse.result;
var i = 0;
Expand All @@ -70,12 +69,12 @@ StockQuotesTable.prototype = {
GBP: "\u00A3",
INR: "\u20A8"
},
render(stockQuotes, settings) {
render: function (stockQuotes, settings) {
for (var rowIndex = 0, l = stockQuotes.length; rowIndex < l; rowIndex++) {
this.renderTableRow(stockQuotes[rowIndex], rowIndex, settings);
}
},
renderTableRow(stockQuote, rowIndex, shouldShow) {
renderTableRow: function (stockQuote, rowIndex, shouldShow) {

var cellContents = [];

Expand Down Expand Up @@ -103,27 +102,27 @@ StockQuotesTable.prototype = {
});
}
},
createStockSymbolLabel(stockQuote) {
createStockSymbolLabel: function (stockQuote) {
return new St.Label({
text: stockQuote.symbol,
style_class: "stocks-label"
});
},
createStockPriceLabel(stockQuote, withCurrency) {
createStockPriceLabel: function (stockQuote, withCurrency) {
var currencyCode = withCurrency ? stockQuote.currency : "";
var currencySymbol = this.currencyCodeToSymbolMap[currencyCode] || currencyCode;
return new St.Label({
text: currencySymbol + "" + this.roundAmount(stockQuote.regularMarketPrice, 2),
style_class: "stocks-label"
});
},
createCompanyNameLabel(stockQuote) {
createCompanyNameLabel: function (stockQuote) {
return new St.Label({
text: stockQuote.shortName,
style_class: "stocks-label"
});
},
createPercentChangeIcon(stockQuote) {
createPercentChangeIcon: function (stockQuote) {
var path = "";
var percentChange = stockQuote.regularMarketChangePercent === null ? 0.0 : parseFloat(stockQuote.regularMarketChangePercent);

Expand All @@ -140,17 +139,17 @@ StockQuotesTable.prototype = {
var image = St.TextureCache.get_default().load_uri_async(uri, -1, -1);
image.set_size(20, 20);

var binIcon = new St.Bin({height: "20px", width: "20px"});
var binIcon = new St.Bin({height: "20", width: "20"});
binIcon.set_child(image);
return binIcon;
},
createPercentChangeLabel(stockQuote) {
createPercentChangeLabel: function (stockQuote) {
return new St.Label({
text: stockQuote.regularMarketChangePercent === null ? "N/A" : this.roundAmount(stockQuote.regularMarketChangePercent, 2) + "%",
style_class: "stocks-label"
});
},
roundAmount(amount, decimals) {
roundAmount: function (amount, decimals) {
return Number((amount).toFixed(decimals));
}
};
Expand All @@ -162,14 +161,14 @@ function StockQuoteDesklet(metadata, id) {

StockQuoteDesklet.prototype = {
__proto__: Desklet.Desklet.prototype,
init(metadata, id) {
init: function (metadata, id) {
this.metadata = metadata;
this.id = id;
this.stockReader = new YahooQueryStockQuoteReader();
this.loadSettings();
this.onUpdate();
},
loadSettings() {
loadSettings: function () {
this.settings = new Settings.DeskletSettings(this, this.metadata.uuid, this.id);
this.settings.bindProperty(Settings.BindingDirection.IN, "height", "height", this.onDisplayChanged, null);
this.settings.bindProperty(Settings.BindingDirection.IN, "width", "width", this.onDisplayChanged, null);
Expand All @@ -182,7 +181,7 @@ StockQuoteDesklet.prototype = {
this.settings.bindProperty(Settings.BindingDirection.IN, "showCurrencyCode", "showCurrencyCode", this.onSettingsChanged, null);
this.settings.bindProperty(Settings.BindingDirection.IN, "showStockPercentChange", "showStockPercentChange", this.onSettingsChanged, null);
},
getQuoteDisplaySettings() {
getQuoteDisplaySettings: function () {
return {
"icon": this.showIcon,
"stockName": this.showStockName,
Expand All @@ -192,19 +191,19 @@ StockQuoteDesklet.prototype = {
"percentChange": this.showStockPercentChange
};
},
onDisplayChanged() {
onDisplayChanged: function () {
this.resize();
},
onSettingsChanged() {
onSettingsChanged: function () {
this.unrender();
this.removeUpdateTimer();
this.onUpdate();
},
on_desklet_removed() {
on_desklet_removed: function () {
this.unrender();
this.removeUpdateTimer();
},
onUpdate() {
onUpdate: function () {
var companySymbols = this.companySymbolsText.split("\n");
try {
var stockQuotes = this.stockReader.getStockQuotes(companySymbols);
Expand All @@ -215,12 +214,12 @@ StockQuoteDesklet.prototype = {
this.onError(companySymbols, err);
}
},
onError(companySymbols, err) {
console.log("Cannot get stock quotes for company symbols: " + companySymbols.join(","));
console.log("The following error occured: " + err);
onError: function (companySymbols, err) {
console.log("Cannot get stock quotes for symbols: " + companySymbols.join(","));
console.log("The following error occurred: " + err);
console.log("Shutting down...");
},
render(stockQuotes) {
render: function (stockQuotes) {
var table = new StockQuotesTable();
table.render(stockQuotes, this.getQuoteDisplaySettings());

Expand All @@ -242,17 +241,17 @@ StockQuoteDesklet.prototype = {
this.mainBox.add(scrollView, {expand: true});
this.setContent(this.mainBox);
},
unrender() {
unrender: function () {
this.mainBox.destroy_all_children();
this.mainBox.destroy();
},
resize() {
resize: function () {
this.mainBox.set_size(this.width, this.height);
},
setUpdateTimer() {
setUpdateTimer: function () {
this.updateLoop = Mainloop.timeout_add(this.delayMinutes * 60 * 1000, Lang.bind(this, this.onUpdate));
},
removeUpdateTimer() {
removeUpdateTimer: function () {
Mainloop.source_remove(this.updateLoop);
}
};
Expand Down

0 comments on commit 820f2ca

Please sign in to comment.