Skip to content

Commit

Permalink
Moved some code to a separate project.
Browse files Browse the repository at this point in the history
This will simply the codebase and keep the solution clean, compact and easy to maintain or code.
  • Loading branch information
ShankarBUS committed Dec 11, 2020
1 parent bff841f commit b42729b
Show file tree
Hide file tree
Showing 28 changed files with 254 additions and 258 deletions.
7 changes: 7 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<PropertyGroup>
<Authors>ModernFlyouts Community</Authors>
<LangVersion>latest</LangVersion>
<Version>0.8.4.1-beta</Version>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Runtime.InteropServices;
using System.Windows.Input;
using static ModernFlyouts.Interop.NativeMethods;
using static ModernFlyouts.Core.Interop.NativeMethods;

namespace ModernFlyouts.Utilities
namespace ModernFlyouts.Core.Interop
{
public class KeyboardHook
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Diagnostics;
using System.Linq;
using System.Windows.Threading;
using static ModernFlyouts.Interop.NativeMethods;
using static ModernFlyouts.Core.Interop.NativeMethods;

namespace ModernFlyouts.Interop
namespace ModernFlyouts.Core.Interop
{
public class NativeFlyoutHandler
{
Expand Down Expand Up @@ -370,7 +370,7 @@ public void ShowNativeFlyout()
}
}

internal void VerifyNativeFlyoutCreated()
public void VerifyNativeFlyoutCreated()
{
if (!_hasNativeFlyoutCreated)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Runtime.InteropServices;
using System.Text;

namespace ModernFlyouts.Interop
namespace ModernFlyouts.Core.Interop
{
public static class NativeMethods
{
Expand Down Expand Up @@ -214,10 +214,10 @@ internal static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLon
internal static extern bool UnhookWinEvent(IntPtr hWinEventHook);

[DllImport("user32.dll", SetLastError = true)]
internal static extern bool RegisterShellHookWindow(IntPtr hWnd);
public static extern bool RegisterShellHookWindow(IntPtr hWnd);

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern uint RegisterWindowMessage(string lpString);
public static extern uint RegisterWindowMessage(string lpString);

[Serializable]
[StructLayout(LayoutKind.Sequential)]
Expand Down Expand Up @@ -299,10 +299,10 @@ public static WINDOWPLACEMENT Default

[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetWindowPlacement(IntPtr hWnd, out WINDOWPLACEMENT lpwndpl);
public static extern bool GetWindowPlacement(IntPtr hWnd, out WINDOWPLACEMENT lpwndpl);

[DllImport("user32.dll")]
internal static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref WINDOWPLACEMENT lpwndpl);
public static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref WINDOWPLACEMENT lpwndpl);

internal delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);

Expand Down Expand Up @@ -331,7 +331,7 @@ internal static string GetWindowClassName(IntPtr hWnd)
}
}

