Skip to content

Commit

Permalink
Game Activity stopped tracking play time on desktop #99
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacro59 committed Jan 24, 2022
1 parent ef25652 commit 2cd1200
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
47 changes: 36 additions & 11 deletions source/GameActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ public class GameActivity : PluginExtended<GameActivitySettingsViewModel, Activi
public System.Timers.Timer tBackup { get; set; }
private ActivityBackup activityBackup { get; set; }

private ulong PlaytimeOnStarted { get; set; }

//private OldToNew oldToNew;


public GameActivity(IPlayniteAPI api) : base(api)
{
// Old database
Expand Down Expand Up @@ -1002,6 +1005,8 @@ public override void OnGameStarting(OnGameStartingEventArgs args)
// Add code to be executed when game is started running.
public override void OnGameStarted(OnGameStartedEventArgs args)
{
PlaytimeOnStarted = args.Game.Playtime;

DataBackup_start();

// start timer si log is enable.
Expand Down Expand Up @@ -1041,21 +1046,41 @@ public override void OnGameStopped(OnGameStoppedEventArgs args)
{
var TaskGameStopped = Task.Run(() =>
{
DataBackup_stop();
// Stop timer si HWiNFO log is enable.
if (PluginSettings.Settings.EnableLogging)
try
{
DataLogging_stop();
}
DataBackup_stop();
// Infos
GameActivitiesLog.GetLastSessionActivity().ElapsedSeconds = args.ElapsedSeconds;
PluginDatabase.Update(GameActivitiesLog);
// Stop timer si HWiNFO log is enable.
if (PluginSettings.Settings.EnableLogging)
{
DataLogging_stop();
}
if (args.Game.Id == PluginDatabase.GameContext.Id)
ulong ElapsedSeconds = args.ElapsedSeconds;
if (ElapsedSeconds == 0)
{
Thread.Sleep(5000);
ElapsedSeconds = args.Game.Playtime - PlaytimeOnStarted;
PlayniteApi.Notifications.Add(new NotificationMessage(
$"gameactivity-noElapsedSeconds",
$"GameActivity" + System.Environment.NewLine + string.Format(resources.GetString("LOCGameActivityNoPlaytime"), args.Game.Name, ElapsedSeconds),
NotificationType.Info
));
}
// Infos
GameActivitiesLog.GetLastSessionActivity().ElapsedSeconds = ElapsedSeconds;
PluginDatabase.Update(GameActivitiesLog);
if (args.Game.Id == PluginDatabase.GameContext.Id)
{
PluginDatabase.SetThemesResources(PluginDatabase.GameContext);
}
}
catch (Exception ex)
{
PluginDatabase.SetThemesResources(PluginDatabase.GameContext);
Common.LogError(ex, false, true, PluginDatabase.PluginName);
}
});

Expand Down
4 changes: 4 additions & 0 deletions source/Localization/LocSource.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0"?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib">

<sys:String x:Key="LOCGameActivityNoPlaytime" xml:space="preserve">There is no play time for {0}.
Used the difference play time: {1}s.</sys:String>


<!-- MainView -->

<sys:String x:Key="LOCGameActivity">GameActivity</sys:String>
Expand Down

0 comments on commit 2cd1200

Please sign in to comment.