Skip to content

Commit

Permalink
Preparing Backgroundog
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Sep 29, 2023
1 parent 552ff79 commit 99f97ad
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Library/Sucrose.Memory/Constant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ public static class Constant

public const string MemoryPerformance = "MemoryPerformance";

public const string VirtualPerformance = "VirtualPerformance";

public const string PerformanceCounter = "PerformanceCounter";

public const string NetworkPerformance = "NetworkPerformance";
Expand Down
2 changes: 2 additions & 0 deletions src/Portal/Sucrose.Portal/Manage/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ internal static class Manager

public static WindowBackdropType BackdropType => SMMI.PortalSettingManager.GetSetting(SMC.BackdropType, DefaultBackdropType);

public static SSDEPT VirtualPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.VirtualPerformance, SSDEPT.Resume);

public static SSDEPT NetworkPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.NetworkPerformance, SSDEPT.Resume);

public static SSDEPT BatteryPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.BatteryPerformance, SSDEPT.Close);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,16 @@ private void InitializeViewModel()
NetworkAdapter.Items.Add(Interface);
}

NetworkAdapter.SelectedValue = SMMM.NetworkAdapter;
string SelectedAdapter = SMMM.NetworkAdapter;

if (string.IsNullOrEmpty(SelectedAdapter))
{
NetworkAdapter.SelectedIndex = 0;
}
else
{
NetworkAdapter.SelectedValue = SelectedAdapter;
}
}
else
{
Expand Down Expand Up @@ -526,6 +535,31 @@ private void InitializeViewModel()

Contents.Add(SystemArea);

SPVCEC Virtual = new()
{
Margin = new Thickness(0, 10, 0, 0),
Expandable = false
};

Virtual.Title.Text = "Sanallaştırma";
Virtual.LeftIcon.Symbol = SymbolRegular.DesktopCheckmark24;
Virtual.Description.Text = "Sanallaştırma uygulamaları çalışırken duvar kağıdına ne olacağı.";

ComboBox VirtualPerformance = new();

VirtualPerformance.SelectionChanged += (s, e) => VirtualPerformanceSelected(VirtualPerformance.SelectedIndex);

foreach (SSDEPT Type in Enum.GetValues(typeof(SSDEPT)))
{
VirtualPerformance.Items.Add(Type);
}

VirtualPerformance.SelectedIndex = (int)SPMM.VirtualPerformance;

Virtual.HeaderFrame = VirtualPerformance;

Contents.Add(Virtual);

SPVCEC Remote = new()
{
Margin = new Thickness(0, 10, 0, 0),
Expand Down Expand Up @@ -770,6 +804,16 @@ private void MemoryPerformanceSelected(int Index)
}
}

private void VirtualPerformanceSelected(int Index)
{
if (Index != (int)SPMM.VirtualPerformance)
{
SSDEPT Type = (SSDEPT)Index;

SMMI.BackgroundogSettingManager.SetSetting(SMC.VirtualPerformance, Type);
}
}

private void NetworkPingTypeSelected(string Value)
{
if (Value != SMMM.PingType)
Expand Down
33 changes: 33 additions & 0 deletions src/Project/Sucrose.Backgroundog/Extension/Virtual.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Management;
using SSSHV = Sucrose.Shared.Space.Helper.Virtual;

namespace Sucrose.Backgroundog.Extension
{
internal static class Virtual
{
public static bool VirtualityActive()
{
try
{
string Query = "SELECT * FROM Win32_Process WHERE ";

foreach (string Name in SSSHV.GetApp())
{
Query += $"Name = '{Name}' OR ";
}

Query = Query.TrimEnd(" OR ".ToCharArray());

ManagementObjectSearcher Searcher = new(Query);

ManagementObjectCollection Collection = Searcher.Get();

return Collection.Count > 0;
}
catch
{
return false;
}
}
}
}
39 changes: 37 additions & 2 deletions src/Project/Sucrose.Backgroundog/Helper/Condition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ public static async Task Start()
return;
}

if (await NetworkCondition())
if (await RemoteCondition())
{
return;
}

if (await RemoteCondition())
if (await VirtualCondition())
{
return;
}

if (await NetworkCondition())
{
return;
}
Expand Down Expand Up @@ -379,6 +384,36 @@ private static async Task<bool> BatteryCondition()
return false;
}

