diff --git a/gradle.properties b/gradle.properties index 6d1b2bf..8ab9826 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,11 +4,11 @@ pluginGroup = com.github.akshayashokcode.devfocus pluginName = DevFocus pluginRepositoryUrl = https://github.com/AkshayAshokCode/DevFocus # SemVer format -> https://semver.org -pluginVersion = 1.2.2 +pluginVersion = 1.2.3 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild = 233 -# pluginUntilBuild = 251.* +pluginUntilBuild = 251.* # IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension platformType = IC diff --git a/src/main/kotlin/com/github/akshayashokcode/devfocus/services/pomodoro/PomodoroTimerService.kt b/src/main/kotlin/com/github/akshayashokcode/devfocus/services/pomodoro/PomodoroTimerService.kt index 47fb800..58f8220 100644 --- a/src/main/kotlin/com/github/akshayashokcode/devfocus/services/pomodoro/PomodoroTimerService.kt +++ b/src/main/kotlin/com/github/akshayashokcode/devfocus/services/pomodoro/PomodoroTimerService.kt @@ -2,6 +2,7 @@ package com.github.akshayashokcode.devfocus.services.pomodoro import com.github.akshayashokcode.devfocus.model.PomodoroMode import com.github.akshayashokcode.devfocus.model.PomodoroSettings +import com.github.akshayashokcode.devfocus.util.SoundPlayer import com.intellij.notification.NotificationGroupManager import com.intellij.notification.NotificationType import com.intellij.openapi.components.Service @@ -77,6 +78,7 @@ class PomodoroTimerService(private val project: Project) { // Work session complete if (currentSessionNum >= totalSessions) { // Last session complete - all done! + playCompleteSound() NotificationGroupManager.getInstance() .getNotificationGroup(NOTIFICATION_GROUP_ID) .createNotification( @@ -94,6 +96,7 @@ class PomodoroTimerService(private val project: Project) { _timeLeft.value = formatTime(remainingTimeMs) } else { // Work session complete - start break + playBreakSound() _currentSession.value = currentSessionNum + 1 NotificationGroupManager.getInstance() @@ -116,6 +119,7 @@ class PomodoroTimerService(private val project: Project) { } else { // Break complete // More sessions remaining - start next session + playWorkSound() NotificationGroupManager.getInstance() .getNotificationGroup(NOTIFICATION_GROUP_ID) .createNotification( @@ -193,4 +197,16 @@ class PomodoroTimerService(private val project: Project) { } return if (totalMs > 0) remainingTimeMs.toFloat() / totalMs.toFloat() else 0f } + + private fun playBreakSound() { + SoundPlayer.play("break.wav") + } + + private fun playWorkSound() { + SoundPlayer.play("work.wav") + } + + private fun playCompleteSound() { + SoundPlayer.play("complete.wav") + } } \ No newline at end of file diff --git a/src/main/kotlin/com/github/akshayashokcode/devfocus/util/SoundPlayer.kt b/src/main/kotlin/com/github/akshayashokcode/devfocus/util/SoundPlayer.kt new file mode 100644 index 0000000..5bfde8f --- /dev/null +++ b/src/main/kotlin/com/github/akshayashokcode/devfocus/util/SoundPlayer.kt @@ -0,0 +1,48 @@ +package com.github.akshayashokcode.devfocus.util + +import java.io.BufferedInputStream +import javax.sound.sampled.AudioSystem +import javax.sound.sampled.Clip +import javax.sound.sampled.LineEvent + +object SoundPlayer { + + @Synchronized + fun play(soundFileName: String) { + + try { + + val resourceStream = SoundPlayer::class.java + .getResourceAsStream("/sounds/$soundFileName") + ?: return + + val bufferedStream = BufferedInputStream(resourceStream) + + val audioInputStream = + AudioSystem.getAudioInputStream(bufferedStream) + + val clip: Clip = AudioSystem.getClip() + + clip.open(audioInputStream) + + clip.addLineListener { event -> + + if (event.type == LineEvent.Type.STOP) { + + clip.stop() + clip.flush() + clip.close() + + audioInputStream.close() + bufferedStream.close() + resourceStream.close() + } + } + + clip.start() + + } catch (e: Exception) { + e.printStackTrace() + } + } +} \ No newline at end of file diff --git a/src/main/resources/sounds/break.wav b/src/main/resources/sounds/break.wav new file mode 100644 index 0000000..c513cd8 Binary files /dev/null and b/src/main/resources/sounds/break.wav differ diff --git a/src/main/resources/sounds/complete.wav b/src/main/resources/sounds/complete.wav new file mode 100644 index 0000000..31c6a87 Binary files /dev/null and b/src/main/resources/sounds/complete.wav differ diff --git a/src/main/resources/sounds/work.wav b/src/main/resources/sounds/work.wav new file mode 100644 index 0000000..29095d5 Binary files /dev/null and b/src/main/resources/sounds/work.wav differ