Skip to content

Commit

Permalink
change access to GUI, correct closing icon when closing app, change t…
Browse files Browse the repository at this point in the history
…he trigger for changing app state.
  • Loading branch information
NicolasConstant committed Nov 11, 2015
1 parent a832003 commit b0f20e3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
6 changes: 6 additions & 0 deletions SpotifySleepModeStopper/Domain/SpotifySaveModeStopper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@ private void AnalyseSpotifyStatus()
if (stateHasChanged)
{
if (_spotifyRunning && _spotifyPlaying)
{
_messageDisplayer.OutputMessage("SleepModeEnabled");
_preventSleepScreen.EnableConstantDisplayAndPower(true);
}
else
{
_messageDisplayer.OutputMessage("SleepModeDisabled");
_preventSleepScreen.EnableConstantDisplayAndPower(false);
}
}
}
catch (Exception e)
Expand Down
4 changes: 2 additions & 2 deletions SpotifySleepModeStopperGui/IconChanger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public IconChanger(Action notifyIsPlaying, Action notifyIsNotPlaying)

public void OutputMessage(string mess)
{
if (mess == "Spotify Playing: True")
if (mess == "SleepModeEnabled")
{
_notifyIsPlaying();
}
else
else if (mess == "SleepModeDisabled")
{
_notifyIsNotPlaying();
}
Expand Down
20 changes: 16 additions & 4 deletions SpotifySleepModeStopperGui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using SpotifyTools.Domain;
using SpotifyTools.Domain.AudioManagement;
using SpotifyTools.Domain.MessageManagement;
using SpotifyTools.Domain.PowerManagement;
using Application = System.Windows.Application;

namespace SpotifySleepModeStopperGui
{
Expand Down Expand Up @@ -76,19 +78,29 @@ public MainWindow()
private void exit_Click(object sender, EventArgs e)
{
_analyser.StopListening();

_notifyIcon.Visible = false;
_notifyIcon.Dispose();

Environment.Exit(0);
}

private void SetNotPlaying()
{
_notifyIcon.Icon = _notPlayingIcon;
_notifyIcon.Text = "Spotify isn't playing";
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
{
_notifyIcon.Icon = _notPlayingIcon;
_notifyIcon.Text = "Spotify isn't playing";
}));
}

private void SetPlaying()
{
_notifyIcon.Icon = _playingIcon;
_notifyIcon.Text = "Spotify is playing";
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
{
_notifyIcon.Icon = _playingIcon;
_notifyIcon.Text = "Spotify is playing";
}));
}
}
}

0 comments on commit b0f20e3

Please sign in to comment.