Update Cef 125.0.210, fix PerformanceCounter bugs

This commit is contained in:
Natsumi
2024-06-15 11:53:58 +12:00
parent 2d13d97ae4
commit fe12f615ba
13 changed files with 223 additions and 153 deletions

View File

@@ -40,6 +40,11 @@ namespace VRCX
ProcessMonitor.Instance.ProcessExited += Instance.OnProcessStateChanged; ProcessMonitor.Instance.ProcessExited += Instance.OnProcessStateChanged;
} }
public void Init()
{
// Create Instance before Cef tries to bind it
}
/// <summary> /// <summary>
/// Computes the MD5 hash of the file represented by the specified base64-encoded string. /// Computes the MD5 hash of the file represented by the specified base64-encoded string.
/// </summary> /// </summary>

View File

@@ -9,20 +9,15 @@ namespace VRCX
public class AppApiVr public class AppApiVr
{ {
public static readonly AppApiVr Instance; public static readonly AppApiVr Instance;
private static readonly PerformanceCounter Uptime;
static AppApiVr() static AppApiVr()
{ {
Instance = new AppApiVr(); Instance = new AppApiVr();
}
try public void Init()
{ {
Uptime = new PerformanceCounter("System", "System Up Time"); // Create Instance before Cef tries to bind it
}
catch
{
Uptime = null;
}
} }
public void VrInit() public void VrInit()
@@ -31,13 +26,18 @@ namespace VRCX
MainForm.Instance.Browser.ExecuteScriptAsync("$app.vrInit", ""); MainForm.Instance.Browser.ExecuteScriptAsync("$app.vrInit", "");
} }
public void ToggleSystemMonitor(bool enabled)
{
SystemMonitor.Instance.Start(enabled);
}
/// <summary> /// <summary>
/// Returns the current CPU usage as a percentage. /// Returns the current CPU usage as a percentage.
/// </summary> /// </summary>
/// <returns>The current CPU usage as a percentage.</returns> /// <returns>The current CPU usage as a percentage.</returns>
public float CpuUsage() public float CpuUsage()
{ {
return CpuMonitor.Instance.CpuUsage; return SystemMonitor.Instance.CpuUsage;
} }
/// <summary> /// <summary>
@@ -56,11 +56,7 @@ namespace VRCX
/// <returns>The number of milliseconds that the system has been running.</returns> /// <returns>The number of milliseconds that the system has been running.</returns>
public double GetUptime() public double GetUptime()
{ {
if (Uptime == null) return SystemMonitor.Instance.UpTime;
return 0;
Uptime.NextValue();
return TimeSpan.FromSeconds(Uptime.NextValue()).TotalMilliseconds;
} }
/// <summary> /// <summary>

View File

@@ -15,10 +15,10 @@ namespace VRCX
return true; return true;
} }
public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback) public bool OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
{ {
if (callback.IsDisposed) if (callback.IsDisposed)
return; return true;
using (callback) using (callback)
{ {
@@ -27,6 +27,8 @@ namespace VRCX
showDialog: true showDialog: true
); );
} }
return true;
} }
public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)

View File

@@ -1,90 +0,0 @@
// Copyright(c) 2019-2022 pypy, Natsumi and individual contributors.
// All rights reserved.
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
using System.Diagnostics;
using System.Threading;
namespace VRCX
{
public class CpuMonitor
{
public static readonly CpuMonitor Instance;
public float CpuUsage;
private readonly PerformanceCounter _performanceCounter;
private readonly Timer _timer;
static CpuMonitor()
{
Instance = new CpuMonitor();
}
public CpuMonitor()
{
try
{
_performanceCounter = new PerformanceCounter(
"Processor Information",
"% Processor Utility",
"_Total",
true
);
}
catch
{
}
// fallback
if (_performanceCounter == null)
{
try
{
_performanceCounter = new PerformanceCounter(
"Processor",
"% Processor Time",
"_Total",
true
);
}
catch
{
}
}
_timer = new Timer(TimerCallback, null, -1, -1);
}
internal void Init()
{
_timer.Change(1000, 1000);
}
internal void Exit()
{
lock (this)
{
_timer.Change(-1, -1);
_performanceCounter?.Dispose();
}
}
private void TimerCallback(object state)
{
lock (this)
{
try
{
if (_performanceCounter != null)
{
CpuUsage = _performanceCounter.NextValue();
}
}
catch
{
}
}
}
}
}

