- version 0.1.8 - new state machine + fix problems with desktop file.

This commit is contained in:
Dmytro Bogovych 2022-09-20 11:19:03 +03:00
parent f1ca3ed0ed
commit fff67bbedb
7 changed files with 51 additions and 10 deletions

View File

@ -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);
}

View File

@ -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<char>(ifs)), std::istreambuf_iterator<char>());
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()

View File

@ -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)

View File

@ -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;

View File

@ -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<std::chrono::steady_clock::time_point> 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();

View File

@ -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++

View File

@ -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