diff --git a/yfquotes@thegli/CHANGELOG.md b/yfquotes@thegli/CHANGELOG.md index bc706200..b565a20d 100644 --- a/yfquotes@thegli/CHANGELOG.md +++ b/yfquotes@thegli/CHANGELOG.md @@ -1,3 +1,16 @@ +### 0.15.1 - September 12, 2024 + +Features: + +- update Catalan translation (courtesy of [Odyssey](https://github.com/odyssey)) +- update Dutch translation (courtesy of [qadzek](https://github.com/qadzek)) +- update Spanish translation (courtesy of [haggen88](https://github.com/haggen88)) + +Bugfixes: + +- cache quotes responses for each desklet instance separately +- restore automatic quotes data refresh on settings import + ### 0.15.0 - September 2, 2024 Features: diff --git a/yfquotes@thegli/files/yfquotes@thegli/desklet.js b/yfquotes@thegli/files/yfquotes@thegli/desklet.js index 330690d8..6220e405 100644 --- a/yfquotes@thegli/files/yfquotes@thegli/desklet.js +++ b/yfquotes@thegli/files/yfquotes@thegli/desklet.js @@ -77,12 +77,15 @@ Soup.Session.prototype.add_feature.call(_httpSession, _cookieJar); let _crumb = null; -let _lastResponse = { +// cache the last QF quotes response +const _lastResponses = new Map(); +_lastResponses.set("default", { + symbolsArgument: "", responseResult: [], // we should never see this error message responseError: _("No quotes data to display"), lastUpdated: new Date() -}; +}); function logDebug(msg) { if (LOG_DEBUG) { @@ -159,6 +162,15 @@ YahooFinanceQuoteUtils.prototype = { }; }, + compareSymbolsArgument: function(symbolsArgument, quoteSymbolsText) { + const argumentFromText = this.buildSymbolsArgument(quoteSymbolsText); + if (symbolsArgument.length === 0 || argumentFromText.length === 0) { + return false; + } + + return symbolsArgument === argumentFromText; + }, + isOkStatus: function(soupMessage) { if (soupMessage) { if (IS_SOUP_2) { @@ -248,6 +260,7 @@ YahooFinanceQuoteReader.prototype = { quoteUtils: new YahooFinanceQuoteUtils(), getCookie: function(customUserAgent, callback) { + logDebug("getCookie"); const _that = this; const message = Soup.Message.new("GET", YF_COOKIE_URL); @@ -296,6 +309,7 @@ YahooFinanceQuoteReader.prototype = { }, postConsent: function(customUserAgent, formData, callback) { + logDebug("postConsent"); const _that = this; const message = Soup.Message.new("POST", YF_CONSENT_URL); @@ -345,6 +359,7 @@ YahooFinanceQuoteReader.prototype = { }, getCrumb: function(customUserAgent, callback) { + logDebug("getCrumb"); const _that = this; const message = Soup.Message.new("GET", YF_CRUMB_URL); @@ -393,6 +408,7 @@ YahooFinanceQuoteReader.prototype = { }, getFinanceData: function(quoteSymbolsArg, customUserAgent, callback) { + logDebug("getFinanceData"); const _that = this; if (quoteSymbolsArg.length === 0) { @@ -710,6 +726,7 @@ StockQuoteDesklet.prototype = { __proto__: Desklet.Desklet.prototype, init: function(metadata, id) { + logDebug("init desklet id " + id); this.metadata = metadata; this.id = id; this.updateId = 0; @@ -864,22 +881,24 @@ StockQuoteDesklet.prototype = { // called on events that change the quotes data layout (sorting, show/hide fields, text color, etc) onRenderSettingsChanged: function() { + logDebug("onRenderSettingsChanged"); this.render(); }, // called on events that change the way YFQ data are fetched (data refresh interval) onDataFetchSettingsChanged: function() { + logDebug("onDataFetchSettingsChanged"); this.removeUpdateTimer(); this.setUpdateTimer(); }, // called on events that change the quotes data (quotes list) - // BEWARE: DO NOT use this function as callback in settings.bindProperty() - otherwise multiple YFQ requests are fired, and multiple timers are created! + // BEWARE: DO NOT use this function as callback in settings.bind() - otherwise multiple YFQ requests are fired, and multiple timers are created! onQuotesListChanged: function() { logDebug("onQuotesListChanged"); if (this.updateInProgress) { - logInfo("Data refresh already in progress"); + logDebug("Data refresh in progress for desklet id " + this.id); return; } this.removeUpdateTimer(); @@ -900,17 +919,18 @@ StockQuoteDesklet.prototype = { }, fetchFinanceDataAndRender: function(quoteSymbolsArg, customUserAgent) { + logDebug("fetchFinanceDataAndRender. quotes=" + quoteSymbolsArg + ", custom User-Agent: " + customUserAgent); const _that = this; this.quoteReader.getFinanceData(quoteSymbolsArg, customUserAgent, function(response) { logDebug("YF query response: " + response); let parsedResponse = JSON.parse(response); - _lastResponse = - { + _lastResponses.set(_that.id, { + symbolsArgument: quoteSymbolsArg, responseResult: parsedResponse.quoteResponse.result, responseError: parsedResponse.quoteResponse.error, lastUpdated: new Date() - }; + }); _that.setUpdateTimer(); _that.render(); }); @@ -920,6 +940,7 @@ StockQuoteDesklet.prototype = { for (let cookie of _cookieJar.all_cookies()) { let cookieName = IS_SOUP_2 ? cookie.name : cookie.get_name(); if (cookieName === name) { + logDebug("Cookie found in jar: " + name); return true; } } @@ -928,6 +949,7 @@ StockQuoteDesklet.prototype = { }, fetchCookieAndRender: function(quoteSymbolsArg, customUserAgent) { + logDebug("fetchCookieAndRender, custom User-Agent: " + customUserAgent); const _that = this; this.quoteReader.getCookie(customUserAgent, function(authResponseMessage, responseBody) { @@ -944,6 +966,7 @@ StockQuoteDesklet.prototype = { }, processConsentAndRender: function(authResponseMessage, consentPage, quoteSymbolsArg, customUserAgent) { + logDebug("processConsentAndRender"); const _that = this; const formElementRegex = /(