Skip to content

Commit

Permalink
Migrating from gRPC to SignalT
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Oct 18, 2023
1 parent 529bda5 commit a55302b
Show file tree
Hide file tree
Showing 44 changed files with 233 additions and 649 deletions.
2 changes: 2 additions & 0 deletions src/Library/Sucrose.Manager/Manage/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public static class Manager

public static int Volume => SHS.Clamp(SMMI.EngineSettingManager.GetSettingStable(SMC.Volume, 100), 0, 100);

public static bool SignalRequired => SMMI.BackgroundogSettingManager.GetSetting(SMC.SignalRequired, false);

public static string UpdatePercentage => SMMI.UpdateSettingManager.GetSetting(SMC.UpdatePercentage, "0%");

public static bool StorePreviewHide => SMMI.PortalSettingManager.GetSetting(SMC.StorePreviewHide, false);
Expand Down
2 changes: 2 additions & 0 deletions src/Library/Sucrose.Memory/Constant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public static class Constant

public const string CpuPerformance = "CpuPerformance";

public const string SignalRequired = "SignalRequired";

public const string StorePagination = "StorePagination";

public const string LibraryLocation = "LibraryLocation";
Expand Down
46 changes: 46 additions & 0 deletions src/Library/Sucrose.Signal/Helper/Deleter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using SMR = Sucrose.Memory.Readonly;

namespace Sucrose.Signal.Helper
{
internal static class Deleter
{
public static async Task Delete(string filePath)
{
try
{
if (File.Exists(filePath))
{
File.Delete(filePath);
}
}
catch
{
try
{
await Task.Delay(SMR.Randomise.Next(5, 50));

if (File.Exists(filePath))
{
File.Delete(filePath);
}
}
catch
{
try
{
await Task.Delay(SMR.Randomise.Next(5, 50));

if (File.Exists(filePath))
{
File.Delete(filePath);
}
}
catch
{
//
}
}
}
}
}
}
25 changes: 25 additions & 0 deletions src/Library/Sucrose.Signal/Interface/Backgroundog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Newtonsoft.Json.Linq;

namespace Sucrose.Signal.Interface
{
public class Backgroundog
{
public JObject Cpu { get; set; } = null;

public JObject Bios { get; set; } = null;

public JObject Date { get; set; } = null;

public JObject Audio { get; set; } = null;

public JObject Memory { get; set; } = null;

public JObject Battery { get; set; } = null;

public JObject Graphic { get; set; } = null;

public JObject Network { get; set; } = null;

public JObject Motherboard { get; set; } = null;
}
}
2 changes: 2 additions & 0 deletions src/Library/Sucrose.Signal/Manage/Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ public static class Internal
public static readonly SSST LauncherManager = new("Launcher.sgnl");

public static readonly SSST WebsiterManager = new("Websiter.sgnl");

public static readonly SSST BackgroundogManager = new("Backgroundog.sgnl");
}
}
41 changes: 33 additions & 8 deletions src/Library/Sucrose.Signal/SignalT.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System.Text.Json;
using Newtonsoft.Json;
using SMR = Sucrose.Memory.Readonly;
using SSHD = Sucrose.Signal.Helper.Deleter;
using SSHR = Sucrose.Signal.Helper.Reader;
using SSHW = Sucrose.Signal.Helper.Writer;
using Timer = System.Timers.Timer;

