Skip to content

Commit

Permalink
single instance check added
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickiel committed Jun 30, 2021
1 parent cf1dc43 commit 2db5897
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 47 deletions.
Binary file added icons/VolumeScroller_light_ApplicationIcon.ico
Binary file not shown.
35 changes: 0 additions & 35 deletions src/VolumeScroller/App.cs

This file was deleted.

4 changes: 3 additions & 1 deletion src/VolumeScroller/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:VolumeScroller"
Startup="App_Startup"
Startup="App_Startup"
Exit="Application_Exit"
ShutdownMode="OnExplicitShutdown">

</Application>
37 changes: 36 additions & 1 deletion src/VolumeScroller/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -13,5 +14,39 @@ namespace VolumeScroller
/// </summary>
public partial class App : Application
{
private AudioController audioController;

public void App_Startup(object sender, StartupEventArgs e)
{
ShutdownIfAlreadyRunning();
InitializeTrayIcon();
Screen.Info screenInfo = new();
audioController = new AudioController(screenInfo);
}

private void ShutdownIfAlreadyRunning()
{
Process currentProcess = Process.GetCurrentProcess();
int count = Process.GetProcesses()
.Count(p => p.ProcessName.Equals(currentProcess.ProcessName));

if (count > 1)
{
Current.Shutdown();
}
}

private static void InitializeTrayIcon()
{
MainModel main = new();
MainViewModel mainViewModel = new(main);
MainWindow mainWindow = new(mainViewModel);
mainWindow.Show();
}

private void Application_Exit(object sender, ExitEventArgs e)
{
audioController.Dispose();
}
}
}
}
10 changes: 10 additions & 0 deletions src/VolumeScroller/Properties/Resources.Designer.cs

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

3 changes: 3 additions & 0 deletions src/VolumeScroller/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,7 @@
<data name="VolumeScroller_light" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\VolumeScroller_light.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="VolumeScroller_light_ApplicationIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\volumescroller_light_applicationicon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file not shown.
13 changes: 3 additions & 10 deletions src/VolumeScroller/VolumeScroller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<ApplicationIcon>Resources\VolumeScroller_light_ApplicationIcon.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Program - Kopieren.cs" />
</ItemGroup>

<ItemGroup>
<None Remove="Resources\VolumeScroller_dark.ico" />
<None Remove="Resources\VolumeScroller_light.ico" />
</ItemGroup>

<ItemGroup>
<ItemGroup>
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="Ikst.MouseHook" Version="1.0.0" />
<PackageReference Include="System.Management" Version="5.0.0" />
Expand All @@ -28,6 +20,7 @@
<ItemGroup>
<Resource Include="Resources\VolumeScroller_dark.ico" />
<Resource Include="Resources\VolumeScroller_light.ico" />
<Resource Include="Resources\VolumeScroller_light_ApplicationIcon.ico" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 2db5897

Please sign in to comment.