From fff67bbedb762580e9fcb5c0050905c86538ef23 Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Tue, 20 Sep 2022 11:19:03 +0300 Subject: [PATCH] - version 0.1.8 - new state machine + fix problems with desktop file. --- app/aboutdlg.cpp | 3 +++ app/autostart.cpp | 18 +++++++++++++++++- app/config.h | 2 +- app/main.cpp | 7 ++++++- app/mainwindow.h | 25 ++++++++++++++++++++----- app/qbreak.pro | 2 ++ scripts/build_linux.sh | 4 ++-- 7 files changed, 51 insertions(+), 10 deletions(-) diff --git a/app/aboutdlg.cpp b/app/aboutdlg.cpp index f5b030b..78c41fb 100644 --- a/app/aboutdlg.cpp +++ b/app/aboutdlg.cpp @@ -13,6 +13,9 @@ AboutDlg::AboutDlg(QWidget *parent) : .arg(QBREAK_VERSION_MAJOR) .arg(QBREAK_VERSION_MINOR) .arg(QBREAK_VERSION_SUFFIX); +#if defined(DEBUG) + version_text += ". Debug build."; +#endif ui->mAppVersionLabel->setText(version_text); } diff --git a/app/autostart.cpp b/app/autostart.cpp index 11c4e42..602ad87 100644 --- a/app/autostart.cpp +++ b/app/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() / QBREAK_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 " + path_to_desktop.string(); + system(uninstall_cmd.c_str()); + // Put .desktop file to ~/.config/autostart - std::ofstream ofs(appmenu_install_dir() / QBREAK_DESKTOP_NAME); + std::ofstream ofs(path_to_desktop); if (ofs.is_open()) { ofs << fixup_desktop_file(read_desktop_file(), path_to_me); @@ -125,6 +138,9 @@ void appmenu::install(const std::string& path_to_me) } } } + + std::string install_cmd = "/usr/bin/xdg-desktop-menu install --novendor " + path_to_desktop.string(); + system(install_cmd.c_str()); } void appmenu::uninstall() diff --git a/app/config.h b/app/config.h index 26f91d3..6e476fb 100644 --- a/app/config.h +++ b/app/config.h @@ -4,7 +4,7 @@ // App version #define QBREAK_VERSION_MAJOR 0 #define QBREAK_VERSION_MINOR 1 -#define QBREAK_VERSION_SUFFIX 6 +#define QBREAK_VERSION_SUFFIX 8 // How often UI is updated - interval in seconds #define INTERVAL_UPDATE_UI (60) diff --git a/app/main.cpp b/app/main.cpp index 583db4b..494354f 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -39,7 +39,12 @@ int main(int argc, char *argv[]) parser.process(app); // Put itself into app menu - appmenu::install(QFileInfo(argv[0]).absoluteFilePath().toStdString()); + auto exe_path = QFileInfo(QCoreApplication::arguments().front()).absoluteFilePath(); + const char* appimage = std::getenv("APPIMAGE"); + if (appimage != nullptr) + exe_path = appimage; + + appmenu::install(exe_path.toStdString()); // Main window is full screen window, so start with tray icon only MainWindow w; diff --git a/app/mainwindow.h b/app/mainwindow.h index 3ca44c8..bf8f8e1 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -11,6 +11,15 @@ #include "settings.h" #include "settingsdialog.h" +// Possible app states +enum class AppState +{ + None, + Counting, + Idle, + Break +}; + QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE @@ -31,25 +40,28 @@ public: private: Ui::MainWindow *ui; - QTimer* mTimer; + QTimer* mMainTimer; QTimer* mNotifyTimer; - QTimer* mShowNotifyTimer; QTimer* mUpdateUITimer; QTimer* mProgressTimer; QSystemTrayIcon* mTrayIcon; SettingsDialog* mSettingsDialog; + std::chrono::steady_clock::time_point mBreakStartTime; + + // How much seconds remains for main break + int mWorkInterval = -1; + app_settings::config mAppConfig; int mPostponeCount; // Time when idle was started std::optional mIdleStart; - // Time remaining in main timer - int mIdleRemaining; - int mLastIdleMilliseconds; + AppState mState = AppState::None; + void init(); void loadConfig(); void applyConfig(); @@ -63,6 +75,9 @@ private: QIcon getAppIcon(); QIcon getTrayIcon(); + // Function to switch state + void shiftTo(AppState state); + public slots: void onUpdateUI(); void onLongBreakNotify(); diff --git a/app/qbreak.pro b/app/qbreak.pro index 73d237f..24d8ef5 100644 --- a/app/qbreak.pro +++ b/app/qbreak.pro @@ -52,6 +52,8 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin unix:LIBS += -L/usr/X11R6/lib/ \ -lX11 -lXext -lXss -ldl +debug: DEFINES += DEBUG + # When using wayland: # unix:LIBS += -L/usr/local/lib \ # -lwayland-client-unstable++ -lwayland-client-extra++ -lwayland-client++ diff --git a/scripts/build_linux.sh b/scripts/build_linux.sh index 0980196..1babd81 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