Skip to content

Commit

Permalink
add customvr.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Natsumi-sama committed May 31, 2024
1 parent 7023b64 commit f958751
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Dotnet/AppApi/AppApiVr.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using CefSharp;

namespace VRCX
Expand Down Expand Up @@ -70,5 +71,18 @@ public string CurrentCulture()
{
return CultureInfo.CurrentCulture.ToString();
}

/// <summary>
/// Returns the file path of the custom user js file, if it exists.
/// </summary>
/// <returns>The file path of the custom user js file, or an empty string if it doesn't exist.</returns>
public string CustomVrScriptPath()
{
var output = string.Empty;
var filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VRCX\\customvr.js");
if (File.Exists(filePath))
output = filePath;
return output;
}
}
}
17 changes: 17 additions & 0 deletions html/src/vr.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ Vue.component('marquee-text', MarqueeText);
currentTime: new Date().toJSON(),
cpuUsage: 0,
pcUptime: '',
customInfo: '',
config: {},
onlineFriendCount: 0,
nowPlaying: {
Expand Down Expand Up @@ -230,6 +231,7 @@ Vue.component('marquee-text', MarqueeText);
mounted() {
workerTimers.setTimeout(() => AppApiVr.VrInit(), 1000);
if (this.appType === '1') {
this.refreshCustomScript();
this.updateStatsLoop();
}
}
Expand Down Expand Up @@ -403,6 +405,21 @@ Vue.component('marquee-text', MarqueeText);
}
};

$app.methods.refreshCustomScript = function () {
if (document.contains(document.getElementById('vr-custom-script'))) {
document.getElementById('vr-custom-script').remove();
}
AppApiVr.CustomVrScriptPath().then((customScript) => {
var head = document.head;
if (customScript) {
var $vrCustomScript = document.createElement('script');
$vrCustomScript.setAttribute('id', 'vr-custom-script');
$vrCustomScript.src = `file://${customScript}?_=${Date.now()}`;
head.appendChild($vrCustomScript);
}
});
};

$app.methods.updateStatsLoop = async function () {
try {
this.currentTime = new Date()
Expand Down
2 changes: 1 addition & 1 deletion html/src/vr.pug
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ html
br
span(style="float:right") {{ currentTime }}
span(v-if="config && !config.hideCpuUsageFromFeed" style="display:inline-block;margin-right:5px") {{ $t('vr.status.cpu') }} {{ cpuUsage }}%
span(style="display:inline-block") {{ $t('vr.status.online') }} {{ onlineFriendCount }}
span(style="display:inline-block") {{ $t('vr.status.online') }} {{ onlineFriendCount }} ‎{{ customInfo }}
template(v-else)
svg(class="np-progress-circle")
circle(class="np-progress-circle-stroke" cx="60" cy="60" stroke="white" r="30" fill="transparent" stroke-width="60")
Expand Down

0 comments on commit f958751

Please sign in to comment.