-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34de5e8
commit a0b0ae6
Showing
18 changed files
with
590 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="SpotifySleepModeStopperGui.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:SpotifySleepModeStopperGui" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace SpotifySleepModeStopperGui | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Media; | ||
using SpotifyTools.Contracts; | ||
|
||
namespace SpotifySleepModeStopperGui | ||
{ | ||
public class IconChanger : IMessageDisplayer | ||
{ | ||
private readonly Action _notifyIsPlaying; | ||
private readonly Action _notifyIsNotPlaying; | ||
|
||
public IconChanger(Action notifyIsPlaying, Action notifyIsNotPlaying) | ||
{ | ||
_notifyIsPlaying = notifyIsPlaying; | ||
_notifyIsNotPlaying = notifyIsNotPlaying; | ||
} | ||
|
||
public void OutputMessage(string mess) | ||
{ | ||
if (mess == "Spotify Playing: True") | ||
{ | ||
_notifyIsPlaying(); | ||
} | ||
else | ||
{ | ||
_notifyIsNotPlaying(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Window x:Class="SpotifySleepModeStopperGui.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:SpotifySleepModeStopperGui" | ||
mc:Ignorable="d" | ||
Title="MainWindow" Height="350" Width="525"> | ||
<Grid> | ||
|
||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Forms; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
using SpotifyTools.Domain; | ||
using SpotifyTools.Domain.AudioManagement; | ||
using SpotifyTools.Domain.MessageManagement; | ||
using SpotifyTools.Domain.PowerManagement; | ||
|
||
namespace SpotifySleepModeStopperGui | ||
{ | ||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
private readonly NotifyIcon _notifyIcon; | ||
private readonly Icon _notPlayingIcon; | ||
private readonly Icon _playingIcon; | ||
private readonly SpotifySaveModeStopper _analyser; | ||
|
||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
|
||
#region Init Tray Icon | ||
WindowState = WindowState.Minimized; | ||
Visibility = Visibility.Hidden; | ||
ShowInTaskbar = false; | ||
|
||
_notifyIcon = new NotifyIcon(); | ||
using ( | ||
var stream = | ||
Assembly.GetExecutingAssembly().GetManifestResourceStream("SpotifySleepModeStopperGui.music.ico")) | ||
{ | ||
_notPlayingIcon = new Icon(stream); | ||
} | ||
using ( | ||
var stream = | ||
Assembly.GetExecutingAssembly() | ||
.GetManifestResourceStream("SpotifySleepModeStopperGui.music_playing.ico")) | ||
{ | ||
_playingIcon = new Icon(stream); | ||
} | ||
SetNotPlaying(); | ||
_notifyIcon.Visible = true; | ||
|
||
var contextMenu = new System.Windows.Forms.ContextMenu(); | ||
var menuItem = new System.Windows.Forms.MenuItem(); | ||
|
||
contextMenu.MenuItems.AddRange(new[] { menuItem }); | ||
menuItem.Index = 0; | ||
menuItem.Text = "Exit"; | ||
menuItem.Click += exit_Click; | ||
_notifyIcon.ContextMenu = contextMenu; | ||
#endregion | ||
|
||
var iconChanger = new IconChanger(SetPlaying, SetNotPlaying); | ||
_analyser = new SpotifySaveModeStopper(iconChanger, new PowerRequestContextHandler(), new CsCoreSoundAnalyser()); | ||
_analyser.StartListening(); | ||
} | ||
|
||
private void exit_Click(object sender, EventArgs e) | ||
{ | ||
_analyser.StopListening(); | ||
Environment.Exit(0); | ||
} | ||
|
||
private void SetNotPlaying() | ||
{ | ||
_notifyIcon.Icon = _notPlayingIcon; | ||
_notifyIcon.Text = "Spotify isn't playing"; | ||
} | ||
|
||
private void SetPlaying() | ||
{ | ||
_notifyIcon.Icon = _playingIcon; | ||
_notifyIcon.Text = "Spotify is playing"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Reflection; | ||
using System.Resources; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using System.Windows; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("Spotify Sleep Mode Stopper")] | ||
[assembly: AssemblyDescription("Prevent windows to sleep when spotify is playing")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("Spotify Sleep Mode Stopper")] | ||
[assembly: AssemblyCopyright("Copyright © 2015")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
//In order to begin building localizable applications, set | ||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file | ||
//inside a <PropertyGroup>. For example, if you are using US english | ||
//in your source files, set the <UICulture> to en-US. Then uncomment | ||
//the NeutralResourceLanguage attribute below. Update the "en-US" in | ||
//the line below to match the UICulture setting in the project file. | ||
|
||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] | ||
|
||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] | ||
|
||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
71 changes: 71 additions & 0 deletions
71
SpotifySleepModeStopperGui/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.