Skip to content

Commit

Permalink
restart application 10 seconds after waking up from sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
mhwlng committed Oct 15, 2023
1 parent 9cf6d2f commit 9a10cdb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
34 changes: 33 additions & 1 deletion fipha/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using static fipha.SensorData;
using static fipha.NowPlayingData;
using System.Windows.Media;
using Microsoft.Win32;


// ReSharper disable StringLiteralTypo
Expand Down Expand Up @@ -96,6 +97,34 @@ private static void RunProcess(string fileName)
process.WaitForExit();
}

private async void OnPowerChange(object s, PowerModeChangedEventArgs e)
{
switch (e.Mode)
{
case PowerModes.Resume:

Log.Info($"Wake Up");

await Task.Run(() =>
{
Thread.Sleep(10000);

System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);
Application.Current.Shutdown();


});


break;
case PowerModes.Suspend:

Log.Info($"Go To Sleep");

break;
}
}

protected override void OnStartup(StartupEventArgs evtArgs)
{
const string appName = "fipha";
Expand All @@ -105,7 +134,7 @@ protected override void OnStartup(StartupEventArgs evtArgs)
if (!createdNew)
{
//app is already running! Exiting the application
Current.Shutdown();
//Current.Shutdown();
}

GetExePath();
Expand Down Expand Up @@ -484,6 +513,7 @@ await Task.Delay(MQTT.MqttPollingInterval,

});

SystemEvents.PowerModeChanged += OnPowerChange;
}


Expand Down Expand Up @@ -544,6 +574,8 @@ protected override void OnExit(ExitEventArgs e)
_hwInfoTokenSource.Dispose();
}

SystemEvents.PowerModeChanged += OnPowerChange;

Log.Info("exiting");

base.OnExit(e);
Expand Down
5 changes: 4 additions & 1 deletion fipha/Mqtt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ public static async Task<bool> Connect()

var options = _mqttSecure
? messageBuilder
.WithTls()
.WithTlsOptions(o =>
{

})
.Build()
: messageBuilder
.Build();
Expand Down
4 changes: 2 additions & 2 deletions fipha/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.1.5")]
[assembly: AssemblyFileVersion("0.0.1.5")]
[assembly: AssemblyVersion("0.0.1.6")]
[assembly: AssemblyFileVersion("0.0.1.6")]

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

0 comments on commit 9a10cdb

Please sign in to comment.