From f347dc8edc1201b6933f25b92b73d61228c92848 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Thu, 13 Aug 2026 23:10:43 +0300 Subject: [PATCH] =?UTF-8?q?vibechat:=20single-instance=20(QLockFile)=20+?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20Chat=E2=86=92vibechat=20(=D0=B1?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=D1=80=D0=BD=D0=B8=D0=BA,=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=84=D0=B8=D0=B3,=20hostname=20node=20name)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/chatgui/CMakeLists.txt | 12 ++++++------ tools/chatgui/build.bat | 2 +- tools/chatgui/build.sh | 10 +++++----- tools/chatgui/build_linux.sh | 4 ++-- tools/chatgui/src/main.cpp | 20 +++++++++++++++++--- tools/chatgui/src/mainwindow.cpp | 6 +++--- tools/chatgui/transport/node_config.cpp | 2 +- 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/tools/chatgui/CMakeLists.txt b/tools/chatgui/CMakeLists.txt index 1acc287c..9396318d 100644 --- a/tools/chatgui/CMakeLists.txt +++ b/tools/chatgui/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.16) -project(chatgui VERSION 0.1.0 LANGUAGES C CXX) +project(vibechat VERSION 0.1.0 LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -83,7 +83,7 @@ endif() # uTun core library (C, built from ../src/ and ../lib/) add_subdirectory(libutun) -add_executable(chatgui +add_executable(vibechat src/main.cpp src/mainwindow.cpp src/channellist.cpp @@ -134,13 +134,13 @@ add_executable(chatgui resources/chatgui.qrc ) -target_include_directories(chatgui PRIVATE ${CMAKE_SOURCE_DIR}/../../lib ${CMAKE_SOURCE_DIR}/../../src ${CMAKE_SOURCE_DIR}/db ${CMAKE_SOURCE_DIR}/../../lib/libopus/include ${FFMPEG_INCLUDE_DIRS}) -target_compile_definitions(chatgui PRIVATE SQLITE_THREADSAFE=1 USE_SQLITE) +target_include_directories(vibechat PRIVATE ${CMAKE_SOURCE_DIR}/../../lib ${CMAKE_SOURCE_DIR}/../../src ${CMAKE_SOURCE_DIR}/db ${CMAKE_SOURCE_DIR}/../../lib/libopus/include ${FFMPEG_INCLUDE_DIRS}) +target_compile_definitions(vibechat PRIVATE SQLITE_THREADSAFE=1 USE_SQLITE) set_source_files_properties(../../lib/sqlite3.c transport/miniaudio_impl.c PROPERTIES LANGUAGE C) if(WIN32) - target_link_libraries(chatgui PRIVATE ${QT_LIBS} rlottie::rlottie ZLIB::ZLIB OpenSSL::Crypto ZXing::ZXing utun pthread ${FFMPEG_TARGET} ${FFMPEG_LIBRARIES}) + target_link_libraries(vibechat PRIVATE ${QT_LIBS} rlottie::rlottie ZLIB::ZLIB OpenSSL::Crypto ZXing::ZXing utun pthread ${FFMPEG_TARGET} ${FFMPEG_LIBRARIES}) else() - target_link_libraries(chatgui PRIVATE ${QT_LIBS} rlottie::rlottie ZLIB::ZLIB OpenSSL::Crypto ZXing::ZXing utun pthread dl ${FFMPEG_TARGET} ${FFMPEG_LIBRARIES}) + target_link_libraries(vibechat PRIVATE ${QT_LIBS} rlottie::rlottie ZLIB::ZLIB OpenSSL::Crypto ZXing::ZXing utun pthread dl ${FFMPEG_TARGET} ${FFMPEG_LIBRARIES}) endif() # ============================================================================ diff --git a/tools/chatgui/build.bat b/tools/chatgui/build.bat index 6209cbd4..36283c7f 100644 --- a/tools/chatgui/build.bat +++ b/tools/chatgui/build.bat @@ -31,7 +31,7 @@ echo. echo =========================================== if %BUILD_RESULT% == 0 ( echo [SUCCESS] Build completed! - echo [INFO] Executable: tools\chatgui\build\chatgui.exe + echo [INFO] Executable: tools\chatgui\build\vibechat.exe ) else ( echo [FAILED] Build failed with error code: %BUILD_RESULT% echo [INFO] Check tools\chatgui\build_win.log for details diff --git a/tools/chatgui/build.sh b/tools/chatgui/build.sh index 6bf036e1..3d516dfb 100755 --- a/tools/chatgui/build.sh +++ b/tools/chatgui/build.sh @@ -41,7 +41,7 @@ log "[3/4] Deploying runtime DLLs..." WINDEPLOYQT="/ucrt64/bin/windeployqt" if [ -x "$WINDEPLOYQT" ]; then log " Running $WINDEPLOYQT..." - "$WINDEPLOYQT" --no-translations --no-compiler-runtime "$BUILD_DIR/chatgui.exe" 2>&1 | tee -a "$LOG_FILE" + "$WINDEPLOYQT" --no-translations --no-compiler-runtime "$BUILD_DIR/vibechat.exe" 2>&1 | tee -a "$LOG_FILE" RC=${PIPESTATUS[0]} if [ $RC -eq 0 ]; then log " OK: windeployqt completed" @@ -51,7 +51,7 @@ if [ -x "$WINDEPLOYQT" ]; then else log " WARN: $WINDEPLOYQT not found (install: pacman -S mingw-w64-ucrt-x86_64-qt5-tools)" log " Resolving dependencies recursively..." - todo="$BUILD_DIR/chatgui.exe" + todo="$BUILD_DIR/vibechat.exe" while [ -n "$todo" ]; do next_todo="" for src in $todo; do @@ -82,16 +82,16 @@ cp "$SRC_DIR/rlottie_build/librlottie.dll" "$BUILD_DIR/" 2>/dev/null && log " O log "" log "[4/4] Verifying..." -EXE="$BUILD_DIR/chatgui.exe" +EXE="$BUILD_DIR/vibechat.exe" if [ -f "$EXE" ]; then SIZE=$(du -h "$EXE" | cut -f1) - log " OK: chatgui.exe ($SIZE)" + log " OK: vibechat.exe ($SIZE)" log "" log "================================" log "Build SUCCESS" log "================================" log "Executable: $EXE" else - log " FAIL: chatgui.exe not found" + log " FAIL: vibechat.exe not found" exit 1 fi diff --git a/tools/chatgui/build_linux.sh b/tools/chatgui/build_linux.sh index 25556257..45ca3776 100755 --- a/tools/chatgui/build_linux.sh +++ b/tools/chatgui/build_linux.sh @@ -47,7 +47,7 @@ cmake --build "$BUILDDIR" -j"$JOBS" echo "" if [ "$ASAN" -eq 1 ]; then - echo "OK. Run: ASAN_OPTIONS=detect_leaks=1:halt_on_error=0 $BUILDDIR/chatgui" + echo "OK. Run: ASAN_OPTIONS=detect_leaks=1:halt_on_error=0 $BUILDDIR/vibechat" else - echo "OK. Run: $BUILDDIR/chatgui" + echo "OK. Run: $BUILDDIR/vibechat" fi diff --git a/tools/chatgui/src/main.cpp b/tools/chatgui/src/main.cpp index 168209eb..ddfa90f6 100644 --- a/tools/chatgui/src/main.cpp +++ b/tools/chatgui/src/main.cpp @@ -2,6 +2,9 @@ #include #include #include +#include +#include +#include #include #ifdef _WIN32 #include @@ -55,9 +58,16 @@ static struct ShutdownSentinel { int main(int argc, char *argv[]) { QApplication app(argc, argv); - app.setApplicationName("Chat"); + app.setApplicationName("vibechat"); app.setQuitOnLastWindowClosed(false); + /* single-instance: лог/БД/сокеты конфликтуют при втором запуске */ + QLockFile lock(QCoreApplication::applicationDirPath() + "/vibechat.lock"); + if (!lock.tryLock()) { + QMessageBox::warning(nullptr, "vibechat", "vibechat is already running."); + return 1; + } + app.setStyle(QStyleFactory::create("Fusion")); QPalette p; p.setColor(QPalette::Window, QColor(53, 53, 53)); @@ -77,13 +87,17 @@ int main(int argc, char *argv[]) { p.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(127, 127, 127)); app.setPalette(p); - QString cfgPath = QCoreApplication::applicationDirPath() + "/chatgui.cfg"; + QString cfgDir = QCoreApplication::applicationDirPath(); + QString cfgPath = cfgDir + "/vibechat.cfg"; + /* миграция: старый конфиг chatgui.cfg → vibechat.cfg */ + if (!QFile::exists(cfgPath) && QFile::exists(cfgDir + "/chatgui.cfg")) + QFile::rename(cfgDir + "/chatgui.cfg", cfgPath); NodeConfig cfg(cfgPath); bool needSave = false; if (!cfg.exists()) { - if (!cfg.create("chatgui", 1333)) { + if (!cfg.create("", 1333)) { qCritical("Failed to create config: %s", qPrintable(cfgPath)); return 1; } diff --git a/tools/chatgui/src/mainwindow.cpp b/tools/chatgui/src/mainwindow.cpp index 059d5202..6c607479 100644 --- a/tools/chatgui/src/mainwindow.cpp +++ b/tools/chatgui/src/mainwindow.cpp @@ -109,7 +109,7 @@ MainWindow::MainWindow(QWidget *parent, DbManager* db, const QString& cfgPath, , m_recorder(nullptr) , m_autoPlayTimer(new QTimer(this)) { - setWindowTitle("Chat"); + setWindowTitle("vibechat"); resize(900, 600); if (m_db) m_db->setDbPath(m_cfgDbPath); setupUi(); @@ -347,7 +347,7 @@ void MainWindow::setupConnects() { void MainWindow::setupTray() { m_trayIcon = new QSystemTrayIcon(this); m_trayIcon->setIcon(style()->standardIcon(QStyle::SP_ComputerIcon)); - m_trayIcon->setToolTip("Chat"); + m_trayIcon->setToolTip("vibechat"); m_trayMenu = new QMenu(this); QAction *settingsAction = m_trayMenu->addAction("Settings"); @@ -378,7 +378,7 @@ void MainWindow::setupTray() { void MainWindow::closeEvent(QCloseEvent *event) { DEBUG_DEBUG(DEBUG_CATEGORY_GENERAL, "MainWindow: closeEvent — hiding to tray"); hide(); - m_trayIcon->showMessage("Chat", "Application minimized to tray.", + m_trayIcon->showMessage("vibechat", "Application minimized to tray.", QSystemTrayIcon::Information, 2000); event->ignore(); } diff --git a/tools/chatgui/transport/node_config.cpp b/tools/chatgui/transport/node_config.cpp index 87635566..646bd35c 100644 --- a/tools/chatgui/transport/node_config.cpp +++ b/tools/chatgui/transport/node_config.cpp @@ -169,7 +169,7 @@ void NodeConfig::generateIdentity() { bool NodeConfig::create(const QString& nodeName, quint16 listenPort) { if (nodeName.isEmpty()) { QString host = QHostInfo::localHostName(); - m_nodeName = host.isEmpty() ? "chatgui" : host; + m_nodeName = host.isEmpty() ? "vibechat" : host; } else { m_nodeName = nodeName; }