View File

@@ -65,7 +65,7 @@ namespace VRCX
if (m_Client == null && m_Active) if (m_Client == null && m_Active)
{ {
m_Client = new DiscordRpcClient(DiscordAppId); m_Client = new DiscordRpcClient(DiscordAppId);
if (m_Client.Initialize() == false) if (!m_Client.Initialize())
{ {
m_Client.Dispose(); m_Client.Dispose();
m_Client = null; m_Client = null;
@@ -117,8 +117,9 @@ namespace VRCX
public void SetText(string details, string state) public void SetText(string details, string state)
{ {
if (m_Client != null && !m_Lock.IsReadLockHeld) if (m_Client == null || m_Lock.IsReadLockHeld)
{ return;
m_Lock.EnterWriteLock(); m_Lock.EnterWriteLock();
try try
{ {
@@ -130,24 +131,21 @@ namespace VRCX
m_Lock.ExitWriteLock(); m_Lock.ExitWriteLock();
} }
} }
}
public void SetAssets(string largeKey, string largeText, string smallKey, string smallText, string partyId, int partySize, int partyMax, string buttonText, string buttonUrl, string appId) public void SetAssets(string largeKey, string largeText, string smallKey, string smallText, string partyId, int partySize, int partyMax, string buttonText, string buttonUrl, string appId)
{ {
m_Lock.EnterWriteLock(); m_Lock.EnterWriteLock();
try try
{ {
if (string.IsNullOrEmpty(largeKey) == true && if (string.IsNullOrEmpty(largeKey) &&
string.IsNullOrEmpty(smallKey) == true) string.IsNullOrEmpty(smallKey))
{ {
m_Presence.Assets = null; m_Presence.Assets = null;
} }
else else
{ {
if (m_Presence.Assets == null) m_Presence.Assets ??= new Assets();
m_Presence.Assets = new Assets(); m_Presence.Party ??= new Party();
if (m_Presence.Party == null)
m_Presence.Party = new Party();
m_Presence.Assets.LargeImageKey = largeKey; m_Presence.Assets.LargeImageKey = largeKey;
m_Presence.Assets.LargeImageText = largeText; m_Presence.Assets.LargeImageText = largeText;
m_Presence.Assets.SmallImageKey = smallKey; m_Presence.Assets.SmallImageKey = smallKey;
@@ -155,15 +153,15 @@ namespace VRCX
m_Presence.Party.ID = partyId; m_Presence.Party.ID = partyId;
m_Presence.Party.Size = partySize; m_Presence.Party.Size = partySize;
m_Presence.Party.Max = partyMax; m_Presence.Party.Max = partyMax;
Button[] Buttons = { }; Button[] buttons = [];
if (!string.IsNullOrEmpty(buttonUrl)) if (!string.IsNullOrEmpty(buttonUrl))
{ {
Buttons = new Button[] buttons =
{ [
new Button() { Label = buttonText, Url = buttonUrl } new Button { Label = buttonText, Url = buttonUrl }
}; ];
} }
m_Presence.Buttons = Buttons; m_Presence.Buttons = buttons;
if (DiscordAppId != appId) if (DiscordAppId != appId)
{ {
DiscordAppId = appId; DiscordAppId = appId;
@@ -196,11 +194,7 @@ namespace VRCX
} }
else else
{ {
if (m_Presence.Timestamps == null) m_Presence.Timestamps ??= new Timestamps();
{
m_Presence.Timestamps = new Timestamps();
}
m_Presence.Timestamps.StartUnixMilliseconds = _startUnixMilliseconds; m_Presence.Timestamps.StartUnixMilliseconds = _startUnixMilliseconds;
if (_endUnixMilliseconds == 0) if (_endUnixMilliseconds == 0)

View File

@@ -144,7 +144,8 @@ namespace VRCX
ProcessMonitor.Instance.Init(); ProcessMonitor.Instance.Init();
VRCXStorage.Load(); VRCXStorage.Load();
SQLiteLegacy.Instance.Init(); SQLiteLegacy.Instance.Init();
CpuMonitor.Instance.Init(); AppApi.Instance.Init();
AppApiVr.Instance.Init();
Discord.Instance.Init(); Discord.Instance.Init();
WorldDBManager.Instance.Init(); WorldDBManager.Instance.Init();
WebApi.Instance.Init(); WebApi.Instance.Init();
@@ -166,7 +167,7 @@ namespace VRCX
WorldDBManager.Instance.Stop(); WorldDBManager.Instance.Stop();
Discord.Instance.Exit(); Discord.Instance.Exit();
CpuMonitor.Instance.Exit(); SystemMonitor.Instance.Exit();
VRCXStorage.Save(); VRCXStorage.Save();
SQLiteLegacy.Instance.Exit(); SQLiteLegacy.Instance.Exit();
ProcessMonitor.Instance.Exit(); ProcessMonitor.Instance.Exit();

151
Dotnet/SystemMonitor.cs Normal file
View File

@@ -0,0 +1,151 @@
// Copyright(c) 2019-2022 pypy, Natsumi and individual contributors.
// All rights reserved.
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
using System;
using System.Diagnostics;
using System.Threading;
using NLog;
namespace VRCX
{
public class SystemMonitor
{
public static readonly SystemMonitor Instance;
public float CpuUsage;
public double UpTime;
private bool _enabled;
private PerformanceCounter _performanceCounterCpuUsage;
private PerformanceCounter _performanceCounterUpTime;
private Thread _thread;
private static readonly NLog.Logger logger = NLog.LogManager.GetLogger("VRCX");
static SystemMonitor()
{
Instance = new SystemMonitor();
}
public void Start(bool enabled)
{
if (enabled == _enabled)
return;
_enabled = enabled;
if (enabled)
StartThread();
else
Exit();
}
internal void Exit()
{
CpuUsage = 0;
UpTime = 0;
try
{
if (_thread != null)
{
_thread.Interrupt();
_thread.Join();
_thread = null;
}
}
catch (ThreadInterruptedException)
{
}
_performanceCounterCpuUsage?.Dispose();
_performanceCounterCpuUsage = null;
_performanceCounterUpTime?.Dispose();
_performanceCounterUpTime = null;
}
private void StartThread()
{
Exit();
try
{
_performanceCounterCpuUsage = new PerformanceCounter(
"Processor Information",
"% Processor Utility",
"_Total",
true
);
_performanceCounterCpuUsage?.NextValue();
}
catch (Exception ex)
{
logger.Warn($"Failed to create \"Processor Utility\" PerformanceCounter ${ex}");
}
// fallback
if (_performanceCounterCpuUsage == null)
{
try
{
_performanceCounterCpuUsage = new PerformanceCounter(
"Processor",
"% Processor Time",
"_Total",
true
);
_performanceCounterCpuUsage?.NextValue();
}
catch (Exception ex)
{
logger.Warn($"Failed to create \"Processor Time\" PerformanceCounter ${ex}");
}
}
try
{
_performanceCounterUpTime = new PerformanceCounter("System", "System Up Time");
_performanceCounterUpTime?.NextValue();
}
catch
{
logger.Warn("Failed to create \"System Up Time\" PerformanceCounter");
}
if (_performanceCounterCpuUsage == null &&
_performanceCounterUpTime == null)
{
logger.Error("Failed to create any PerformanceCounter");
return;
}
logger.Info("SystemMonitor started");
_thread = new Thread(ThreadProc)
{
IsBackground = true
};
_thread.Start();
}
private void ThreadProc()
{
try
{
while (_enabled)
{
if (_performanceCounterCpuUsage != null)
CpuUsage = _performanceCounterCpuUsage.NextValue();
if (_performanceCounterUpTime != null)
UpTime = TimeSpan.FromSeconds(_performanceCounterUpTime.NextValue()).TotalMilliseconds;
Thread.Sleep(1000);
}
}
catch (Exception ex)
{
logger.Warn($"SystemMonitor thread exception: {ex}");
}
Exit();
}
}
}

View File

@@ -119,8 +119,8 @@
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CefSharp.OffScreen.NETCore" Version="124.3.80" /> <PackageReference Include="CefSharp.OffScreen.NETCore" Version="125.0.210" />
<PackageReference Include="CefSharp.WinForms.NETCore" Version="124.3.80" /> <PackageReference Include="CefSharp.WinForms.NETCore" Version="125.0.210" />
<PackageReference Include="DiscordRichPresence" Version="1.2.1.24" /> <PackageReference Include="DiscordRichPresence" Version="1.2.1.24" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" /> <PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

View File

@@ -15225,8 +15225,8 @@ speechSynthesis.getVoices();
'VRCX_hideDevicesFromFeed', 'VRCX_hideDevicesFromFeed',
false false
); );
$app.data.hideCpuUsageFromFeed = await configRepository.getBool( $app.data.vrOverlayCpuUsage = await configRepository.getBool(
'VRCX_hideCpuUsageFromFeed', 'VRCX_vrOverlayCpuUsage',
false false
); );
$app.data.hideUptimeFromFeed = await configRepository.getBool( $app.data.hideUptimeFromFeed = await configRepository.getBool(
@@ -15429,8 +15429,8 @@ speechSynthesis.getVoices();
this.hideDevicesFromFeed this.hideDevicesFromFeed
); );
await configRepository.setBool( await configRepository.setBool(
'VRCX_hideCpuUsageFromFeed', 'VRCX_vrOverlayCpuUsage',
this.hideCpuUsageFromFeed this.vrOverlayCpuUsage
); );
await configRepository.setBool( await configRepository.setBool(
'VRCX_hideUptimeFromFeed', 'VRCX_hideUptimeFromFeed',
@@ -16155,7 +16155,7 @@ speechSynthesis.getVoices();
var VRConfigVars = { var VRConfigVars = {
overlayNotifications: this.overlayNotifications, overlayNotifications: this.overlayNotifications,
hideDevicesFromFeed: this.hideDevicesFromFeed, hideDevicesFromFeed: this.hideDevicesFromFeed,
hideCpuUsageFromFeed: this.hideCpuUsageFromFeed, vrOverlayCpuUsage: this.vrOverlayCpuUsage,
minimalFeed: this.minimalFeed, minimalFeed: this.minimalFeed,
notificationPosition: this.notificationPosition, notificationPosition: this.notificationPosition,
notificationTimeout: this.notificationTimeout, notificationTimeout: this.notificationTimeout,

View File

@@ -374,7 +374,7 @@
"background_color": "Background Color", "background_color": "Background Color",
"minimal_feed_icons": "Minimal Feed Icons", "minimal_feed_icons": "Minimal Feed Icons",
"hide_vr_devices": "Hide VR Devices", "hide_vr_devices": "Hide VR Devices",
"hide_cpu_usage": "Hide CPU Usage", "show_cpu_usage": "Show CPU Usage",
"hide_game_uptime": "Hide Game Uptime", "hide_game_uptime": "Hide Game Uptime",
"show_pc_uptime": "Show PC Uptime", "show_pc_uptime": "Show PC Uptime",
"wrist_feed_filters": "Wrist Feed Filters" "wrist_feed_filters": "Wrist Feed Filters"

View File

@@ -372,8 +372,8 @@ mixin settingsTab()
span.name {{ $t('view.settings.wrist_overlay.steamvr_wrist_overlay.hide_vr_devices') }} span.name {{ $t('view.settings.wrist_overlay.steamvr_wrist_overlay.hide_vr_devices') }}
el-switch(v-model="hideDevicesFromFeed" @change="saveOpenVROption" :disabled="!openVR || !overlayWrist") el-switch(v-model="hideDevicesFromFeed" @change="saveOpenVROption" :disabled="!openVR || !overlayWrist")
div.options-container-item div.options-container-item
span.name {{ $t('view.settings.wrist_overlay.steamvr_wrist_overlay.hide_cpu_usage') }} span.name {{ $t('view.settings.wrist_overlay.steamvr_wrist_overlay.show_cpu_usage') }}
el-switch(v-model="hideCpuUsageFromFeed" @change="saveOpenVROption" :disabled="!openVR || !overlayWrist") el-switch(v-model="vrOverlayCpuUsage" @change="saveOpenVROption" :disabled="!openVR || !overlayWrist")
div.options-container-item div.options-container-item
span.name {{ $t('view.settings.wrist_overlay.steamvr_wrist_overlay.hide_game_uptime') }} span.name {{ $t('view.settings.wrist_overlay.steamvr_wrist_overlay.hide_game_uptime') }}
el-switch(v-model="hideUptimeFromFeed" @change="saveOpenVROption" :disabled="!openVR || !overlayWrist") el-switch(v-model="hideUptimeFromFeed" @change="saveOpenVROption" :disabled="!openVR || !overlayWrist")

View File

@@ -194,8 +194,11 @@ Vue.component('marquee-text', MarqueeText);
// 2 = 항상 화면에 보이는 거 // 2 = 항상 화면에 보이는 거
appType: location.href.substr(-1), appType: location.href.substr(-1),
appLanguage: 'en', appLanguage: 'en',
currentCulture: 'en-nz',
currentTime: new Date().toJSON(), currentTime: new Date().toJSON(),
cpuUsageEnabled: false,
cpuUsage: 0, cpuUsage: 0,
pcUptimeEnabled: false,
pcUptime: '', pcUptime: '',
customInfo: '', customInfo: '',
config: {}, config: {},
@@ -351,6 +354,16 @@ Vue.component('marquee-text', MarqueeText);
this.setDatetimeFormat(); this.setDatetimeFormat();
this.setAppLanguage(this.config.appLanguage); this.setAppLanguage(this.config.appLanguage);
this.updateFeedLength(); this.updateFeedLength();
if (
this.config.vrOverlayCpuUsage !== this.cpuUsageEnabled ||
this.config.pcUptimeOnFeed !== this.pcUptimeEnabled
) {
this.cpuUsageEnabled = this.config.vrOverlayCpuUsage;
this.pcUptimeEnabled = this.config.pcUptimeOnFeed;
AppApiVr.ToggleSystemMonitor(
this.cpuUsageEnabled || this.pcUptimeEnabled
);
}
}; };
$app.methods.updateOnlineFriendCount = function (count) { $app.methods.updateOnlineFriendCount = function (count) {
@@ -435,7 +448,7 @@ Vue.component('marquee-text', MarqueeText);
.replace(' PM', ' pm') .replace(' PM', ' pm')
.replace(',', ''); .replace(',', '');
if (!this.config.hideCpuUsageFromFeed) { if (this.cpuUsageEnabled) {
var cpuUsage = await AppApiVr.CpuUsage(); var cpuUsage = await AppApiVr.CpuUsage();
this.cpuUsage = cpuUsage.toFixed(0); this.cpuUsage = cpuUsage.toFixed(0);
} }
@@ -802,8 +815,6 @@ Vue.component('marquee-text', MarqueeText);
this.hudTimeout = JSON.parse(json); this.hudTimeout = JSON.parse(json);
}; };
$app.data.currentCulture = await AppApiVr.CurrentCulture();
$app.methods.setDatetimeFormat = async function () { $app.methods.setDatetimeFormat = async function () {
this.currentCulture = await AppApiVr.CurrentCulture(); this.currentCulture = await AppApiVr.CurrentCulture();
var formatDate = function (date) { var formatDate = function (date) {

View File

@@ -532,7 +532,7 @@ html
span(style="display:inline-block;font-weight:bold") {{ lastLocation.friendList.length !== 0 ? ` (${lastLocation.friendList.length})` : ''}} span(style="display:inline-block;font-weight:bold") {{ lastLocation.friendList.length !== 0 ? ` (${lastLocation.friendList.length})` : ''}}
br br
span(style="float:right") {{ currentTime }} span(style="float:right") {{ currentTime }}
span(v-if="config && !config.hideCpuUsageFromFeed" style="display:inline-block;margin-right:5px") {{ $t('vr.status.cpu') }} {{ cpuUsage }}% span(v-if="config && cpuUsageEnabled" style="display:inline-block;margin-right:5px") {{ $t('vr.status.cpu') }} {{ cpuUsage }}%
span(style="display:inline-block") {{ $t('vr.status.online') }} {{ onlineFriendCount }} {{ customInfo }} span(style="display:inline-block") {{ $t('vr.status.online') }} {{ onlineFriendCount }} {{ customInfo }}
template(v-else) template(v-else)
svg(class="np-progress-circle") svg(class="np-progress-circle")