Skip to content

Commit

Permalink
feat: waifu log watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
zaerald committed Oct 31, 2020
1 parent ad13b4b commit b5eaba6
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ data class AlertConfiguration(
val isDisplayNotificationEnabled: Boolean = false,
val isSoundAlertEnabled: Boolean = false
)

object AlertConfigurationAllEnabled {
fun create() = AlertConfiguration(
isAlertEnabled = true,
isDisplayNotificationEnabled = true,
isSoundAlertEnabled = true
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package zd.zero.waifu.motivator.plugin.integrations

import com.intellij.execution.filters.ConsoleFilterProvider
import com.intellij.execution.filters.Filter
import com.intellij.openapi.project.Project
import zd.zero.waifu.motivator.plugin.alert.AlertConfigurationAllEnabled
import zd.zero.waifu.motivator.plugin.assets.WaifuAssetCategory
import zd.zero.waifu.motivator.plugin.motivation.MotivationFactory
import zd.zero.waifu.motivator.plugin.motivation.event.MotivationEvent
import zd.zero.waifu.motivator.plugin.motivation.event.MotivationEventCategory
import zd.zero.waifu.motivator.plugin.motivation.event.MotivationEvents
import zd.zero.waifu.motivator.plugin.settings.WaifuMotivatorPluginState.getPluginState

class WaifuConsoleFilterProvider : ConsoleFilterProvider {

private var prevLength: Int = Int.MAX_VALUE

private var alertShown = false

override fun getDefaultFilters(project: Project): Array<Filter> = when {
getPluginState().isLogWatcherEnabled -> arrayOf(
Filter { line, entireLength ->
val newConsole = entireLength < prevLength
if (newConsole) alertShown = false

val pluginState = getPluginState()
if (alertShown.not() && pluginState.logWatcherKeyword.isNotEmpty() &&
line.contains(pluginState.logWatcherKeyword, ignoreCase = pluginState.isLogWatcherCaseSensitivityIgnored)
) {
MotivationFactory.showUntitledMotivationEventFromCategories(
MotivationEvent(
MotivationEvents.MISC,
MotivationEventCategory.POSITIVE,
"Waifu Log Watcher Event",
project
) { AlertConfigurationAllEnabled.create() },
WaifuAssetCategory.ACKNOWLEDGEMENT,
WaifuAssetCategory.CELEBRATION,
WaifuAssetCategory.HAPPY,
WaifuAssetCategory.SMUG
)

alertShown = true
}

prevLength = entireLength
return@Filter null
}
)
else -> Filter.EMPTY_ARRAY
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,68 @@
</component>
</children>
</grid>
<grid id="21b3" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title-resource-bundle="messages/MessageBundle" title-key="settings.tab.log.watcher"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<hspacer id="1fa9d">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="72028" class="javax.swing.JCheckBox" binding="ignoreCaseSensitivityCheckBox" default-binding="true">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
<text resource-bundle="messages/MessageBundle" key="settings.log.watcher.ignore.case.sensitivity"/>
</properties>
</component>
<vspacer id="7c2ee">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="2" hsize-policy="1" anchor="1" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="11" height="5"/>
</grid>
</constraints>
</vspacer>
<vspacer id="6ee99">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="be9fd" class="javax.swing.JTextField" binding="logWatcherKeywordTextField">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="1" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<enabled value="true"/>
</properties>
</component>
<component id="c1e09" class="javax.swing.JCheckBox" binding="enableLogWatcherCheckBox">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/MessageBundle" key="settings.log.watcher.watch.logs"/>
</properties>
</component>
<component id="1558" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="1" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/MessageBundle" key="settings.log.watcher.header"/>
</properties>
</component>
</children>
</grid>
<grid id="5245b" layout-manager="GridLayoutManager" row-count="8" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.SpinnerNumberModel;
Expand Down Expand Up @@ -92,6 +93,12 @@ public class WaifuMotivatorSettingsPage implements SearchableConfigurable, Confi

private JCheckBox showStatusBarIcon;

private JCheckBox ignoreCaseSensitivityCheckBox;

private JTextField logWatcherKeywordTextField;

private JCheckBox enableLogWatcherCheckBox;

private ListTableModel<Integer> exitCodeListModel;

public WaifuMotivatorSettingsPage() {
Expand Down Expand Up @@ -120,6 +127,11 @@ public JComponent createComponent() {
eventsBeforeFrustrationSpinner.setEnabled(allowFrustrationCheckBox.isSelected());
} );

enableLogWatcherCheckBox.addActionListener( e -> {
ignoreCaseSensitivityCheckBox.setEnabled( enableLogWatcherCheckBox.isSelected() );
logWatcherKeywordTextField.setEnabled( enableLogWatcherCheckBox.isSelected() );
} );

frustrationProbabilitySlider.setForeground( UIUtil.getContextHelpForeground() );

preferredCharactersList.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
Expand Down Expand Up @@ -153,6 +165,9 @@ public boolean isModified() {
enableSayonara.isSelected() != this.state.isSayonaraEnabled() ||
!getPreferredCharacters().equals( this.state.getPreferredCharacters() ) ||
showStatusBarIcon.isSelected() != this.state.isShowMood() ||
enableLogWatcherCheckBox.isSelected() != this.state.isLogWatcherEnabled() ||
ignoreCaseSensitivityCheckBox.isSelected() != this.state.isLogWatcherCaseSensitivityIgnored() ||
!logWatcherKeywordTextField.getText().equals( this.state.getLogWatcherKeyword()) ||
exitCodesChanged;
}

Expand Down Expand Up @@ -202,6 +217,9 @@ public void apply() {
);
this.state.setPreferredCharacters( getPreferredCharacters() );
this.state.setShowMood( showStatusBarIcon.isSelected() );
this.state.setLogWatcherEnabled( enableLogWatcherCheckBox.isSelected() );
this.state.setLogWatcherCaseSensitivityIgnored( ignoreCaseSensitivityCheckBox.isSelected() );
this.state.setLogWatcherKeyword( logWatcherKeywordTextField.getText() );

// updates the Tip of the Day setting
GeneralSettings.getInstance().setShowTipsOnStartup( !enableWaifuOfTheDay.isSelected() );
Expand Down Expand Up @@ -238,12 +256,22 @@ private void setFieldsFromState() {
this.enableIdleSoundCheckBox.setSelected( this.state.isIdleSoundEnabled() );
this.enableTaskEventNotificationsCheckBox.setSelected( this.state.isTaskMotivationEnabled() );
this.enableTaskEventSoundsCheckBox.setSelected( this.state.isTaskSoundEnabled() );
this.allowFrustrationCheckBox.setSelected( this.state.isAllowFrustration() );
this.eventsBeforeFrustrationSpinner.setValue( this.state.getEventsBeforeFrustration() );
this.frustrationProbabilitySlider.setValue( this.state.getProbabilityOfFrustration() );
this.enableExitCodeNotifications.setSelected( this.state.isExitCodeNotificationEnabled() );
this.enableExitCodeSound.setSelected( this.state.isExitCodeSoundEnabled() );
this.showStatusBarIcon.setSelected( this.state.isShowMood() );

this.allowFrustrationCheckBox.setSelected( this.state.isAllowFrustration() );
this.eventsBeforeFrustrationSpinner.setValue( this.state.getEventsBeforeFrustration() );
this.eventsBeforeFrustrationSpinner.setEnabled( allowFrustrationCheckBox.isSelected() );
this.frustrationProbabilitySlider.setValue( this.state.getProbabilityOfFrustration() );
this.frustrationProbabilitySlider.setEnabled( allowFrustrationCheckBox.isSelected() );

this.enableLogWatcherCheckBox.setSelected( this.state.isLogWatcherEnabled() );
this.ignoreCaseSensitivityCheckBox.setSelected( this.state.isLogWatcherCaseSensitivityIgnored() );
this.ignoreCaseSensitivityCheckBox.setEnabled( enableLogWatcherCheckBox.isSelected() );
this.logWatcherKeywordTextField.setText( this.state.getLogWatcherKeyword() );
this.logWatcherKeywordTextField.setEnabled( enableLogWatcherCheckBox.isSelected() );

initializeExitCodes();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ class WaifuMotivatorState {
var preferredCharacters = ""

var isShowMood = true

var isLogWatcherEnabled = false

var isLogWatcherCaseSensitivityIgnored = true

var logWatcherKeyword = ""
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
serviceImplementation="zd.zero.waifu.motivator.plugin.settings.WaifuMotivatorPluginState"/>
<applicationService serviceImplementation="zd.zero.waifu.motivator.plugin.service.ApplicationService"/>
<applicationService serviceImplementation="zd.zero.waifu.motivator.plugin.service.WaifuGatekeeper"/>
<consoleFilterProvider implementation="zd.zero.waifu.motivator.plugin.integrations.WaifuConsoleFilterProvider"/>
<errorHandler
id="7111f9b9-f252-483e-9496-72d649347b6d"
implementation="zd.zero.waifu.motivator.plugin.integrations.ErrorReporter"/>
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/messages/MessageBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ settings.sound.on.motivate.me.tooltip=Plays a sound whenever 'Motivate Me' actio
### Preferences
settings.preferences.preferred.character.label=Preferred Characters

## Log Watcher
settings.tab.log.watcher=Log Watcher
settings.log.watcher.watch.logs=Watch Logs
settings.log.watcher.ignore.case.sensitivity=Ignore case sensitivity
settings.log.watcher.header=I'll watch the logs for you senpai!

## Personality
settings.tab.personality=Personality
Expand Down

0 comments on commit b5eaba6

Please # to comment.