From f2002892aa875b9ad83bcb4bf71768f557071dc6 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Thu, 4 Jan 2018 13:32:20 +0100 Subject: [PATCH] Save previous crashed session that were not restored to session file Closes #2331 --- src/lib/app/mainapplication.cpp | 12 +++++++++++- src/lib/session/recoveryjsobject.cpp | 1 + src/lib/session/restoremanager.cpp | 15 ++++++++++++++- src/lib/session/restoremanager.h | 2 ++ src/lib/session/sessionmanager.cpp | 2 +- src/lib/tabwidget/tabwidget.cpp | 4 ++++ src/lib/webtab/webtab.cpp | 4 ---- 7 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index 13abef057..d0d0c4575 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -426,7 +426,7 @@ void MainApplication::openSession(BrowserWindow* window, RestoreData &restoreDat if (m_isRestoring) window->tabWidget()->closeRecoveryTab(); - if (window->tabWidget()->normalTabsCount() > 1) { + if (window->tabWidget()->count() != 0) { // This can only happen when recovering crashed session! // Don't restore tabs in current window as user already opened some new tabs. createWindow(Qz::BW_OtherRestoredWindow)->restoreWindow(restoreData.windows.takeAt(0)); @@ -452,6 +452,7 @@ bool MainApplication::restoreSession(BrowserWindow* window, RestoreData restoreD openSession(window, restoreData); + m_restoreManager->clearRestoreData(); destroyRestoreManager(); m_isRestoring = false; @@ -460,6 +461,10 @@ bool MainApplication::restoreSession(BrowserWindow* window, RestoreData restoreD void MainApplication::destroyRestoreManager() { + if (m_restoreManager && m_restoreManager->isValid()) { + return; + } + // Restore JavaScript settings const bool jsEnabled = Settings().value(QSL("Web-Browser-Settings/allowJavaScript"), true).toBool(); m_webProfile->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, jsEnabled); @@ -730,6 +735,11 @@ QByteArray MainApplication::saveState() const restoreData.windows.append(BrowserWindow::SavedWindow(window)); } + if (m_restoreManager && m_restoreManager->isValid()) { + QDataStream stream(&restoreData.crashedSession, QIODevice::WriteOnly); + stream << m_restoreManager->restoreData(); + } + QByteArray data; QDataStream stream(&data, QIODevice::WriteOnly); diff --git a/src/lib/session/recoveryjsobject.cpp b/src/lib/session/recoveryjsobject.cpp index 818559317..c013e0e13 100644 --- a/src/lib/session/recoveryjsobject.cpp +++ b/src/lib/session/recoveryjsobject.cpp @@ -78,6 +78,7 @@ void RecoveryJsObject::startNewSession() m_page->load(window->homepageUrl()); + mApp->restoreManager()->clearRestoreData(); mApp->destroyRestoreManager(); } diff --git a/src/lib/session/restoremanager.cpp b/src/lib/session/restoremanager.cpp index 9646a160a..da9a22577 100644 --- a/src/lib/session/restoremanager.cpp +++ b/src/lib/session/restoremanager.cpp @@ -22,7 +22,7 @@ #include -static const int restoreDataVersion = 0; +static const int restoreDataVersion = 1; bool RestoreData::isValid() const { @@ -42,6 +42,7 @@ QDataStream &operator<<(QDataStream &stream, const RestoreData &data) } stream << restoreDataVersion; + stream << data.crashedSession; return stream; } @@ -61,6 +62,10 @@ QDataStream &operator>>(QDataStream &stream, RestoreData &data) int version; stream >> version; + if (version >= 1) { + stream >> data.crashedSession; + } + return stream; } @@ -80,6 +85,14 @@ RestoreData RestoreManager::restoreData() const return m_data; } +void RestoreManager::clearRestoreData() +{ + m_data.clear(); + + QDataStream stream(&m_data.crashedSession, QIODevice::ReadOnly); + stream >> m_data; +} + bool RestoreManager::isValid() const { return m_data.isValid(); diff --git a/src/lib/session/restoremanager.h b/src/lib/session/restoremanager.h index 664a67a35..bc0f00286 100644 --- a/src/lib/session/restoremanager.h +++ b/src/lib/session/restoremanager.h @@ -28,6 +28,7 @@ class RecoveryJsObject; struct QUPZILLA_EXPORT RestoreData { QVector windows; + QByteArray crashedSession; bool isValid() const; void clear(); @@ -44,6 +45,7 @@ public: bool isValid() const; RestoreData restoreData() const; + void clearRestoreData(); QObject *recoveryObject(WebPage *page); diff --git a/src/lib/session/sessionmanager.cpp b/src/lib/session/sessionmanager.cpp index 50165ae93..6220f16fe 100644 --- a/src/lib/session/sessionmanager.cpp +++ b/src/lib/session/sessionmanager.cpp @@ -377,7 +377,7 @@ void SessionManager::openSessionManagerDialog() void SessionManager::autoSaveLastSession() { - if (mApp->isPrivate() || mApp->isRestoring() || mApp->windowCount() == 0 || mApp->restoreManager()) { + if (mApp->isPrivate() || mApp->isRestoring() || mApp->windowCount() == 0) { return; } diff --git a/src/lib/tabwidget/tabwidget.cpp b/src/lib/tabwidget/tabwidget.cpp index 67ad49130..9f80970bc 100644 --- a/src/lib/tabwidget/tabwidget.cpp +++ b/src/lib/tabwidget/tabwidget.cpp @@ -767,6 +767,10 @@ QList TabWidget::allTabs(bool withPinned) bool TabWidget::restoreState(const QVector &tabs, int currentTab) { + if (tabs.isEmpty()) { + return false; + } + for (int i = 0; i < tabs.size(); ++i) { WebTab::SavedTab tab = tabs.at(i); int index = addView(QUrl(), Qz::NT_CleanSelectedTab, false, tab.isPinned); diff --git a/src/lib/webtab/webtab.cpp b/src/lib/webtab/webtab.cpp index 5b9802105..a9cc43f2b 100644 --- a/src/lib/webtab/webtab.cpp +++ b/src/lib/webtab/webtab.cpp @@ -46,10 +46,6 @@ WebTab::SavedTab::SavedTab() WebTab::SavedTab::SavedTab(WebTab* webTab) { - if (webTab->url().toString() == QL1S("falkon:restore")) { - return; - } - title = webTab->title(); url = webTab->url(); icon = webTab->icon(true);