Browse Source

vibechat: single-instance (QLockFile) + переименование Chat→vibechat (бинарник, конфиг, hostname node name)

topo_upd
Evgeny 2 months ago
parent
commit
f347dc8edc
  1. 12
      tools/chatgui/CMakeLists.txt
  2. 2
      tools/chatgui/build.bat
  3. 10
      tools/chatgui/build.sh
  4. 4
      tools/chatgui/build_linux.sh
  5. 20
      tools/chatgui/src/main.cpp
  6. 6
      tools/chatgui/src/mainwindow.cpp
  7. 2
      tools/chatgui/transport/node_config.cpp

12
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()
# ============================================================================

2
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

10
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

4
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

20
tools/chatgui/src/main.cpp

@ -2,6 +2,9 @@
#include <QPalette>
#include <QStyleFactory>
#include <QDir>
#include <QFile>
#include <QLockFile>
#include <QMessageBox>
#include <cstdio>
#ifdef _WIN32
#include <windows.h>
@ -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;
}

6
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();
}

2
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;
}

Loading…
Cancel
Save