From 913ccafd5f4cb4511a31386dc1b6e8f437068e61 Mon Sep 17 00:00:00 2001 From: Greg Date: Sat, 18 Feb 2023 16:42:07 -0700 Subject: [PATCH] Make applications actually disable when the target is offline. --- Playstation/OrbisLibAPI/Version.h | 22 ++-- .../OrbisNeighborHood/Controls/AppPanel.xaml | 8 +- .../Controls/AppPanel.xaml.cs | 110 ++++++++++++------ .../MVVM/View/AppListView.xaml.cs | 4 +- .../Resources/BuildNumber.txt | 2 +- .../Resources/BuildString.txt | 2 +- 6 files changed, 94 insertions(+), 54 deletions(-) diff --git a/Playstation/OrbisLibAPI/Version.h b/Playstation/OrbisLibAPI/Version.h index b750bf9..c8a5b66 100644 --- a/Playstation/OrbisLibAPI/Version.h +++ b/Playstation/OrbisLibAPI/Version.h @@ -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 diff --git a/Windows/OrbisNeighborHood/Controls/AppPanel.xaml b/Windows/OrbisNeighborHood/Controls/AppPanel.xaml index b898dd3..12b153d 100644 --- a/Windows/OrbisNeighborHood/Controls/AppPanel.xaml +++ b/Windows/OrbisNeighborHood/Controls/AppPanel.xaml @@ -180,14 +180,14 @@ Click="ChangeIcon_Click" Grid.Column="6"/> - - + diff --git a/Windows/OrbisNeighborHood/Controls/AppPanel.xaml.cs b/Windows/OrbisNeighborHood/Controls/AppPanel.xaml.cs index 191146b..da2c684 100644 --- a/Windows/OrbisNeighborHood/Controls/AppPanel.xaml.cs +++ b/Windows/OrbisNeighborHood/Controls/AppPanel.xaml.cs @@ -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 /// 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 diff --git a/Windows/OrbisNeighborHood/MVVM/View/AppListView.xaml.cs b/Windows/OrbisNeighborHood/MVVM/View/AppListView.xaml.cs index f1220de..658efb4 100644 --- a/Windows/OrbisNeighborHood/MVVM/View/AppListView.xaml.cs +++ b/Windows/OrbisNeighborHood/MVVM/View/AppListView.xaml.cs @@ -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); diff --git a/Windows/OrbisNeighborHood/Resources/BuildNumber.txt b/Windows/OrbisNeighborHood/Resources/BuildNumber.txt index 5e84f34..47fe54a 100644 --- a/Windows/OrbisNeighborHood/Resources/BuildNumber.txt +++ b/Windows/OrbisNeighborHood/Resources/BuildNumber.txt @@ -1 +1 @@ -2676 +2685 diff --git a/Windows/OrbisNeighborHood/Resources/BuildString.txt b/Windows/OrbisNeighborHood/Resources/BuildString.txt index 343ea2d..53172a6 100644 --- a/Windows/OrbisNeighborHood/Resources/BuildString.txt +++ b/Windows/OrbisNeighborHood/Resources/BuildString.txt @@ -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