diff --git a/README.md b/README.md index 1ad5dcb..16dbf2b 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ 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/*. @@ -15,6 +15,15 @@ Check out the desklet configuration settings, and choose the refresh period, the ## 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: diff --git a/files/yfquotes@thegli/desklet.js b/files/yfquotes@thegli/desklet.js index 1674afb..5a5a1cc 100644 --- a/files/yfquotes@thegli/desklet.js +++ b/files/yfquotes@thegli/desklet.js @@ -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 @@ -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; @@ -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; @@ -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 = []; @@ -103,13 +102,13 @@ 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({ @@ -117,13 +116,13 @@ StockQuotesTable.prototype = { 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); @@ -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)); } }; @@ -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); @@ -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, @@ -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); @@ -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()); @@ -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); } };