Bug 470293 - Kate clears sessions upon close
Summary: Kate clears sessions upon close
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: sessions (other bugs)
Version First Reported In: 22.12.3
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
: 467877 472510 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-05-26 14:32 UTC by Christopher Jacobs
Modified: 2024-06-20 10:48 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 23.08.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Jacobs 2023-05-26 14:32:38 UTC
SUMMARY
If Kate is not closed using "file->quit" from the menu bar, all of the files in the sessions are cleared and the session is saved as empty, overwriting any previous session information as well --- that is, all of the "[Document X]" sections are removed and `Count=0` is written to the [Open Documents] section. Reproducible in both Windows and Linux/Plasma

STEPS TO REPRODUCE
1. Open some files with Kate.
2. Save session.
2.5. (optional) Check the `.katesession` file for the files you have open and confirm that they exist.
3. Close application using the "X" button in the title bar.
4. Relaunch Kate, see that the "Session Chooser" lists 0 files, and no files are opened when the session is selected.

OBSERVED RESULT


EXPECTED RESULT


SOFTWARE/OS VERSIONS
Windows: Windows 10
Linux/KDE Plasma:
  linux 6.2.2.arch1-1
  plasma-framework 5.103.0-1
  plasma-workspace 5.27.2-1
Qt Version: 
  qt5-base 5.15.8+kde+r182-1
Comment 1 Christoph Cullmann 2023-07-31 18:15:24 UTC
*** Bug 472510 has been marked as a duplicate of this bug. ***
Comment 2 Christoph Cullmann 2023-07-31 18:16:55 UTC
I think we did break the logic for that with the current code in


/**
 * queryClose(), take care that after the last mainwindow the stuff is closed
 */
bool KateMainWindow::queryClose()
{
    // session saving, can we close all views ?
    // just test, not close them actually
    if (qApp->isSavingSession()) {
        return queryClose_internal();
    }

    // normal closing of window
    // if we are not the last window, just close the documents we own
    if (KateApp::self()->mainWindowsCount() > 1) {
        return winClosesDocuments() ? queryClose_internal(nullptr, this) : true;
    }

    // last one: check if we can close all documents, try run
    // and save docs if we really close down !
    if (queryClose_internal()) {
        KateApp::self()->sessionManager()->saveActiveSession(true);
        KateApp::self()->stashManager()->stashDocuments(KateApp::self()->sessionManager()->activeSession()->config(),
                                                        KateApp::self()->documentManager()->documentList());
        return true;
    }

    return false;
}
Comment 3 Christoph Cullmann 2023-07-31 18:40:53 UTC
Hmmm, or the session save timer does that on shutdown.


void KateSessionManager::initTimer()
{
    if (m_sessionSaveTimer) {
        qWarning() << "Session save timer is already initalized! should not happen";
        return;
    }
    m_sessionSaveTimer = std::make_unique<QTimer>();
    m_sessionSaveTimer->setInterval(5000);
    m_sessionSaveTimer->setSingleShot(true);
    auto *t = m_sessionSaveTimer.get();
    auto dm = KateApp::self()->documentManager();
    auto startTimer = [t] {
        if (!t->isActive()) {
            t->start();
        }
    };
    connect(dm, &KateDocManager::documentCreated, t, startTimer);
    connect(dm, &KateDocManager::documentDeleted, t, startTimer);
    m_sessionSaveTimer->callOnTimeout(this, [this] {
        saveActiveSession(true);
    });
}
Comment 4 Bug Janitor Service 2023-07-31 19:18:04 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/1272
Comment 5 Christoph Cullmann 2023-07-31 19:26:52 UTC
If somebody could test my patch that would be awesome.
Comment 6 Christoph Cullmann 2023-08-01 17:51:43 UTC
Git commit 772450c9fb3217373ab3d279dfc5df0b4c741d3c by Christoph Cullmann.
Committed on 01/08/2023 at 19:33.
Pushed by cullmann into branch 'master'.

avoid that the session save timer messes up session saving

we need to ensure it doesn't trigger during window/app closing

M  +3    -0    apps/lib/kateapp.cpp
M  +6    -0    apps/lib/katemainwindow.cpp
M  +19   -28   apps/lib/session/katesessionmanager.cpp
M  +40   -3    apps/lib/session/katesessionmanager.h

https://invent.kde.org/utilities/kate/-/commit/772450c9fb3217373ab3d279dfc5df0b4c741d3c
Comment 7 Christoph Cullmann 2023-08-02 19:20:09 UTC
Git commit f459fc544c31efbee9645612ee517f73a2808886 by Christoph Cullmann.
Committed on 02/08/2023 at 21:20.
Pushed by cullmann into branch 'release/23.08'.

avoid that the session save timer messes up session saving

we need to ensure it doesn't trigger during window/app closing


(cherry picked from commit 772450c9fb3217373ab3d279dfc5df0b4c741d3c)

M  +3    -0    apps/lib/kateapp.cpp
M  +6    -0    apps/lib/katemainwindow.cpp
M  +19   -28   apps/lib/session/katesessionmanager.cpp
M  +40   -3    apps/lib/session/katesessionmanager.h

https://invent.kde.org/utilities/kate/-/commit/f459fc544c31efbee9645612ee517f73a2808886
Comment 8 Christoph Cullmann 2023-08-02 19:24:04 UTC
I hope this is fixed, if somebody can confirm with a master build that would be great.
Comment 9 Christoph Cullmann 2023-09-30 16:58:29 UTC
*** Bug 467877 has been marked as a duplicate of this bug. ***
Comment 10 Félim Whiteley 2024-06-20 10:48:41 UTC
This was still an issue up until 24.05.0 so not sure it was the same as the linked bug but it's working now! Thanks!