Skip to content

Commit

Permalink
revised menu organization
Browse files Browse the repository at this point in the history
reduced size of files in the data directory
added hwinfo support
  • Loading branch information
mhwlng committed Dec 24, 2020
1 parent 713fa11 commit 1e5b19e
Show file tree
Hide file tree
Showing 17 changed files with 955 additions and 231 deletions.
52 changes: 52 additions & 0 deletions Elite/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public partial class App : Application
public static readonly object RefreshJsonLock = new object();
public static readonly object RefreshSystemLock = new object();

public static Task HWInfoTask;
private static CancellationTokenSource _hwInfoTokenSource = new CancellationTokenSource();

public static Task JsonTask;
private static CancellationTokenSource _jsonTokenSource = new CancellationTokenSource();

Expand Down Expand Up @@ -317,6 +320,7 @@ protected override void OnStartup(StartupEventArgs evtArgs)
Engine.Razor.Compile("target.cshtml", null);
Engine.Razor.Compile("galnet.cshtml", null);
Engine.Razor.Compile("poi.cshtml", null);
Engine.Razor.Compile("hwinfo.cshtml", null);
Engine.Razor.Compile("galaxy.cshtml", null);
Engine.Razor.Compile("engineers.cshtml", null);
Expand Down Expand Up @@ -356,6 +360,15 @@ protected override void OnStartup(StartupEventArgs evtArgs)
Engineer.GetShoppingList();
Engineer.GetBestSystems();
splashScreen.Dispatcher.Invoke(() => splashScreen.ProgressText.Text = "Getting sensor data from HWInfo...");
HWInfo.ReadMem("HWINFO.INC");
if (HWInfo.SensorData.Any())
{
HWInfo.SaveDataToFile(@"Data\hwinfo.json");
}
if (File.Exists(Path.Combine(ExePath, "joystickSettings.config")) && ConfigurationManager.GetSection("joystickSettings") is NameValueCollection joystickSection)
{
_pid = joystickSection["PID"];
Expand Down Expand Up @@ -610,6 +623,28 @@ protected override void OnStartup(StartupEventArgs evtArgs)
}, jsonToken);
var hwInfoToken = _hwInfoTokenSource.Token;
HWInfoTask = Task.Run(async () =>
{
Log.Info("HWInfo task started");
while (true)
{
if (hwInfoToken.IsCancellationRequested)
{
hwInfoToken.ThrowIfCancellationRequested();
}
HWInfo.ReadMem("HWINFO.INC");
FipHandler.RefreshHWInfoPages();
await Task.Delay(5 * 1000, _hwInfoTokenSource.Token); // repeat every 5 seconds
}
}, hwInfoToken);
});

}
Expand Down Expand Up @@ -639,6 +674,23 @@ protected override void OnExit(ExitEventArgs e)

_notifyIcon.Dispose(); //the icon would clean up automatically, but this is cleaner

_hwInfoTokenSource.Cancel();

var hwInfoToken = _hwInfoTokenSource.Token;

try
{
HWInfoTask?.Wait(hwInfoToken);
}
catch (OperationCanceledException)
{
Log.Info("HWInfo background task ended");
}
finally
{
_hwInfoTokenSource.Dispose();
}

_jsonTokenSource.Cancel();

var jsonToken = _jsonTokenSource.Token;
Expand Down
7 changes: 7 additions & 0 deletions Elite/Elite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<Compile Include="Audio\CachedSoundSampleProvider.cs" />
<Compile Include="CommunityGoals.cs" />
<Compile Include="Galnet.cs" />
<Compile Include="HWInfo.cs" />
<Compile Include="SystemInfo.cs" />
<Compile Include="Route.cs" />
<Compile Include="Cargo.cs" />
Expand Down Expand Up @@ -213,6 +214,9 @@
<None Include="Templates\cargo.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Templates\hwinfo.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Templates\galnet.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -271,6 +275,9 @@
<ItemGroup>
<Content Include="FodyWeavers.xml" />
<Resource Include="Hourglass.ico" />
<None Include="HWINFO.inc">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Content Include="Sounds\257357__brnck__button-click.wav">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
17 changes: 17 additions & 0 deletions Elite/FipHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Microsoft.Win32;

namespace Elite
Expand Down Expand Up @@ -115,6 +116,22 @@ public void RefreshSystemDevicePages()
}
}

public void RefreshHWInfoPages()
{
if (HWInfo.SensorData.Any())
{
for (var index = 0; index < _fipPanels.Count; index++)
{
var fipPanel = _fipPanels[index];

if (fipPanel.CurrentTab == LcdTab.HWInfo)
{
fipPanel.RefreshDevicePage();
}
}
}
}

private bool IsFipDevice(IntPtr device)
{
var mGuid = Guid.Empty;
Expand Down
Loading

0 comments on commit 1e5b19e

Please sign in to comment.