1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

Save previous crashed session that were not restored to session file

Closes #2331
This commit is contained in:
David Rosca 2018-01-04 13:32:20 +01:00
parent d1becc23e9
commit f2002892aa
7 changed files with 33 additions and 7 deletions

View File

@ -426,7 +426,7 @@ void MainApplication::openSession(BrowserWindow* window, RestoreData &restoreDat
if (m_isRestoring) if (m_isRestoring)
window->tabWidget()->closeRecoveryTab(); window->tabWidget()->closeRecoveryTab();
if (window->tabWidget()->normalTabsCount() > 1) { if (window->tabWidget()->count() != 0) {
// This can only happen when recovering crashed session! // This can only happen when recovering crashed session!
// Don't restore tabs in current window as user already opened some new tabs. // Don't restore tabs in current window as user already opened some new tabs.
createWindow(Qz::BW_OtherRestoredWindow)->restoreWindow(restoreData.windows.takeAt(0)); createWindow(Qz::BW_OtherRestoredWindow)->restoreWindow(restoreData.windows.takeAt(0));
@ -452,6 +452,7 @@ bool MainApplication::restoreSession(BrowserWindow* window, RestoreData restoreD
openSession(window, restoreData); openSession(window, restoreData);
m_restoreManager->clearRestoreData();
destroyRestoreManager(); destroyRestoreManager();
m_isRestoring = false; m_isRestoring = false;
@ -460,6 +461,10 @@ bool MainApplication::restoreSession(BrowserWindow* window, RestoreData restoreD
void MainApplication::destroyRestoreManager() void MainApplication::destroyRestoreManager()
{ {
if (m_restoreManager && m_restoreManager->isValid()) {
return;
}
// Restore JavaScript settings // Restore JavaScript settings
const bool jsEnabled = Settings().value(QSL("Web-Browser-Settings/allowJavaScript"), true).toBool(); const bool jsEnabled = Settings().value(QSL("Web-Browser-Settings/allowJavaScript"), true).toBool();
m_webProfile->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, jsEnabled); m_webProfile->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, jsEnabled);
@ -730,6 +735,11 @@ QByteArray MainApplication::saveState() const
restoreData.windows.append(BrowserWindow::SavedWindow(window)); restoreData.windows.append(BrowserWindow::SavedWindow(window));
} }
if (m_restoreManager && m_restoreManager->isValid()) {
QDataStream stream(&restoreData.crashedSession, QIODevice::WriteOnly);
stream << m_restoreManager->restoreData();
}
QByteArray data; QByteArray data;
QDataStream stream(&data, QIODevice::WriteOnly); QDataStream stream(&data, QIODevice::WriteOnly);

View File

@ -78,6 +78,7 @@ void RecoveryJsObject::startNewSession()
m_page->load(window->homepageUrl()); m_page->load(window->homepageUrl());
mApp->restoreManager()->clearRestoreData();
mApp->destroyRestoreManager(); mApp->destroyRestoreManager();
} }

View File

@ -22,7 +22,7 @@
#include <QFile> #include <QFile>
static const int restoreDataVersion = 0; static const int restoreDataVersion = 1;
bool RestoreData::isValid() const bool RestoreData::isValid() const
{ {
@ -42,6 +42,7 @@ QDataStream &operator<<(QDataStream &stream, const RestoreData &data)
} }
stream << restoreDataVersion; stream << restoreDataVersion;
stream << data.crashedSession;
return stream; return stream;
} }
@ -61,6 +62,10 @@ QDataStream &operator>>(QDataStream &stream, RestoreData &data)
int version; int version;
stream >> version; stream >> version;
if (version >= 1) {
stream >> data.crashedSession;
}
return stream; return stream;
} }
@ -80,6 +85,14 @@ RestoreData RestoreManager::restoreData() const
return m_data; return m_data;
} }
void RestoreManager::clearRestoreData()
{
m_data.clear();
QDataStream stream(&m_data.crashedSession, QIODevice::ReadOnly);
stream >> m_data;
}
bool RestoreManager::isValid() const bool RestoreManager::isValid() const
{ {
return m_data.isValid(); return m_data.isValid();

View File

@ -28,6 +28,7 @@ class RecoveryJsObject;
struct QUPZILLA_EXPORT RestoreData struct QUPZILLA_EXPORT RestoreData
{ {
QVector<BrowserWindow::SavedWindow> windows; QVector<BrowserWindow::SavedWindow> windows;
QByteArray crashedSession;
bool isValid() const; bool isValid() const;
void clear(); void clear();
@ -44,6 +45,7 @@ public:
bool isValid() const; bool isValid() const;
RestoreData restoreData() const; RestoreData restoreData() const;
void clearRestoreData();
QObject *recoveryObject(WebPage *page); QObject *recoveryObject(WebPage *page);

View File

@ -377,7 +377,7 @@ void SessionManager::openSessionManagerDialog()
void SessionManager::autoSaveLastSession() void SessionManager::autoSaveLastSession()
{ {
if (mApp->isPrivate() || mApp->isRestoring() || mApp->windowCount() == 0 || mApp->restoreManager()) { if (mApp->isPrivate() || mApp->isRestoring() || mApp->windowCount() == 0) {
return; return;
} }

View File

@ -767,6 +767,10 @@ QList<WebTab*> TabWidget::allTabs(bool withPinned)
bool TabWidget::restoreState(const QVector<WebTab::SavedTab> &tabs, int currentTab) bool TabWidget::restoreState(const QVector<WebTab::SavedTab> &tabs, int currentTab)
{ {
if (tabs.isEmpty()) {
return false;
}
for (int i = 0; i < tabs.size(); ++i) { for (int i = 0; i < tabs.size(); ++i) {
WebTab::SavedTab tab = tabs.at(i); WebTab::SavedTab tab = tabs.at(i);
int index = addView(QUrl(), Qz::NT_CleanSelectedTab, false, tab.isPinned); int index = addView(QUrl(), Qz::NT_CleanSelectedTab, false, tab.isPinned);

View File

@ -46,10 +46,6 @@ WebTab::SavedTab::SavedTab()
WebTab::SavedTab::SavedTab(WebTab* webTab) WebTab::SavedTab::SavedTab(WebTab* webTab)
{ {
if (webTab->url().toString() == QL1S("falkon:restore")) {
return;
}
title = webTab->title(); title = webTab->title();
url = webTab->url(); url = webTab->url();
icon = webTab->icon(true); icon = webTab->icon(true);