Skip to content

Commit

Permalink
Creation of a windows app
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasConstant committed Nov 10, 2015
1 parent 34de5e8 commit a0b0ae6
Show file tree
Hide file tree
Showing 18 changed files with 590 additions and 27 deletions.
7 changes: 7 additions & 0 deletions SpotifySleepModeStopper.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpotifySleepModeStopperCons
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpotifySleepModeStopperService", "WindowsService\SpotifySleepModeStopperService.csproj", "{23717C35-642B-41D5-882B-460083C1E376}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpotifySleepModeStopperGui", "SpotifySleepModeStopperGui\SpotifySleepModeStopperGui.csproj", "{8C0977F4-070D-4B83-A825-EDDECD812C36}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -33,6 +35,10 @@ Global
{23717C35-642B-41D5-882B-460083C1E376}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23717C35-642B-41D5-882B-460083C1E376}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23717C35-642B-41D5-882B-460083C1E376}.Release|Any CPU.Build.0 = Release|Any CPU
{8C0977F4-070D-4B83-A825-EDDECD812C36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8C0977F4-070D-4B83-A825-EDDECD812C36}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C0977F4-070D-4B83-A825-EDDECD812C36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C0977F4-070D-4B83-A825-EDDECD812C36}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -41,5 +47,6 @@ Global
{0EFA9F55-FD0A-4B27-B953-4B6F5213A7B5} = {3D8B40CA-FF63-47A7-B987-16C32BABDA81}
{ECEFE84A-5AB9-460C-9937-AA18C20674A2} = {EA773A42-7CE2-4520-936D-4B76A417252D}
{23717C35-642B-41D5-882B-460083C1E376} = {A18AF2DC-D0FB-4CA4-AB24-07EA9826EF48}
{8C0977F4-070D-4B83-A825-EDDECD812C36} = {EA773A42-7CE2-4520-936D-4B76A417252D}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public void EnableConstantDisplayAndPower(bool enableConstantDisplayAndPower)
_powerRequest = PowerCreateRequest(ref _powerRequestContext);

// Set the request
var s = PowerSetRequest(_powerRequest, PowerRequestType.PowerRequestSystemRequired);
var s2 = PowerSetRequest(_powerRequest, PowerRequestType.PowerRequestDisplayRequired);
PowerSetRequest(_powerRequest, PowerRequestType.PowerRequestSystemRequired);
PowerSetRequest(_powerRequest, PowerRequestType.PowerRequestDisplayRequired);
}
else
{
Expand All @@ -107,28 +107,5 @@ public void EnableConstantDisplayAndPower(bool enableConstantDisplayAndPower)
CloseHandle(_powerRequest);
}
}

//[DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
//internal static extern IntPtr GetProcAddress(IntPtr hModule, string procName);

//[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
//internal static extern IntPtr LoadLibrary(string dllToLoad);

//private static bool PowerAvailabilityRequestsSupported()
//{
// var ptr = LoadLibrary("kernel32.dll");
// var ptr2 = GetProcAddress(ptr, "PowerSetRequest");

// if (ptr2 == IntPtr.Zero)
// {
// // Power availability requests NOT suppoted.
// return false;
// }
// else
// {
// // Power availability requests ARE suppoted.
// return true;
// }
//}
}
}
4 changes: 2 additions & 2 deletions SpotifySleepModeStopper/Domain/SpotifySaveModeStopper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ private bool IsSpotifyRunning()

private bool IsSoundStreaming()
{
//var isSpotifyPlaying = _soundAnalyser.IsProcessNameOutputingSound(SpotifyProcessName);
var isSpotifyPlaying = _soundAnalyser.IsWindowsOutputingSound();
var isSpotifyPlaying = _soundAnalyser.IsProcessNameOutputingSound(SpotifyProcessName);
//var isSpotifyPlaying = _soundAnalyser.IsWindowsOutputingSound();
return isSpotifyPlaying;
}
}
Expand Down
6 changes: 6 additions & 0 deletions SpotifySleepModeStopperGui/App.config
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>
9 changes: 9 additions & 0 deletions SpotifySleepModeStopperGui/App.xaml
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>
17 changes: 17 additions & 0 deletions SpotifySleepModeStopperGui/App.xaml.cs
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
{
}
}
34 changes: 34 additions & 0 deletions SpotifySleepModeStopperGui/IconChanger.cs
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();
}
}
}
}
12 changes: 12 additions & 0 deletions SpotifySleepModeStopperGui/MainWindow.xaml
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>
94 changes: 94 additions & 0 deletions SpotifySleepModeStopperGui/MainWindow.xaml.cs
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";
}
}
}
55 changes: 55 additions & 0 deletions SpotifySleepModeStopperGui/Properties/AssemblyInfo.cs
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 SpotifySleepModeStopperGui/Properties/Resources.Designer.cs

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

Loading

0 comments on commit a0b0ae6

Please sign in to comment.