Make applications actually disable when the target is offline.

This commit is contained in:
Greg
2023-02-18 16:42:07 -07:00
parent a1248d114f
commit 913ccafd5f
6 changed files with 94 additions and 54 deletions
+11 -11
View File
@@ -1,11 +1,11 @@
#pragma once
#define ORBISLIB_MAJOR 3
#define ORBISLIB_MINOR 0
#define ORBISLIB_BUILDVERSION 1141
#define stringify(a) stringify_(a)
#define stringify_(a) #a
#if defined(_DEBUG)
#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Dev Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__)
#else
#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__)
#endif
#pragma once
#define ORBISLIB_MAJOR 3
#define ORBISLIB_MINOR 0
#define ORBISLIB_BUILDVERSION 1144
#define stringify(a) stringify_(a)
#define stringify_(a) #a
#if defined(_DEBUG)
#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Dev Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__)
#else
#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__)
#endif
@@ -180,14 +180,14 @@
Click="ChangeIcon_Click"
Grid.Column="6"/>
<!-- OpenStore -->
<local:ImageButton x:Name="OpenStore"
<!-- SetAsFocus -->
<local:ImageButton x:Name="SetAsFocus"
Width="35"
Height="35"
ToolTip="Open in Playstation store."
ToolTip="Set this app as the main focus."
ImageSource="/OrbisNeighborHood;component/Images/Store.png"
ImageMargin="4"
Click="OpenStore_Click"
Click="SetAsFocus_Click"
Grid.Column="8"/>
<!-- More Info -->
@@ -1,5 +1,6 @@
using OrbisLib2.Common.API;
using OrbisLib2.Common.Database.App;
using OrbisLib2.Common.Database.Types;
using OrbisLib2.General;
using OrbisLib2.Targets;
using System;
@@ -19,7 +20,8 @@ namespace OrbisNeighborHood.Controls
/// </summary>
public partial class AppPanel : UserControl
{
public AppBrowse App;
public AppBrowse _App;
private string _AppVersion;
private AppState AppState = AppState.STATE_NOT_RUNNING;
private VisibilityType Visible = VisibilityType.VT_NONE;
@@ -28,13 +30,59 @@ namespace OrbisNeighborHood.Controls
{
InitializeComponent();
this.App = App;
_App = App;
_AppVersion = AppVersion;
// Update Application information.
Update(App, AppVersion);
// Start background task to periodically check if this application is currently running.
Task.Run(() => UpdateApp());
var currentTarget = TargetManager.SelectedTarget;
EnableTargetOptions(currentTarget.Info.Status == TargetStatusType.APIAvailable);
Events.TargetStateChanged += Events_TargetStateChanged;
Events.DBTouched += Events_DBTouched;
Events.SelectedTargetChanged += Events_SelectedTargetChanged; ;
}
private void EnableTargetOptions(bool state)
{
Dispatcher.Invoke(() =>
{
if (!state)
{
StartStop.IsEnabled = state;
SuspendResume.IsEnabled = state;
}
Visibility.IsEnabled = state;
ChangeIcon.IsEnabled = state;
SetAsFocus.IsEnabled = state;
Delete.IsEnabled = state;
if (!state)
{
Update(_App, _AppVersion);
}
});
}
private void Events_SelectedTargetChanged(object? sender, SelectedTargetChangedEvent e)
{
var currentTarget = TargetManager.SelectedTarget;
EnableTargetOptions(currentTarget.Info.Status == TargetStatusType.APIAvailable);
}
private void Events_DBTouched(object? sender, DBTouchedEvent e)
{
var currentTarget = TargetManager.SelectedTarget;
EnableTargetOptions(currentTarget.Info.Status == TargetStatusType.APIAvailable);
}
private void Events_TargetStateChanged(object? sender, TargetStateChangedEvent e)
{
EnableTargetOptions(e.State == TargetStateChangedEvent.TargetState.APIAvailable);
}
public void Update(AppBrowse App, string AppVersion)
@@ -82,8 +130,14 @@ namespace OrbisNeighborHood.Controls
{
var currentTarget = TargetManager.SelectedTarget;
if (currentTarget.Info.Status != TargetStatusType.APIAvailable)
{
Thread.Sleep(2000);
continue;
}
// Get Current App status.
var newAppState = currentTarget.Application.GetAppState(App.TitleId);
var newAppState = currentTarget.Application.GetAppState(_App.TitleId);
if (newAppState >= 0)
AppState = newAppState;
@@ -92,18 +146,18 @@ namespace OrbisNeighborHood.Controls
{
Dispatcher.Invoke(() =>
{
StartStop.ToolTip = $"Stop {App.TitleName}.";
StartStop.ToolTip = $"Stop {_App.TitleName}.";
StartStop.ImageSource = "/OrbisNeighborHood;component/Images/Stop.png";
SuspendResume.IsEnabled = true;
if (AppState == AppState.STATE_SUSPENDED)
{
SuspendResume.ToolTip = $"Resume {App.TitleName}.";
SuspendResume.ToolTip = $"Resume {_App.TitleName}.";
SuspendResume.ImageSource = "/OrbisNeighborHood;component/Images/Start.png";
}
else
{
SuspendResume.ToolTip = $"Suspend {App.TitleName}.";
SuspendResume.ToolTip = $"Suspend {_App.TitleName}.";
SuspendResume.ImageSource = "/OrbisNeighborHood;component/Images/Suspend.png";
}
});
@@ -112,24 +166,24 @@ namespace OrbisNeighborHood.Controls
{
Dispatcher.Invoke(() =>
{
StartStop.ToolTip = $"Start {App.TitleName}.";
StartStop.ToolTip = $"Start {_App.TitleName}.";
StartStop.ImageSource = "/OrbisNeighborHood;component/Images/Start.png";
SuspendResume.ToolTip = $"Not available while {App.TitleName} is not running.";
SuspendResume.ToolTip = $"Not available while {_App.TitleName} is not running.";
SuspendResume.ImageSource = "/OrbisNeighborHood;component/Images/UnAvailable.png";
SuspendResume.IsEnabled = false;
});
}
// App Visibility.
//Visible = currentTarget.Application.GetVisibility(App.TitleId);
// App Visibility. TODO: fix db corruption.
//Visible = currentTarget.Application.GetVisibility(_App.TitleId);
if (Visible == VisibilityType.VT_NONE || Visible == VisibilityType.VT_INVISIBLE)
{
Dispatcher.Invoke(() => Visibility.ToolTip = $"Show {App.TitleName} from Home Menu.");
Dispatcher.Invoke(() => Visibility.ToolTip = $"Show {_App.TitleName} from Home Menu.");
}
else
{
Dispatcher.Invoke(() => Visibility.ToolTip = $"Hide {App.TitleName} from Home Menu.");
Dispatcher.Invoke(() => Visibility.ToolTip = $"Hide {_App.TitleName} from Home Menu.");
}
Thread.Sleep(1000);
@@ -145,11 +199,11 @@ namespace OrbisNeighborHood.Controls
var currentTarget = TargetManager.SelectedTarget;
if (AppState == AppState.STATE_RUNNING || AppState == AppState.STATE_SUSPENDED)
{
currentTarget.Application.Stop(App.TitleId);
currentTarget.Application.Stop(_App.TitleId);
}
else
{
currentTarget.Application.Start(App.TitleId);
currentTarget.Application.Start(_App.TitleId);
}
});
}
@@ -161,11 +215,11 @@ namespace OrbisNeighborHood.Controls
var currentTarget = TargetManager.SelectedTarget;
if (AppState == AppState.STATE_SUSPENDED)
{
currentTarget.Application.Resume(App.TitleId);
currentTarget.Application.Resume(_App.TitleId);
}
else
{
currentTarget.Application.Suspend(App.TitleId);
currentTarget.Application.Suspend(_App.TitleId);
}
});
}
@@ -177,14 +231,14 @@ namespace OrbisNeighborHood.Controls
var currentTarget = TargetManager.SelectedTarget;
if (Visible == VisibilityType.VT_NONE || Visible == VisibilityType.VT_INVISIBLE)
{
if(currentTarget.Application.SetVisibility(App.TitleId, VisibilityType.VT_VISIBLE))
if(currentTarget.Application.SetVisibility(_App.TitleId, VisibilityType.VT_VISIBLE))
{
Visible = VisibilityType.VT_VISIBLE;
}
}
else
{
if(currentTarget.Application.SetVisibility(App.TitleId, VisibilityType.VT_INVISIBLE))
if(currentTarget.Application.SetVisibility(_App.TitleId, VisibilityType.VT_INVISIBLE))
{
Visible = VisibilityType.VT_INVISIBLE;
}
@@ -197,23 +251,9 @@ namespace OrbisNeighborHood.Controls
}
private void OpenStore_Click(object sender, RoutedEventArgs e)
private void SetAsFocus_Click(object sender, RoutedEventArgs e)
{
try
{
var Title = new TMDB(App.TitleId);
var url = $"https://store.playstation.com/product/{Title.ContentID}/";
System.Diagnostics.Process.Start(new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});
}
catch
{
}
}
private void MoreInfo_Click(object sender, RoutedEventArgs e)
@@ -224,7 +264,7 @@ namespace OrbisNeighborHood.Controls
private void Delete_Click(object sender, RoutedEventArgs e)
{
// TODO: Add are you sure?
Task.Run(() => TargetManager.SelectedTarget.Application.Delete(App.TitleId));
Task.Run(() => TargetManager.SelectedTarget.Application.Delete(_App.TitleId));
}
#endregion
@@ -170,7 +170,7 @@ namespace OrbisNeighborHood.MVVM.View
Dispatcher.Invoke(() =>
{
var pannel = PanelList.Find(x => x.App.TitleId == app.TitleId);
var pannel = PanelList.Find(x => x._App.TitleId == app.TitleId);
if(pannel != null)
{
pannel.Update(app, appVersion);
@@ -185,7 +185,7 @@ namespace OrbisNeighborHood.MVVM.View
// Check to remove apps.
Parallel.ForEach(PanelList, panel =>
{
var app = appList.Find(x => x.TitleId == panel.App.TitleId);
var app = appList.Find(x => x.TitleId == panel._App.TitleId);
if(app == null)
{
PanelList.Remove(panel);
@@ -1 +1 @@
2676
2685
@@ -1 +1 @@
Version 3.0.2676 Debug Build Saturday February 18 2023 3:43 PM
Version 3.0.2685 Debug Build Saturday February 18 2023 4:24 PM