diff --git a/src/main/kotlin/com/github/akshayashokcode/devfocus/services/settings/DevFocusSettingsState.kt b/src/main/kotlin/com/github/akshayashokcode/devfocus/services/settings/DevFocusSettingsState.kt new file mode 100644 index 0000000..3470bfa --- /dev/null +++ b/src/main/kotlin/com/github/akshayashokcode/devfocus/services/settings/DevFocusSettingsState.kt @@ -0,0 +1,33 @@ +package com.github.akshayashokcode.devfocus.services.settings + +import com.intellij.openapi.components.PersistentStateComponent +import com.intellij.openapi.components.Service +import com.intellij.openapi.components.State +import com.intellij.openapi.components.Storage + +@Service(Service.Level.APP) +@State( + name = "DevFocusSettings", + storages = [Storage("DevFocusSettings.xml")] +) +class DevFocusSettingsState : + PersistentStateComponent { + + data class SettingsState( + var soundEnabled: Boolean = true + ) + + private var state = SettingsState() + + override fun getState(): SettingsState = state + + override fun loadState(state: SettingsState) { + this.state = state + } + + var soundEnabled: Boolean + get() = state.soundEnabled + set(value) { + state.soundEnabled = value + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/akshayashokcode/devfocus/toolWindow/PomodoroToolWindowPanel.kt b/src/main/kotlin/com/github/akshayashokcode/devfocus/toolWindow/PomodoroToolWindowPanel.kt index e0e8db7..99dffdf 100644 --- a/src/main/kotlin/com/github/akshayashokcode/devfocus/toolWindow/PomodoroToolWindowPanel.kt +++ b/src/main/kotlin/com/github/akshayashokcode/devfocus/toolWindow/PomodoroToolWindowPanel.kt @@ -5,7 +5,9 @@ import com.github.akshayashokcode.devfocus.model.PomodoroSettings import com.github.akshayashokcode.devfocus.services.pomodoro.PomodoroTimerService import com.github.akshayashokcode.devfocus.ui.components.CircularTimerPanel import com.github.akshayashokcode.devfocus.ui.components.SessionIndicatorPanel +import com.github.akshayashokcode.devfocus.ui.settings.PomodoroSettingsDialog import com.github.akshayashokcode.devfocus.ui.settings.PomodoroSettingsPanel +import com.intellij.icons.AllIcons import com.intellij.openapi.Disposable import com.intellij.openapi.project.Project import com.intellij.ui.components.JBPanel @@ -31,6 +33,14 @@ class PomodoroToolWindowPanel(private val project: Project) : JBPanel selectedItem = PomodoroMode.CLASSIC } + // Setting button + private val settingsButton = JButton(AllIcons.General.GearPlain).apply { + toolTipText = "Settings" + isBorderPainted = false + isContentAreaFilled = false + isFocusPainted = false + } + // Info label showing current mode settings private val infoLabel = JLabel("📊 25 min work • 5 min break").apply { horizontalAlignment = SwingConstants.CENTER @@ -94,6 +104,7 @@ class PomodoroToolWindowPanel(private val project: Project) : JBPanel val topPanel = JPanel(BorderLayout(5, 5)).apply { border = BorderFactory.createEmptyBorder(10, 10, 5, 10) add(modeComboBox, BorderLayout.CENTER) + add(settingsButton, BorderLayout.EAST) } // Info panel @@ -158,6 +169,10 @@ class PomodoroToolWindowPanel(private val project: Project) : JBPanel } updateSettingsPanelVisibility() } + + settingsButton.addActionListener { + PomodoroSettingsDialog(project).show() + } } private fun updateSettingsPanelVisibility() { diff --git a/src/main/kotlin/com/github/akshayashokcode/devfocus/ui/settings/PomodoroSettingsDialog.kt b/src/main/kotlin/com/github/akshayashokcode/devfocus/ui/settings/PomodoroSettingsDialog.kt new file mode 100644 index 0000000..9988eb0 --- /dev/null +++ b/src/main/kotlin/com/github/akshayashokcode/devfocus/ui/settings/PomodoroSettingsDialog.kt @@ -0,0 +1,47 @@ +package com.github.akshayashokcode.devfocus.ui.settings + +import com.github.akshayashokcode.devfocus.services.settings.DevFocusSettingsState +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.project.Project +import com.intellij.openapi.ui.DialogWrapper +import java.awt.BorderLayout +import javax.swing.BorderFactory +import javax.swing.JCheckBox +import javax.swing.JComponent +import javax.swing.JPanel + +class PomodoroSettingsDialog( + project: Project +) : DialogWrapper(project) { + + private val settings = + ApplicationManager.getApplication() + .getService(DevFocusSettingsState::class.java) + + private val soundCheckbox = + JCheckBox( + "Notification sound", + settings.soundEnabled + ) + + init { + title = "DevFocus Settings" + init() + } + + override fun createCenterPanel(): JComponent { + + return JPanel(BorderLayout()).apply { + border = BorderFactory.createEmptyBorder(16, 16, 16, 16) + + add(soundCheckbox, BorderLayout.NORTH) + } + } + + override fun doOKAction() { + + settings.soundEnabled = soundCheckbox.isSelected + + super.doOKAction() + } +} \ 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 index 5bfde8f..41957da 100644 --- a/src/main/kotlin/com/github/akshayashokcode/devfocus/util/SoundPlayer.kt +++ b/src/main/kotlin/com/github/akshayashokcode/devfocus/util/SoundPlayer.kt @@ -1,5 +1,7 @@ package com.github.akshayashokcode.devfocus.util +import com.github.akshayashokcode.devfocus.services.settings.DevFocusSettingsState +import com.intellij.openapi.application.ApplicationManager import java.io.BufferedInputStream import javax.sound.sampled.AudioSystem import javax.sound.sampled.Clip @@ -11,6 +13,12 @@ object SoundPlayer { fun play(soundFileName: String) { try { + val settings = ApplicationManager.getApplication() + .getService(DevFocusSettingsState::class.java) + + if (!settings.soundEnabled) { + return + } val resourceStream = SoundPlayer::class.java .getResourceAsStream("/sounds/$soundFileName")