Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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()
Expand All @@ -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(
Expand Down Expand Up @@ -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")
}
}
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
Binary file added src/main/resources/sounds/break.wav
Binary file not shown.
Binary file added src/main/resources/sounds/complete.wav
Binary file not shown.
Binary file added src/main/resources/sounds/work.wav
Binary file not shown.
Loading