internal static void SetToolWindow(IntPtr hWnd)
public static void SetToolWindow(IntPtr hWnd)
{
var exstyle = GetWindowLongPtr(hWnd, (int)GetWindowLongFields.GWL_EXSTYLE);
IntPtr style = new((uint)GetWindowLongPtr(hWnd, (int)GetWindowLongFields.GWL_STYLE) & ~(uint)WindowStyles.WS_SYSMENU);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ModernFlyouts
{
internal abstract class SourceAppInfo
public abstract class SourceAppInfo
{
#region Properties

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using ModernFlyouts.Utilities;
using ModernFlyouts.Core.Utilities;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
using static ModernFlyouts.Interop.NativeMethods;
using static ModernFlyouts.Core.Interop.NativeMethods;

namespace ModernFlyouts
{
Expand Down Expand Up @@ -89,7 +89,7 @@ await Task.Run(() =>

#region Window activation things

public static WindowSizeState GetWindowSizeState(IntPtr hWnd)
private static WindowSizeState GetWindowSizeState(IntPtr hWnd)
{
GetWindowPlacement(hWnd, out WINDOWPLACEMENT placement);

Expand All @@ -102,7 +102,7 @@ public static WindowSizeState GetWindowSizeState(IntPtr hWnd)
};
}

public enum WindowSizeState
private enum WindowSizeState
{
Normal,
Minimized,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private interface IAppxManifestApplicationsEnumerator
}

[Guid("5DA89BF4-3773-46BE-B650-7E744863B7E8"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IAppxManifestApplication
private interface IAppxManifestApplication
{
[PreserveSig]
int GetStringValue([MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string vaue);
Expand Down
14 changes: 14 additions & 0 deletions ModernFlyouts.Core/ModernFlyouts.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NAudio" Version="1.10.0" />
<PackageReference Include="System.Drawing.Common" Version="5.0.0" />
<PackageReference Include="System.Management" Version="5.0.0" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions ModernFlyouts.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[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)
)]
62 changes: 62 additions & 0 deletions ModernFlyouts.Core/Utilities/AirplaneModeWatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Diagnostics;
using System.Management;

namespace ModernFlyouts.Core.Utilities
{
public class AirplaneModeWatcher
{
private readonly ManagementEventWatcher watcher;

public event EventHandler<AirplaneModeChangedEventArgs> Changed;

public AirplaneModeWatcher()
{
try
{
WqlEventQuery query = new(
"SELECT * FROM RegistryValueChangeEvent WHERE " +
"Hive = 'HKEY_LOCAL_MACHINE'" +
@"AND KeyPath = 'SYSTEM\\CurrentControlSet\\Control\\RadioManagement\\SystemRadioState' AND ValueName=''");

watcher = new ManagementEventWatcher(query);
watcher.EventArrived += new EventArrivedEventHandler(HandleEvent);
}
catch (ManagementException managementException)
{
Debug.WriteLine($"{nameof(AirplaneModeWatcher)}: " + managementException.Message);
}
}

public void Start()
{
watcher.Start();
}

public void Stop()
{
watcher.Stop();
}

public static bool GetIsAirplaneModeEnabled()
{
var regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\RadioManagement\SystemRadioState", false);
return (int)regkey?.GetValue("", 1) == 1;
}

private void HandleEvent(object sender, EventArrivedEventArgs e)
{
Changed?.Invoke(this, new AirplaneModeChangedEventArgs(GetIsAirplaneModeEnabled()));
}
}

public class AirplaneModeChangedEventArgs : EventArgs
{
public AirplaneModeChangedEventArgs(bool isEnabled)
{
IsEnabled = isEnabled;
}

public bool IsEnabled { get; }
}
}
31 changes: 31 additions & 0 deletions ModernFlyouts.Core/Utilities/AudioDeviceNotificationClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using NAudio.CoreAudioApi;
using NAudio.CoreAudioApi.Interfaces;
using System;

namespace ModernFlyouts.Core.Utilities
{
public class AudioDeviceNotificationClient : IMMNotificationClient
{
public event EventHandler<string> DefaultDeviceChanged;

public void OnDefaultDeviceChanged(DataFlow dataFlow, Role deviceRole, string defaultDeviceId)
{
if (dataFlow == DataFlow.Render && deviceRole == Role.Multimedia)
{
DefaultDeviceChanged?.Invoke(this, defaultDeviceId);
}
}

public void OnDeviceAdded(string deviceId)
{ }

public void OnDeviceRemoved(string deviceId)
{ }

public void OnDeviceStateChanged(string deviceId, DeviceState newState)
{ }

public void OnPropertyValueChanged(string deviceId, PropertyKey propertyKey)
{ }
}
}
68 changes: 68 additions & 0 deletions ModernFlyouts.Core/Utilities/BrightnessWatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Diagnostics;
using System.Management;

namespace ModernFlyouts.Core.Utilities
{
public class BrightnessWatcher
{
private readonly ManagementEventWatcher watcher;

public event EventHandler<BrightnessChangedEventArgs> Changed;

public BrightnessWatcher()
{
try
{
var scope = new ManagementScope("root\\WMI");
var query = new WqlEventQuery("SELECT * FROM WmiMonitorBrightnessEvent");
watcher = new ManagementEventWatcher(scope, query);
watcher.EventArrived += new EventArrivedEventHandler(HandleEvent);
}
catch (ManagementException managementException)
{
Debug.WriteLine($"{nameof(BrightnessWatcher)}: " + managementException.Message);
}
}

public void Start()
{
try
{
watcher.Start();
}
catch (ManagementException managementException)
{
Debug.WriteLine($"{nameof(BrightnessWatcher)}: " + managementException.Message);
}
}

public void Stop()
{
try
{
watcher.Stop();
}
catch (ManagementException managementException)
{
Debug.WriteLine($"{nameof(BrightnessWatcher)}: " + managementException.Message);
}
}

private void HandleEvent(object sender, EventArrivedEventArgs e)
{
int value = int.Parse(e.NewEvent.Properties["Brightness"].Value.ToString());
Changed?.Invoke(this, new BrightnessChangedEventArgs(value));
}
}

public class BrightnessChangedEventArgs : EventArgs
{
public BrightnessChangedEventArgs(int newValue)
{
NewValue = newValue;
}

public int NewValue { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
using System.Security;
using System.Text;

namespace ModernFlyouts.Utilities
namespace ModernFlyouts.Core.Utilities
{
public sealed class IconExtractor
{
Expand Down
22 changes: 22 additions & 0 deletions ModernFlyouts.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModernFlyouts", "ModernFlyo
EndProject
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "ModernFlyouts.Package", "ModernFlyouts.Package\ModernFlyouts.Package.wapproj", "{E918A18D-953D-4B4A-AC18-B74303995AEE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModernFlyouts.Core", "ModernFlyouts.Core\ModernFlyouts.Core.csproj", "{81626E00-9226-4125-B8EA-7EE7C2772169}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -71,6 +73,26 @@ Global
{E918A18D-953D-4B4A-AC18-B74303995AEE}.Release|x86.ActiveCfg = Release|x86
{E918A18D-953D-4B4A-AC18-B74303995AEE}.Release|x86.Build.0 = Release|x86
{E918A18D-953D-4B4A-AC18-B74303995AEE}.Release|x86.Deploy.0 = Release|x86
{81626E00-9226-4125-B8EA-7EE7C2772169}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Debug|ARM.ActiveCfg = Debug|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Debug|ARM.Build.0 = Debug|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Debug|ARM64.Build.0 = Debug|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Debug|x64.ActiveCfg = Debug|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Debug|x64.Build.0 = Debug|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Debug|x86.ActiveCfg = Debug|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Debug|x86.Build.0 = Debug|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Release|Any CPU.Build.0 = Release|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Release|ARM.ActiveCfg = Release|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Release|ARM.Build.0 = Release|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Release|ARM64.ActiveCfg = Release|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Release|ARM64.Build.0 = Release|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Release|x64.ActiveCfg = Release|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Release|x64.Build.0 = Release|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Release|x86.ActiveCfg = Release|Any CPU
{81626E00-9226-4125-B8EA-7EE7C2772169}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion ModernFlyouts/Controls/SimpleWrapPanel/SimpleWrapPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,4 @@ void Arrange(UIElement child, bool isLast = false)
return finalSize;
}
}
}
}
Loading

1 comment on commit b42729b

@ShankarBUS
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Samuel12321,
I also removed some no more used string resources. Make sure to update other related files too.
Sorry for the burden 😅. I did what I had to do.

This repo will receive much more breaking changes in the upcoming weeks.
Make sure you pull the origin in VS Team Explorer or VS Git or any other git tool you use before every commit. And make your local clone is in sync with this repo.
Unnecessary merge commits at these kinda times would be worse (no more spaghett please). Please be careful.

Please sign in to comment.