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
Original file line number Diff line number Diff line change
@@ -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<DevFocusSettingsState.SettingsState> {

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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,6 +33,14 @@ class PomodoroToolWindowPanel(private val project: Project) : JBPanel<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
Expand Down Expand Up @@ -94,6 +104,7 @@ class PomodoroToolWindowPanel(private val project: Project) : JBPanel<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
Expand Down Expand Up @@ -158,6 +169,10 @@ class PomodoroToolWindowPanel(private val project: Project) : JBPanel<JBPanel<*>
}
updateSettingsPanelVisibility()
}

settingsButton.addActionListener {
PomodoroSettingsDialog(project).show()
}
}

private fun updateSettingsPanelVisibility() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand Down
Loading