make singleton

This commit is contained in:
pypy
2020-03-21 16:39:35 +09:00
parent 336241c4c7
commit a9d454308b
6 changed files with 36 additions and 5 deletions

View File

@@ -10,11 +10,17 @@ namespace VRCX
{
public class Discord
{
public static Discord Instance { get; private set; }
private static readonly ReaderWriterLockSlim m_Lock = new ReaderWriterLockSlim();
private static readonly RichPresence m_Presence = new RichPresence();
private static Thread m_Thread;
private static bool m_Active;
static Discord()
{
Instance = new Discord();
}
public static void Init()
{
m_Thread = new Thread(() =>

View File

@@ -20,6 +20,7 @@ namespace VRCX
public class LogWatcher
{
public static LogWatcher Instance { get; private set; }
private static readonly ReaderWriterLockSlim m_Lock = new ReaderWriterLockSlim();
private static List<string[]> m_GameLog = new List<string[]>();
private static Thread m_Thread;
@@ -28,6 +29,11 @@ namespace VRCX
// NOTE
// FileSystemWatcher() is unreliable
static LogWatcher()
{
Instance = new LogWatcher();
}
public static void Init()
{
m_Thread = new Thread(() =>

View File

@@ -41,11 +41,11 @@ namespace VRCX
{
CamelCaseJavascriptNames = false
};
Browser.JavascriptObjectRepository.Register("VRCX", new VRCX(), true, options);
Browser.JavascriptObjectRepository.Register("VRCXStorage", new VRCXStorage(), false, options);
Browser.JavascriptObjectRepository.Register("SQLite", new SQLite(), true, options);
Browser.JavascriptObjectRepository.Register("LogWatcher", new LogWatcher(), true, options);
Browser.JavascriptObjectRepository.Register("Discord", new Discord(), true, options);
Browser.JavascriptObjectRepository.Register("VRCX", VRCX.Instance, true, options);
Browser.JavascriptObjectRepository.Register("VRCXStorage", VRCXStorage.Instance, false, options);
Browser.JavascriptObjectRepository.Register("SQLite", SQLite.Instance, true, options);
Browser.JavascriptObjectRepository.Register("LogWatcher", LogWatcher.Instance, true, options);
Browser.JavascriptObjectRepository.Register("Discord", Discord.Instance, true, options);
Browser.IsBrowserInitializedChanged += (A, B) =>
{
// Browser.ShowDevTools();

View File

@@ -9,9 +9,15 @@ namespace VRCX
{
public class SQLite
{
public static SQLite Instance { get; private set; }
private static readonly ReaderWriterLockSlim m_Lock = new ReaderWriterLockSlim();
private static SQLiteConnection m_Connection;
static SQLite()
{
Instance = new SQLite();
}
public static void Init()
{
m_Connection = new SQLiteConnection($"Data Source={Application.StartupPath}/VRCX.sqlite;Version=3");

View File

@@ -15,6 +15,13 @@ namespace VRCX
{
public class VRCX
{
public static VRCX Instance { get; private set; }
static VRCX()
{
Instance = new VRCX();
}
public void ShowDevTools()
{
try

View File

@@ -11,10 +11,16 @@ namespace VRCX
{
public class VRCXStorage
{
public static VRCXStorage Instance { get; private set; }
private static readonly ReaderWriterLockSlim m_Lock = new ReaderWriterLockSlim();
private static Dictionary<string, string> m_Storage = new Dictionary<string, string>();
private static bool m_Dirty;
static VRCXStorage()
{
Instance = new VRCXStorage();
}
public static void Load()
{
m_Lock.EnterWriteLock();