From 65b7167b5f0dbef5c7bc282138f6e592e17f07bf Mon Sep 17 00:00:00 2001 From: chylex <contact@chylex.com> Date: Sat, 5 Aug 2017 18:36:17 +0200 Subject: [PATCH] Rewrite browser reload to save column notification state in session data --- Core/FormBrowser.cs | 4 ++-- Resources/Scripts/code.js | 16 +++++++++++++--- Resources/Scripts/plugins.browser.js | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs index d7fe7e1b..4f56659e 100644 --- a/Core/FormBrowser.cs +++ b/Core/FormBrowser.cs @@ -328,7 +328,7 @@ private void trayIcon_ClickClose(object sender, EventArgs e){ } private void plugins_Reloaded(object sender, PluginErrorEventArgs e){ - browser.GetBrowser().Reload(); + ReloadToTweetDeck(); } private void plugins_PluginChangedState(object sender, PluginChangedStateEventArgs e){ @@ -429,7 +429,7 @@ public void UpdateProperties(PropertyBridge.Environment environment){ } public void ReloadToTweetDeck(){ - browser.ExecuteScriptAsync($"gc&&gc();window.location.href='{TwitterUtils.TweetDeckURL}'"); + browser.ExecuteScriptAsync($"if(window.TDGF_reload)window.TDGF_reload();else window.location.href='{TwitterUtils.TweetDeckURL}'"); } // callback handlers diff --git a/Resources/Scripts/code.js b/Resources/Scripts/code.js index b2860bc9..4ae84619 100644 --- a/Resources/Scripts/code.js +++ b/Resources/Scripts/code.js @@ -854,8 +854,19 @@ } // - // Block: Memory cleanup check and execution. + // Block: Custom reload function with memory cleanup. // + window.TDGF_reload = function(){ + let session = TD.storage.feedController.getAll() + .filter(feed => !!feed.getTopSortIndex()) + .reduce((obj, feed) => (obj[feed.privateState.key] = feed.getTopSortIndex(), obj), {}); + + $TD.setSessionData("gc", JSON.stringify(session)).then(() => { + window.gc && window.gc(); + window.location.reload(); + }); + }; + window.TDGF_tryRunCleanup = function(){ // all textareas are empty if ($("textarea").is(function(){ @@ -882,8 +893,7 @@ } // cleanup - window.gc && window.gc(); - window.location.reload(); + window.TDGF_reload(); return true; }; diff --git a/Resources/Scripts/plugins.browser.js b/Resources/Scripts/plugins.browser.js index a5fd9911..05cce5d7 100644 --- a/Resources/Scripts/plugins.browser.js +++ b/Resources/Scripts/plugins.browser.js @@ -98,7 +98,7 @@ // window.TDPF_requestReload = function(){ if (!isReloading){ - window.setTimeout(() => location.reload(), 1); + window.setTimeout(window.TDGF_reload, 1); isReloading = true; } };