Activate the existing VibeChat window on repeated launches

This commit is contained in:
evgeny committed 2026-10-19 10:29:12 +02:00
1 parent 50017b7f74
commit d7f30d7bb1
7 files changed
+473 -28

No files matched your search

+17 -16
View File
@@ -8,7 +8,6 @@
#include <QStyleFactory>
#include <QDir>
#include <QFile>
#include <QLockFile>
#include <QMessageBox>
#include <QTranslator>
#include <QComboBox>
@@ -20,6 +19,7 @@
#include <QVBoxLayout>
#include "gui_language.h"
#include "call_camera_capture.h"
#include "single_instance.h"
#include "config_parser.h"
#include <cstdio>
#include <cstring>
@@ -108,6 +108,8 @@ static struct ShutdownSentinel {
int main(int argc, char *argv[]) {
if (argc >= 2 && std::strcmp(argv[1], "--call-camera-worker") == 0) return call_camera_worker_main(argc, argv);
debug_config_init();
/* До чтения конфига видны запуск и IPC; затем уровень заменяет настройка профиля. */
debug_set_level(DEBUG_LEVEL_INFO);
#ifdef _WIN32
const bool consoleAttached = attach_parent_console();
#endif
@@ -149,16 +151,14 @@ int main(int argc, char *argv[]) {
}
#endif
/* Блокировка до любых изменений конфига/БД; предупреждение после загрузки языка. */
QLockFile lock(cfgDir + "/vibechat.lock");
const bool locked = lock.tryLock();
#ifdef _WIN32
if (!locked && lock.error() != QLockFile::LockFailedError) {
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Cannot lock data directory %s: error=%d; selection reason: %s",
qPrintable(cfgDir), static_cast<int>(lock.error()), qPrintable(storageReason));
/* Второй экземпляр передаёт запрос владельцу до чтения конфига и запуска ядра. */
SingleInstance instance(cfgDir);
const auto role = instance.start();
if (role == SingleInstance::Activated) return 0;
if (role == SingleInstance::Error) {
QMessageBox::critical(nullptr, "vibechat", instance.errorString());
return 1;
}
#endif
app.setStyle(QStyleFactory::create("Fusion"));
QPalette p;
@@ -181,7 +181,7 @@ int main(int argc, char *argv[]) {
QString cfgPath = cfgDir + "/vibechat.cfg";
/* миграция: старый конфиг chatgui.cfg → vibechat.cfg */
if (locked && !QFile::exists(cfgPath) && QFile::exists(cfgDir + "/chatgui.cfg"))
if (!QFile::exists(cfgPath) && QFile::exists(cfgDir + "/chatgui.cfg"))
QFile::rename(cfgDir + "/chatgui.cfg", cfgPath);
NodeConfig cfg(cfgPath);
@@ -208,10 +208,6 @@ int main(int argc, char *argv[]) {
};
QString language = resolveGuiLanguage(cfg.language());
if (!loadLanguage(language)) return 1;
if (!locked) {
QMessageBox::warning(nullptr, "vibechat", QCoreApplication::translate("ChatGui", "vibechat is already running."));
return 1;
}
bool needSave = false;
const bool firstRun = !cfg.exists();
@@ -275,7 +271,10 @@ int main(int argc, char *argv[]) {
nickname->setFocus();
nickname->selectAll();
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "First-run setup: requesting nickname and language, config=%s", qPrintable(cfgPath));
if (wizard.exec() != QDialog::Accepted) {
instance.setWindow(&wizard);
const int setupResult = wizard.exec();
instance.setWindow(nullptr);
if (setupResult != QDialog::Accepted) {
if (!languageReady) return 1;
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "First-run setup: cancelled, config not created");
return 0;
@@ -341,8 +340,10 @@ int main(int argc, char *argv[]) {
DbManager db;
MainWindow w(nullptr, &db, cfgPath, dbPath, debugFile,
cfg.debugLevel(), cfg.debugCategories());
instance.setWindow(&w);
if (minimized) w.showMinimized(); else w.show();
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "GUI startup: minimized_requested=%d minimized=%d", minimized, w.isMinimized());
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "GUI startup: minimized_requested=%d minimized=%d activation_server=%s",
minimized, w.isMinimized(), qPrintable(instance.serverName()));
#ifdef _WIN32
g_ctrl_node = w.utunNode();