diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8873a20..5ea4d31 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,6 +5,8 @@ name: Build app on: push: + branches: + - '*' tags: - '*' @@ -26,7 +28,7 @@ jobs: runs-on: ${{matrix.os}} steps: - uses: actions/checkout@v4 - - uses: AllanChain/install-qt-static@v6.8 + - uses: AllanChain/install-qt-static-custom@v6.8 - uses: ilammy/msvc-dev-cmd@v1 if: contains(matrix.os, 'windows') @@ -70,6 +72,7 @@ jobs: release: runs-on: ubuntu-latest needs: build + if: startsWith(github.ref, 'refs/tags/') steps: - uses: actions/checkout@v4 with: diff --git a/CMakeLists.txt b/CMakeLists.txt index ce16afe..268ba7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,8 @@ endif() include(GNUInstallDirs) -find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets) -find_package(Qt6 REQUIRED COMPONENTS Widgets) +find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets Multimedia) +find_package(Qt6 REQUIRED COMPONENTS Widgets Multimedia) file(GLOB PROJECT_SOURCES "src/*.cpp" "src/*.h" "resources/index.qrc") @@ -41,7 +41,7 @@ qt_add_executable(sane-break ) target_include_directories(sane-break PRIVATE "src" ${CMAKE_CURRENT_BINARY_DIR}) -target_link_libraries(sane-break PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) +target_link_libraries(sane-break PRIVATE Qt6::Widgets Qt6::Multimedia) if(CMAKE_SYSTEM_NAME STREQUAL "Linux") file(GLOB PROJECT_SOURCES_LINUX "src/linux/*") diff --git a/resources/index.qrc b/resources/index.qrc index 984697b..b40f4d5 100644 --- a/resources/index.qrc +++ b/resources/index.qrc @@ -3,6 +3,8 @@ images/icon_tray.png images/icon_tray-pause.png images/icon-256.png + sounds/bell.mp3 + sounds/wood.mp3 style.css NOTICE.md diff --git a/resources/sounds/.gitignore b/resources/sounds/.gitignore new file mode 100644 index 0000000..751553b --- /dev/null +++ b/resources/sounds/.gitignore @@ -0,0 +1 @@ +*.bak diff --git a/resources/sounds/bell.mmp b/resources/sounds/bell.mmp new file mode 100644 index 0000000..6372704 --- /dev/null +++ b/resources/sounds/bell.mmp @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +


]]>
+ + +
+
diff --git a/resources/sounds/bell.mp3 b/resources/sounds/bell.mp3 new file mode 100644 index 0000000..24afcf2 Binary files /dev/null and b/resources/sounds/bell.mp3 differ diff --git a/resources/sounds/wood.mmp b/resources/sounds/wood.mmp new file mode 100644 index 0000000..5768215 --- /dev/null +++ b/resources/sounds/wood.mmp @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +


]]>
+ + +
+
diff --git a/resources/sounds/wood.mp3 b/resources/sounds/wood.mp3 new file mode 100644 index 0000000..88931d4 Binary files /dev/null and b/resources/sounds/wood.mp3 differ diff --git a/src/pref-window.cpp b/src/pref-window.cpp index 510ed0e..d6e8eca 100644 --- a/src/pref-window.cpp +++ b/src/pref-window.cpp @@ -221,6 +221,17 @@ PreferenceWindow::PreferenceWindow(QWidget *parent) : QMainWindow(parent) { flashForLabel->setText(QString("%1 sec").arg(value)); }); + QLabel *bellLabel = new QLabel("Sound Effect after break"); + QHBoxLayout *bellLayout = new QHBoxLayout(); + bellLayout->addWidget(bellLabel); + bellSoundSelect = new QComboBox(); + bellSoundSelect->setEditable(true); + bellSoundSelect->addItem(""); + bellSoundSelect->addItem("qrc:/sounds/wood.mp3"); + bellSoundSelect->addItem("qrc:/sounds/bell.mp3"); + bellLayout->addWidget(bellSoundSelect); + layout->addLayout(bellLayout); + layout->addWidget(new QLabel("

Pausing

")); QGridLayout *pauseForm = new QGridLayout(); @@ -265,6 +276,7 @@ void PreferenceWindow::loadSettings() { flashForSlider->setValue(SanePreferences::flashFor->get()); pauseOnIdleSlider->setValue(SanePreferences::pauseOnIdleFor->get() / 60); pauseOnBatteryCheck->setChecked(SanePreferences::pauseOnBattery->get()); + bellSoundSelect->setEditText(SanePreferences::bellSound->get()); } void PreferenceWindow::saveSettings() { @@ -275,6 +287,7 @@ void PreferenceWindow::saveSettings() { SanePreferences::flashFor->set(flashForSlider->value()); SanePreferences::pauseOnIdleFor->set(pauseOnIdleSlider->value() * 60); SanePreferences::pauseOnBattery->set(pauseOnBatteryCheck->isChecked()); + SanePreferences::bellSound->set(bellSoundSelect->currentText()); } void PreferenceWindow::closeEvent(QCloseEvent *event) { diff --git a/src/pref-window.h b/src/pref-window.h index 7a3b47a..cdcde2f 100644 --- a/src/pref-window.h +++ b/src/pref-window.h @@ -6,6 +6,7 @@ #define SANE_PREFERENCES_WINDOW_H #include +#include #include #include #include @@ -42,5 +43,6 @@ class PreferenceWindow : public QMainWindow { SteppedSlider *flashForSlider; SteppedSlider *pauseOnIdleSlider; QCheckBox *pauseOnBatteryCheck; + QComboBox *bellSoundSelect; }; #endif // SANE_PREFERENCES_WINDOW_H diff --git a/src/preferences.cpp b/src/preferences.cpp index fbf5af0..955eb82 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -15,3 +15,4 @@ Setting* SanePreferences::pauseOnIdleFor = new Setting("pause/on-idle-for", 180); Setting* SanePreferences::pauseOnBattery = new Setting("pause/on-battery", false); +Setting* SanePreferences::bellSound = new Setting("bell/sound", ""); diff --git a/src/preferences.h b/src/preferences.h index b003bee..9fe851b 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -62,6 +62,7 @@ class SanePreferences : public QObject { static Setting *flashFor; static Setting *pauseOnIdleFor; static Setting *pauseOnBattery; + static Setting *bellSound; }; #endif // SANE_PREFERENCES_H diff --git a/src/window-manager.cpp b/src/window-manager.cpp index 0e4af13..4969a7e 100644 --- a/src/window-manager.cpp +++ b/src/window-manager.cpp @@ -18,7 +18,9 @@ #include "macos/workspace.h" #endif #include +#include #include +#include #include #include #include @@ -40,6 +42,14 @@ BreakWindowManager::BreakWindowManager() : QObject() { connect(idleTimer, &SystemIdleTime::idleStart, this, &BreakWindowManager::onIdleStart); connect(idleTimer, &SystemIdleTime::idleEnd, this, &BreakWindowManager::onIdleEnd); + + soundPlayer = new QMediaPlayer(this); + audioOutput = new QAudioOutput(); + soundPlayer->setAudioOutput(audioOutput); + audioOutput->setVolume(100); + setSound(); + connect(SanePreferences::bellSound, &SettingWithSignal::changed, this, + &BreakWindowManager::setSound); #ifdef LayerShellQt_FOUND if (QGuiApplication::platformName() == "wayland") LayerShellQt::Shell::useLayerShell(); @@ -111,7 +121,10 @@ void BreakWindowManager::tick() { remainingTime--; for (auto w : std::as_const(windows)) w->setTime(remainingTime); } - if (remainingTime <= 0) return close(); + if (remainingTime <= 0) { + soundPlayer->play(); + close(); + } } void BreakWindowManager::forceBreak() { @@ -119,6 +132,10 @@ void BreakWindowManager::forceBreak() { for (auto w : std::as_const(windows)) w->setFullScreen(); } +void BreakWindowManager::setSound() { + soundPlayer->setSource(QUrl(SanePreferences::bellSound->get())); +} + void BreakWindowManager::onIdleStart() { if (isForceBreak || remainingTime <= 0) return; for (auto w : std::as_const(windows)) { diff --git a/src/window-manager.h b/src/window-manager.h index 7d7b1e9..4382d02 100644 --- a/src/window-manager.h +++ b/src/window-manager.h @@ -5,7 +5,9 @@ #ifndef SANE_BREAK_WINDOW_MANAGER_H #define SANE_BREAK_WINDOW_MANAGER_H +#include #include +#include #include #include "break-window.h" @@ -32,10 +34,13 @@ class BreakWindowManager : public QObject { QList windows; QTimer *countdownTimer; QTimer *forceBreakTimer; + QMediaPlayer *soundPlayer; + QAudioOutput *audioOutput; SystemIdleTime *idleTimer; void createWindows(BreakType type); void tick(); void forceBreak(); + void setSound(); void onIdleStart(); void onIdleEnd(); };