private static async Task<bool> VirtualCondition()
{
if (SBMI.CategoryPerformance == SSDECPT.Virtual)
{
int Count = 0;
int MaxCount = 3;

while (!SBMI.Virtuality || SBMM.VirtualPerformance == SSDEPT.Resume)
{
if (Count >= MaxCount)
{
Lifecycle();
SBMI.Condition = false;
SBMI.Performance = SSDEPT.Resume;
SBMI.CategoryPerformance = SSDECPT.Not;

return true;
}
else
{
Count++;
}

await Task.Delay(TimeSpan.FromSeconds(1));
}
}

return false;
}

private static async Task<bool> FullscreenCondition()
{
if (SBMI.CategoryPerformance == SSDECPT.Fullscreen)
Expand Down
35 changes: 35 additions & 0 deletions src/Project/Sucrose.Backgroundog/Helper/Performance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public static async Task Start()
return;
}

if (await VirtualPerformance())
{
return;
}

if (await NetworkPerformance())
{
return;
Expand Down Expand Up @@ -362,6 +367,36 @@ private static async Task<bool> BatteryPerformance()
return false;
}

private static async Task<bool> VirtualPerformance()
{
if (SBMM.VirtualPerformance != SSDEPT.Resume)
{
int Count = 0;
int MaxCount = 5;

while (SBMI.Virtuality)
{
if (Count >= MaxCount)
{
SBMI.Performance = SBMM.VirtualPerformance;
SBMI.CategoryPerformance = SSDECPT.Virtual;
SBMI.Condition = true;
Lifecycle();

return true;
}
else
{
Count++;
}

await Task.Delay(TimeSpan.FromSeconds(1));
}
}

return false;
}

private static async Task<bool> FullscreenPerformance()
{
if (SBMM.FullscreenPerformance != SSDEPT.Resume)
Expand Down
13 changes: 13 additions & 0 deletions src/Project/Sucrose.Backgroundog/Helper/Specification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SBEAS = Sucrose.Backgroundog.Extension.AudioSession;
using SBER = Sucrose.Backgroundog.Extension.Remote;
using SBEUV = Sucrose.Backgroundog.Extension.UpdateVisitor;
using SBEV = Sucrose.Backgroundog.Extension.Virtual;
using SBMI = Sucrose.Backgroundog.Manage.Internal;
using SBSSSS = Sucrose.Backgroundog.Struct.Sensor.SensorStruct;
using SECNT = Skylark.Enum.ClearNumericType;
Expand Down Expand Up @@ -330,6 +331,18 @@ public static async Task Start()
}
});

_ = Task.Run(() =>
{
try
{
SBMI.Virtuality = SBEV.VirtualityActive();
}
catch (Exception Exception)
{
SSWW.Watch_CatchException(Exception);
}
});

_ = Task.Run(() =>
{
try
Expand Down
2 changes: 2 additions & 0 deletions src/Project/Sucrose.Backgroundog/Manage/Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ internal static class Internal

public static SBHI Initialize = new();

public static bool Virtuality = false;

public static int InitializeTime = 250;

public static bool FocusDesktop = false;
Expand Down
2 changes: 2 additions & 0 deletions src/Project/Sucrose.Backgroundog/Manage/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ internal static class Manager
{
public static SSDEPT FullscreenPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.FullscreenPerformance, SSDEPT.Close);

public static SSDEPT VirtualPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.VirtualPerformance, SSDEPT.Resume);

public static SSDEPT NetworkPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.NetworkPerformance, SSDEPT.Resume);

public static SSDEPT BatteryPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.BatteryPerformance, SSDEPT.Pause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal enum CategoryPerformanceType
Saver,
Memory,
Remote,
Virtual,
Network,
Battery,
Fullscreen
Expand Down
25 changes: 25 additions & 0 deletions src/Shared/Sucrose.Shared.Space/Helper/Virtual.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Sucrose.Shared.Space.Helper
{
internal static class Virtual
{
public static List<string> GetApp()
{
return new()
{
"nox.exe",
"memu.exe",
"vmware.exe",
"dnplayer.exe",
"noxplayer.exe",
"hd-player.exe",
"vmware-vmx.exe",
"virtualbox.exe",
"bluestacks.exe",
"noxvmhandle.exe",
"virtualboxvm.exe",
"windowssandbox.exe",
"windowssandboxclient.exe"
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Helper\Copy.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helper\Graphic.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helper\Management.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helper\Virtual.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helper\Remote.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helper\Network.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helper\Clean.cs" />
Expand Down

0 comments on commit 99f97ad

Please sign in to comment.