namespace Sucrose.Signal
{
public class SignalT(string Name)
{
private readonly JsonSerializerSettings SerializerSettings = new() { TypeNameHandling = TypeNameHandling.None, Formatting = Formatting.Indented };
private readonly string Source = Path.Combine(SMR.AppDataPath, SMR.AppName, SMR.CacheFolder, SMR.Signal);
private readonly JsonSerializerOptions Options = new() { WriteIndented = true };
private readonly Random Random = new();
private FileSystemWatcher FileWatcher;

public FileSystemEventHandler CreatedEventHandler;
Expand Down Expand Up @@ -95,37 +96,52 @@ public void FileSave<T>(T Data)

while (File.Exists(Destination))
{
Destination = Path.Combine(Source, $"{Path.GetFileNameWithoutExtension(Name)}-{Random.Next(0, int.MaxValue)}{Path.GetExtension(Name)}");
Destination = Path.Combine(Source, $"{Path.GetFileNameWithoutExtension(Name)}-{SMR.Randomise.Next(0, int.MaxValue)}{Path.GetExtension(Name)}");
}

SSHW.Write(Destination, JsonSerializer.Serialize(Data, Options));
SSHW.Write(Destination, JsonConvert.SerializeObject(Data, SerializerSettings));
}

public string FileName(string Source)
{
return Path.GetFileName(Source);
}

public T FileRead<T>(string Source, T Default)
public async void FileDelete(string Source)
{
await SSHD.Delete(Source);
}

public T FileRead<T>(string Source, T Default, bool Delete = true)
{
try
{
string Data = SSHR.Read(Source).Result;

return JsonSerializer.Deserialize<T>(Data, Options);
if (Delete)
{
DeletionTimer(Source);
}

return JsonConvert.DeserializeObject<T>(Data, SerializerSettings);
}
catch
{
return Default;
}
}

public string FileRead(string Source, string Default)
public string FileRead(string Source, string Default, bool Delete = true)
{
try
{
string Data = SSHR.Read(Source).Result;

if (Delete)
{
DeletionTimer(Source);
}

return Data;
}
catch
Expand All @@ -145,5 +161,14 @@ private bool FileCheck(string Source)
return false;
}
}

