From d99d8f7f84532f916c302b40e15f577fb220a06c Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Tue, 20 Sep 2022 10:25:59 +0300 Subject: [PATCH] - version 0.9.6 - fixes desktop file creation + settings file location --- client/config.h | 2 +- client/main.cpp | 3 +-- client/mainwindow.cpp | 8 +++++++- client/platforms/linux/autostart.cpp | 18 +++++++++++++++++- client/settings.cpp | 6 +++++- scripts/build_linux.sh | 4 ++-- 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/client/config.h b/client/config.h index 22278eb..ce89312 100644 --- a/client/config.h +++ b/client/config.h @@ -39,7 +39,7 @@ #define APP_VERSION_MAJOR 0 #define APP_VERSION_MINOR 9 -#define APP_VERSION_SUFFIX 5 +#define APP_VERSION_SUFFIX 6 //#ifdef TARGET_OSX #define ICONS ":/assets/images" diff --git a/client/main.cpp b/client/main.cpp index 8899723..bc3d29a 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -10,9 +10,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - helper::theme::applyCurrent(Settings::instance()); - app.setApplicationName(APPNAME); + helper::theme::applyCurrent(Settings::instance()); auto& settings = Settings::instance(); QFont f; if (settings.data().count(KEY_APP_FONT) > 0) diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp index 87b121e..770ed7b 100644 --- a/client/mainwindow.cpp +++ b/client/mainwindow.cpp @@ -1556,7 +1556,13 @@ void MainWindow::showMainWindow() void MainWindow::setupAppMenu() { #if defined(TARGET_LINUX) - appmenu::install(QCoreApplication::applicationFilePath().toStdString()); + auto exe_path = QFileInfo(QCoreApplication::arguments().front()).absoluteFilePath(); + const char* appimage = std::getenv("APPIMAGE"); + if (appimage != nullptr) + exe_path = appimage; + + qDebug() << "Found exe path: " << exe_path; + appmenu::install(exe_path.toStdString()); #endif } diff --git a/client/platforms/linux/autostart.cpp b/client/platforms/linux/autostart.cpp index c479a9a..4383353 100644 --- a/client/platforms/linux/autostart.cpp +++ b/client/platforms/linux/autostart.cpp @@ -98,8 +98,21 @@ static fs::path appmenu_install_dir() void appmenu::install(const std::string& path_to_me) { + auto path_to_desktop = appmenu_install_dir() / NOO_DESKTOP_NAME; + + // Check if app is installed already. + // The code below checks for path to app; as this app is distributed as .AppImage with version numbers - every new version will trigger desktop file rewriting + std::ifstream ifs(path_to_desktop); + std::string content((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); + if (content.find(path_to_me) != std::string::npos) + return; + + // Remove old one + std::string uninstall_cmd = "/usr/bin/xdg-desktop-menu uninstall --novendor " + (appmenu_install_dir() / NOO_DESKTOP_NAME).string(); + system(uninstall_cmd.c_str()); + // Put .desktop file to ~/.config/autostart - std::ofstream ofs(appmenu_install_dir() / NOO_DESKTOP_NAME); + std::ofstream ofs(path_to_desktop); if (ofs.is_open()) { ofs << fixup_desktop_file(read_desktop_file(), path_to_me); @@ -126,6 +139,9 @@ void appmenu::install(const std::string& path_to_me) } } } + + std::string install_cmd = "/usr/bin/xdg-desktop-menu install --novendor " + (appmenu_install_dir() / NOO_DESKTOP_NAME).string(); + system(install_cmd.c_str()); } void appmenu::uninstall() diff --git a/client/settings.cpp b/client/settings.cpp index dc4af1e..5003e7d 100644 --- a/client/settings.cpp +++ b/client/settings.cpp @@ -6,6 +6,7 @@ #include #include #include +#include Settings::Settings() { @@ -27,7 +28,8 @@ void Settings::save() auto path = helper::path::pathToSettings(); QSettings settings(path, QSettings::IniFormat); settings.clear(); - for (const QString& e: data().keys()) + + for (const QString& e: mData.keys()) { settings.setValue(e, data().value(e)); } @@ -42,6 +44,8 @@ void Settings::load() // Path to settings file QString path = helper::path::pathToSettings(); + qDebug() << "Settings file path: " << path; + // Check if directory exists at all QString dir = QFileInfo(path).absoluteDir().path(); diff --git a/scripts/build_linux.sh b/scripts/build_linux.sh index dbbaa32..8c5b05d 100755 --- a/scripts/build_linux.sh +++ b/scripts/build_linux.sh @@ -2,9 +2,9 @@ # I use this script on two different hosts so there are logic to find proper Qt installation -export QT_HOME=/home/$USER/qt/5.12.10/gcc_64 +export QT_HOME=/home/$USER/qt5.15/5.15.2/gcc_64 if [ ! -d "$QT_HOME" ] ; then - export QT_HOME=/home/$USER/qt5/5.12.12/gcc_64 + export QT_HOME=/home/$USER/qt5.15/5.15.2/gcc_64 fi # Build .appimage