Occasionally save window/split/tab layout
The window layout is only saved if something has been changed. When something relevant to the window layout is changed, a save is queued to run after 10 seconds. If within those 10 seconds, another thing is changed, that timer is reset and will run after 10 seconds again. Events that cause the save to be queued up: - Tab created - Tab removed - Tab moved - Tab name changed - Split created - Split removed - Split moved - Split channel changed - Split resized - Window moved - Window resized What currently does not trigger the save to be queued up: - Active tab changed
This commit is contained in:
@@ -23,6 +23,8 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#define SETTINGS_FILENAME "/window-layout.json"
|
||||
|
||||
namespace chatterino {
|
||||
@@ -83,6 +85,14 @@ WindowManager::WindowManager()
|
||||
this->wordFlagsListener_.cb = [this](auto) {
|
||||
this->updateWordTypeMask(); //
|
||||
};
|
||||
|
||||
this->saveTimer = new QTimer;
|
||||
|
||||
this->saveTimer->setSingleShot(true);
|
||||
|
||||
QObject::connect(this->saveTimer, &QTimer::timeout, [] {
|
||||
getApp()->windows->save(); //
|
||||
});
|
||||
}
|
||||
|
||||
MessageElementFlags WindowManager::getWordFlags()
|
||||
@@ -357,6 +367,8 @@ void WindowManager::initialize(Settings &settings, Paths &paths)
|
||||
|
||||
void WindowManager::save()
|
||||
{
|
||||
log("[WindowManager] Saving");
|
||||
|
||||
assertInGuiThread();
|
||||
auto app = getApp();
|
||||
|
||||
@@ -453,6 +465,13 @@ void WindowManager::sendAlert()
|
||||
QApplication::alert(this->getMainWindow().window(), flashDuration);
|
||||
}
|
||||
|
||||
void WindowManager::queueSave()
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
this->saveTimer->start(10s);
|
||||
}
|
||||
|
||||
void WindowManager::encodeNodeRecusively(SplitNode *node, QJsonObject &obj)
|
||||
{
|
||||
switch (node->getType()) {
|
||||
|
||||
Reference in New Issue
Block a user