Skip to content

Commit

Permalink
MIKU per project (#72)
Browse files Browse the repository at this point in the history
* A new MIKU for every project

* Separate project Idle events

* Updated changelog and bump version to v0.7.0

* Last minute cleanup
  • Loading branch information
Unthrottled authored Feb 21, 2021
1 parent 693dd4e commit feeadfc
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 58 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

# AMII Changelog

## [0.7.0]

### Changed

- The number of available MIKUs. Each project gets it's very own MIKU.
They function independently of each other and have their own moods.

### Fixed

- Idle personality when in `Minimal Mode`

## [0.6.0]

### Added
Expand Down
3 changes: 2 additions & 1 deletion docs/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@


### Changed
- How the AFK gifs are dismissed. They only get dismissed when the project it is on gains focus again. Not when any project gains focus.
- The number of available MIKUs. Each project gets it's very own MIKU.
They function independently of each other and have their own moods.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pluginGroup = io.unthrottled
pluginName_ = Anime Memes
pluginVersion = 0.6.0
pluginVersion = 0.7.0
pluginSinceBuild = 202.6397.94
pluginUntilBuild = 211.*
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/io/unthrottled/amii/actions/MemeOnDemand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.unthrottled.amii.actions
import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.DumbAware
import io.unthrottled.amii.events.EVENT_TOPIC
import io.unthrottled.amii.events.UserEvent
Expand All @@ -24,7 +23,7 @@ class MemeOnDemand : AnAction(), DumbAware, Logging, Disposable {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project!!
debouncer.debounce {
ApplicationManager.getApplication().messageBus
project.messageBus
.syncPublisher(EVENT_TOPIC)
.onDispatch(
UserEvent(
Expand Down
7 changes: 3 additions & 4 deletions src/main/kotlin/io/unthrottled/amii/actions/RelaxAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.unthrottled.amii.actions

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.DumbAware
import io.unthrottled.amii.core.personality.emotions.EMOTIONAL_MUTATION_TOPIC
import io.unthrottled.amii.core.personality.emotions.EmotionalMutationAction
Expand All @@ -11,9 +10,9 @@ import io.unthrottled.amii.core.personality.emotions.MoodCategory

class RelaxAction : AnAction(), DumbAware {
override fun actionPerformed(e: AnActionEvent) {
ApplicationManager.getApplication().messageBus
.syncPublisher(EMOTIONAL_MUTATION_TOPIC)
.onAction(
e.project?.messageBus
?.syncPublisher(EMOTIONAL_MUTATION_TOPIC)
?.onAction(
EmotionalMutationAction(
EmotionalMutationType.RESET,
MoodCategory.NEGATIVE,
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/io/unthrottled/amii/core/MIKU.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.unthrottled.amii.core

import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.Project
import io.unthrottled.amii.config.Config
import io.unthrottled.amii.config.ConfigListener
import io.unthrottled.amii.config.ConfigListener.Companion.CONFIG_TOPIC
Expand Down Expand Up @@ -30,7 +31,7 @@ import io.unthrottled.amii.tools.logger
import io.unthrottled.amii.tools.runSafely

// Meme Inference Knowledge Unit
class MIKU :
class MIKU(private val project: Project) :
UserEventListener,
EmotionalMutationActionListener,
MoodListener,
Expand All @@ -51,7 +52,7 @@ class MIKU :
private val taskPersonalityCore = TaskPersonalityCore()
private val onDemandPersonalityCore = OnDemandPersonalityCore()
private val alertPersonalityCore = AlertPersonalityCore()
private val idlePersonalityCore = IdlePersonalityCore()
private val idlePersonalityCore = IdlePersonalityCore(project)
private val greetingPersonalityCore = GreetingPersonalityCore()
private val resetCore = ResetCore()
private val singleEventDebouncer = AlarmDebouncer<UserEvent>(DEBOUNCE_INTERVAL)
Expand Down Expand Up @@ -136,7 +137,7 @@ class MIKU :
}

private fun publishMood(currentMood: Mood) {
ApplicationManager.getApplication().messageBus
project.messageBus
.syncPublisher(EMOTION_TOPIC)
.onDerivedMood(currentMood)
}
Expand Down
14 changes: 13 additions & 1 deletion src/main/kotlin/io/unthrottled/amii/core/ModalityProcessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.unthrottled.amii.core

import io.unthrottled.amii.config.Config
import io.unthrottled.amii.events.UserEvent
import io.unthrottled.amii.events.UserEvents

class ModalityProcessor(private val config: Config) {

Expand All @@ -15,13 +16,24 @@ class ModalityProcessor(private val config: Config) {

private fun shouldReact(userEvent: UserEvent): Boolean {
val otherUserEvent = lastSeenUserEvent
return if (config.minimalMode.not() || otherUserEvent == null) {
return if (
config.minimalMode.not() ||
isWhitelisted(userEvent) ||
otherUserEvent == null
) {
true
} else {
isDifferent(otherUserEvent, userEvent)
}
}

private val whiteListedEvents = setOf(
UserEvents.IDLE,
UserEvents.RETURN,
)
private fun isWhitelisted(userEvent: UserEvent) =
whiteListedEvents.contains(userEvent.type)

private fun isDifferent(
aUserEvent: UserEvent,
anotherUserEvent: UserEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.unthrottled.amii.core.personality

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.Project
import io.unthrottled.amii.assets.MemeAssetCategory
import io.unthrottled.amii.config.Config
import io.unthrottled.amii.core.personality.emotions.Mood
Expand All @@ -17,7 +17,7 @@ import io.unthrottled.amii.tools.PluginMessageBundle
import io.unthrottled.amii.tools.gt
import io.unthrottled.amii.tools.lt

class IdlePersonalityCore : PersonalityCore, Logging {
class IdlePersonalityCore(private val project: Project) : PersonalityCore, Logging {

companion object {
private const val MOOD_KEY = "mood"
Expand Down Expand Up @@ -68,14 +68,14 @@ class IdlePersonalityCore : PersonalityCore, Logging {
this.addListener(
object : MemeLifecycleListener {
override fun onDismiss() {
ApplicationManager.getApplication().messageBus
project.messageBus
.syncPublisher(EVENT_TOPIC)
.onDispatch(
UserEvent(
UserEvents.RETURN,
UserEventCategory.NEUTRAL,
PluginMessageBundle.message("user.event.idle.name"),
userEvent.project
project
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.unthrottled.amii.core.personality.emotions

import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.Project
import com.intellij.util.Alarm
import io.unthrottled.amii.core.personality.emotions.EmotionalMutationType.COOL_DOWN
import io.unthrottled.amii.core.personality.emotions.MoodCategory.NEGATIVE
Expand All @@ -11,7 +11,7 @@ internal enum class CoolDownStatus {
COOLING_DOWN, COOL, UNINITIALIZED
}

class CoolDownCore : MoodListener, Disposable {
class CoolDownCore(private val project: Project) : MoodListener, Disposable {
companion object {
private const val COOL_DOWN_DURATION_IN_MINUTES = 2L
}
Expand Down Expand Up @@ -42,7 +42,7 @@ class CoolDownCore : MoodListener, Disposable {
private fun registerCoolDownEvent() {
coolDownAlarm.addRequest(
{
ApplicationManager.getApplication().messageBus
project.messageBus
.syncPublisher(EMOTIONAL_MUTATION_TOPIC)
.onAction(EmotionalMutationAction(COOL_DOWN, NEGATIVE))
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ExitCodeListener(private val project: Project) : ExecutionListener, Dispos
env.project == project
) {
log.debug("Should do something with exit code: $exitCode")
ApplicationManager.getApplication().messageBus
project.messageBus
.syncPublisher(EVENT_TOPIC)
.onDispatch(
UserEvent(
Expand Down
54 changes: 37 additions & 17 deletions src/main/kotlin/io/unthrottled/amii/listeners/IdleEventListener.kt
Original file line number Diff line number Diff line change
@@ -1,62 +1,74 @@
package io.unthrottled.amii.listeners

import com.intellij.ide.IdeEventQueue
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
import com.intellij.util.Alarm
import com.intellij.util.ui.UIUtil
import io.unthrottled.amii.config.Config
import io.unthrottled.amii.config.ConfigListener
import io.unthrottled.amii.config.ConfigListener.Companion.CONFIG_TOPIC
import io.unthrottled.amii.events.EVENT_TOPIC
import io.unthrottled.amii.events.UserEvent
import io.unthrottled.amii.events.UserEventCategory
import io.unthrottled.amii.events.UserEvents
import io.unthrottled.amii.tools.BalloonTools
import io.unthrottled.amii.tools.PluginMessageBundle
import io.unthrottled.amii.tools.runSafely
import java.awt.AWTEvent
import java.awt.Toolkit
import java.awt.event.AWTEventListener
import java.awt.event.InputEvent
import java.util.concurrent.TimeUnit

class IdleEventListener(private val project: Project) : Runnable, Disposable {
class IdleEventListener(private val project: Project) : Runnable, Disposable, AWTEventListener {
private val messageBus = ApplicationManager.getApplication().messageBus.connect()
private val log = Logger.getInstance(this::class.java)
private val rootPane = BalloonTools.getIDEFrame(project).component
private var idleTimeout =
TimeUnit.MILLISECONDS.convert(
getCurrentTimoutInMinutes(),
TimeUnit.MINUTES
).toInt()
private val idleAlarm = Alarm()

init {
val self = this
messageBus.subscribe(
CONFIG_TOPIC,
ConfigListener { newPluginState ->
IdeEventQueue.getInstance().removeIdleListener(self)
IdeEventQueue.getInstance().addIdleListener(
self,
TimeUnit.MILLISECONDS.convert(
newPluginState.idleTimeoutInMinutes,
TimeUnit.MINUTES
).toInt()
)
idleAlarm.cancelAllRequests()
self.idleTimeout = TimeUnit.MILLISECONDS.convert(
newPluginState.idleTimeoutInMinutes,
TimeUnit.MINUTES
).toInt()
idleAlarm.addRequest(self, self.idleTimeout)
}
)
IdeEventQueue.getInstance().addIdleListener(
Toolkit.getDefaultToolkit().addAWTEventListener(
this,
TimeUnit.MILLISECONDS.convert(
getCurrentTimoutInMinutes(),
TimeUnit.MINUTES
).toInt()
AWTEvent.MOUSE_EVENT_MASK or
AWTEvent.MOUSE_MOTION_EVENT_MASK or
AWTEvent.KEY_EVENT_MASK
)
idleAlarm.addRequest(this, idleTimeout)
}

private fun getCurrentTimoutInMinutes(): Long =
Config.instance.idleTimeoutInMinutes

override fun dispose() {
messageBus.dispose()
idleAlarm.dispose()
runSafely({
IdeEventQueue.getInstance().removeIdleListener(this)
Toolkit.getDefaultToolkit().removeAWTEventListener(this)
}) {}
}

override fun run() {
log.debug("Observed idled timeout")
ApplicationManager.getApplication().messageBus
project.messageBus
.syncPublisher(EVENT_TOPIC)
.onDispatch(
UserEvent(
Expand All @@ -66,5 +78,13 @@ class IdleEventListener(private val project: Project) : Runnable, Disposable {
project
)
)
idleAlarm.addRequest(this, idleTimeout)
}

override fun eventDispatched(e: AWTEvent) {
if (e !is InputEvent || !UIUtil.isDescendingFrom(e.component, rootPane)) return

idleAlarm.cancelAllRequests()
idleAlarm.addRequest(this, idleTimeout)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import java.util.concurrent.TimeUnit

class SilenceListener(private val project: Project) : Runnable, UserEventListener, Disposable {
private val messageBus = ApplicationManager.getApplication().messageBus.connect()
private val projectMessageBus = project.messageBus.connect()
private val log = Logger.getInstance(this::class.java)
private val silenceAlarm = Alarm()

init {
val self = this
messageBus.subscribe(EVENT_TOPIC, this)
projectMessageBus.subscribe(EVENT_TOPIC, this)
messageBus.subscribe(
ConfigListener.CONFIG_TOPIC,
ConfigListener { newPluginState ->
Expand Down Expand Up @@ -54,12 +55,13 @@ class SilenceListener(private val project: Project) : Runnable, UserEventListene

override fun dispose() {
messageBus.dispose()
projectMessageBus.dispose()
silenceAlarm.dispose()
}

override fun run() {
log.debug("Observed silence timeout")
ApplicationManager.getApplication().messageBus
project.messageBus
.syncPublisher(EVENT_TOPIC)
.onDispatch(
UserEvent(
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/io/unthrottled/amii/listeners/TaskListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TaskListener(private val project: Project) :

private var previousTaskStatus = TaskStatus.UNKNOWN

private val messageBusConnection = ApplicationManager.getApplication().messageBus.connect()
private val messageBusConnection = project.messageBus.connect()

init {
ApplicationManager.getApplication().invokeLater {
Expand All @@ -36,7 +36,7 @@ class TaskListener(private val project: Project) :
override fun finished(result: ProjectTaskManager.Result) {
when {
result.hasErrors() -> {
ApplicationManager.getApplication().messageBus
project.messageBus
.syncPublisher(EVENT_TOPIC)
.onDispatch(
UserEvent(
Expand All @@ -48,7 +48,7 @@ class TaskListener(private val project: Project) :
)
}
previousTaskStatus == TaskStatus.FAIL -> {
ApplicationManager.getApplication().messageBus
project.messageBus
.syncPublisher(EVENT_TOPIC)
.onDispatch(
UserEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.unthrottled.amii.listeners
import com.intellij.execution.testframework.sm.runner.SMTRunnerEventsAdapter
import com.intellij.execution.testframework.sm.runner.SMTestProxy.SMRootTestProxy
import com.intellij.execution.testframework.sm.runner.states.TestStateInfo
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.Project
import io.unthrottled.amii.events.EVENT_TOPIC
import io.unthrottled.amii.events.UserEvent
Expand All @@ -30,7 +29,7 @@ class TestEventListener(private val project: Project) : SMTRunnerEventsAdapter()
PluginMessageBundle.message("user.event.test.fail.name") to UserEventCategory.NEGATIVE
}

ApplicationManager.getApplication().messageBus
project.messageBus
.syncPublisher(EVENT_TOPIC)
.onDispatch(
UserEvent(
Expand Down
Loading

0 comments on commit feeadfc

Please sign in to comment.