private void DeletionTimer(string Source)
{
Timer Deletion = new(3000);

Deletion.Elapsed += (sender, e) => FileDelete(Source);
Deletion.AutoReset = false;
Deletion.Start();
}
}
}
4 changes: 2 additions & 2 deletions src/Library/Sucrose.Signal/Sucrose.Signal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net48')) OR $(TargetFramework.StartsWith('netstandard'))">
<PackageReference Include="System.Text.Json" Version="8.0.0-rc.2.23479.6" />
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions src/Live/Sucrose.Live.Aurora/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Application = System.Windows.Application;
using SEWTT = Skylark.Enum.WindowsThemeType;
using SHC = Skylark.Helper.Culture;
using SMC = Sucrose.Memory.Constant;
using SMMI = Sucrose.Manager.Manage.Internal;
using SMMM = Sucrose.Manager.Manage.Manager;
using SMR = Sucrose.Memory.Readonly;
Expand Down Expand Up @@ -141,6 +142,8 @@ protected void Configure()
{
Source = Path.Combine(SMMM.LibraryLocation, SMMM.LibrarySelected, Source);

SMMI.BackgroundogSettingManager.SetSetting(SMC.SignalRequired, false);

if (File.Exists(Source))
{
SSSHS.Apply();
Expand Down
2 changes: 0 additions & 2 deletions src/Live/Sucrose.Live.Aurora/Sucrose.Live.Aurora.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\gRPC\Sucrose.Grpc\Sucrose.Grpc.csproj" />
<ProjectReference Include="..\..\Library\Sucrose.Manager\Sucrose.Manager.csproj" />
<ProjectReference Include="..\..\gRPC\Sucrose.Grpc.Client\Sucrose.Grpc.Client.csproj" />
</ItemGroup>

<Import Project="..\..\Shared\Sucrose.Shared.Zip\Sucrose.Shared.Zip.projitems" Label="Shared" />
Expand Down
2 changes: 2 additions & 0 deletions src/Live/Sucrose.Live.CefSharp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ protected void Configure()
Source = Path.Combine(SMMM.LibraryLocation, SMMM.LibrarySelected, Source);
}

SMMI.BackgroundogSettingManager.SetSetting(SMC.SignalRequired, false);

if (SSTHV.IsUrl(Source) || File.Exists(Source))
{
SSSHS.Apply();
Expand Down
4 changes: 2 additions & 2 deletions src/Live/Sucrose.Live.CefSharp/Sucrose.Live.CefSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\gRPC\Sucrose.Grpc\Sucrose.Grpc.csproj" />
<ProjectReference Include="..\..\Library\Sucrose.Signal\Sucrose.Signal.csproj" />
<ProjectReference Include="..\..\Library\Sucrose.Manager\Sucrose.Manager.csproj" />
<ProjectReference Include="..\..\gRPC\Sucrose.Grpc.Client\Sucrose.Grpc.Client.csproj" />
</ItemGroup>

<Import Project="..\..\Shared\Sucrose.Shared.Zip\Sucrose.Shared.Zip.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Live\Sucrose.Shared.Live.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Space\Sucrose.Shared.Space.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Theme\Sucrose.Shared.Theme.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Signal\Sucrose.Shared.Signal.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Watchdog\Sucrose.Shared.Watchdog.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Resources\Sucrose.Shared.Resources.projitems" Label="Shared" />
<Import Project="..\..\Shared\Engine\Sucrose.Shared.Engine\Sucrose.Shared.Engine.projitems" Label="Shared" />
Expand Down
3 changes: 3 additions & 0 deletions src/Live/Sucrose.Live.MpvPlayer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Application = System.Windows.Application;
using SEWTT = Skylark.Enum.WindowsThemeType;
using SHC = Skylark.Helper.Culture;
using SMC = Sucrose.Memory.Constant;
using SMMI = Sucrose.Manager.Manage.Internal;
using SMMM = Sucrose.Manager.Manage.Manager;
using SMR = Sucrose.Memory.Readonly;
Expand Down Expand Up @@ -138,6 +139,8 @@ protected void Configure()
Source = Path.Combine(SMMM.LibraryLocation, SMMM.LibrarySelected, Source);
}

SMMI.BackgroundogSettingManager.SetSetting(SMC.SignalRequired, false);

if (SSTHV.IsUrl(Source) || File.Exists(Source))
{
SSSHS.Apply();
Expand Down
2 changes: 0 additions & 2 deletions src/Live/Sucrose.Live.MpvPlayer/Sucrose.Live.MpvPlayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\gRPC\Sucrose.Grpc\Sucrose.Grpc.csproj" />
<ProjectReference Include="..\..\Library\Sucrose.Manager\Sucrose.Manager.csproj" />
<ProjectReference Include="..\..\gRPC\Sucrose.Grpc.Client\Sucrose.Grpc.Client.csproj" />
</ItemGroup>

<Import Project="..\..\Shared\Sucrose.Shared.Zip\Sucrose.Shared.Zip.projitems" Label="Shared" />
Expand Down
3 changes: 3 additions & 0 deletions src/Live/Sucrose.Live.Nebula/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Application = System.Windows.Application;
using SEWTT = Skylark.Enum.WindowsThemeType;
using SHC = Skylark.Helper.Culture;
using SMC = Sucrose.Memory.Constant;
using SMMI = Sucrose.Manager.Manage.Internal;
using SMMM = Sucrose.Manager.Manage.Manager;
using SMR = Sucrose.Memory.Readonly;
Expand Down Expand Up @@ -138,6 +139,8 @@ protected void Configure()
Source = Path.Combine(SMMM.LibraryLocation, SMMM.LibrarySelected, Source);
}

SMMI.BackgroundogSettingManager.SetSetting(SMC.SignalRequired, false);

if (SSTHV.IsUrl(Source) || File.Exists(Source))
{
SSSHS.Apply();
Expand Down
2 changes: 0 additions & 2 deletions src/Live/Sucrose.Live.Nebula/Sucrose.Live.Nebula.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\gRPC\Sucrose.Grpc\Sucrose.Grpc.csproj" />
<ProjectReference Include="..\..\Library\Sucrose.Manager\Sucrose.Manager.csproj" />
<ProjectReference Include="..\..\gRPC\Sucrose.Grpc.Client\Sucrose.Grpc.Client.csproj" />
</ItemGroup>

<Import Project="..\..\Shared\Sucrose.Shared.Zip\Sucrose.Shared.Zip.projitems" Label="Shared" />
Expand Down
3 changes: 3 additions & 0 deletions src/Live/Sucrose.Live.Vexana/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Application = System.Windows.Application;
using SEWTT = Skylark.Enum.WindowsThemeType;
using SHC = Skylark.Helper.Culture;
using SMC = Sucrose.Memory.Constant;
using SMMI = Sucrose.Manager.Manage.Internal;
using SMMM = Sucrose.Manager.Manage.Manager;
using SMR = Sucrose.Memory.Readonly;
Expand Down Expand Up @@ -138,6 +139,8 @@ protected void Configure()
Source = Path.Combine(SMMM.LibraryLocation, SMMM.LibrarySelected, Source);
}

SMMI.BackgroundogSettingManager.SetSetting(SMC.SignalRequired, false);

if (SSTHV.IsUrl(Source) || File.Exists(Source))
{
SSSHS.Apply();
Expand Down
2 changes: 0 additions & 2 deletions src/Live/Sucrose.Live.Vexana/Sucrose.Live.Vexana.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\gRPC\Sucrose.Grpc\Sucrose.Grpc.csproj" />
<ProjectReference Include="..\..\Library\Sucrose.Manager\Sucrose.Manager.csproj" />
<ProjectReference Include="..\..\gRPC\Sucrose.Grpc.Client\Sucrose.Grpc.Client.csproj" />
</ItemGroup>

<Import Project="..\..\Shared\Sucrose.Shared.Zip\Sucrose.Shared.Zip.projitems" Label="Shared" />
Expand Down
2 changes: 2 additions & 0 deletions src/Live/Sucrose.Live.WebView/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ protected void Configure()
Source = Path.Combine(SMMM.LibraryLocation, SMMM.LibrarySelected, Source);
}

SMMI.BackgroundogSettingManager.SetSetting(SMC.SignalRequired, false);

if (SSTHV.IsUrl(Source) || File.Exists(Source))
{
SSSHS.Apply();
Expand Down
4 changes: 2 additions & 2 deletions src/Live/Sucrose.Live.WebView/Sucrose.Live.WebView.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\gRPC\Sucrose.Grpc\Sucrose.Grpc.csproj" />
<ProjectReference Include="..\..\Library\Sucrose.Signal\Sucrose.Signal.csproj" />
<ProjectReference Include="..\..\Library\Sucrose.Manager\Sucrose.Manager.csproj" />
<ProjectReference Include="..\..\gRPC\Sucrose.Grpc.Client\Sucrose.Grpc.Client.csproj" />
</ItemGroup>

<Import Project="..\..\Shared\Sucrose.Shared.Zip\Sucrose.Shared.Zip.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Live\Sucrose.Shared.Live.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Space\Sucrose.Shared.Space.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Theme\Sucrose.Shared.Theme.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Signal\Sucrose.Shared.Signal.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Watchdog\Sucrose.Shared.Watchdog.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Resources\Sucrose.Shared.Resources.projitems" Label="Shared" />
<Import Project="..\..\Shared\Engine\Sucrose.Shared.Engine\Sucrose.Shared.Engine.projitems" Label="Shared" />
Expand Down
1 change: 0 additions & 1 deletion src/Portal/Sucrose.Portal/Sucrose.Portal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
<Import Project="..\..\Shared\Sucrose.Shared.Theme\Sucrose.Shared.Theme.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Store\Sucrose.Shared.Store.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Space\Sucrose.Shared.Space.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Signal\Sucrose.Shared.Signal.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Watchdog\Sucrose.Shared.Watchdog.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Resources\Sucrose.Shared.Resources.projitems" Label="Shared" />
<Import Project="..\..\Shared\Sucrose.Shared.Dependency\Sucrose.Shared.Dependency.projitems" Label="Shared" />
Expand Down
Loading

0 comments on commit a55302b

Please sign in to comment.