Skip to content

Commit

Permalink
make singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
pypy-vrc committed Mar 21, 2020
1 parent 336241c commit a9d4543
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(() =>
Expand Down
6 changes: 6 additions & 0 deletions LogWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class LogWatcherFile

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;
Expand All @@ -28,6 +29,11 @@ public class LogWatcher
// NOTE
// FileSystemWatcher() is unreliable

static LogWatcher()
{
Instance = new LogWatcher();
}

public static void Init()
{
m_Thread = new Thread(() =>
Expand Down
10 changes: 5 additions & 5 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public MainForm()
{
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();
Expand Down
6 changes: 6 additions & 0 deletions SQLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
7 changes: 7 additions & 0 deletions VRCX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions VRCXStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a9d4543

Please sign in to comment.