mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-17 13:53:52 +02:00
add SharedVariable
This commit is contained in:
@@ -32,6 +32,7 @@ namespace VRCX
|
||||
CamelCaseJavascriptNames = false
|
||||
};
|
||||
JavascriptObjectRepository.Register("VRCX", VRCX.Instance, true, options);
|
||||
JavascriptObjectRepository.Register("SharedVariable", SharedVariable.Instance, true, options);
|
||||
JavascriptObjectRepository.Register("VRCXStorage", VRCXStorage.Instance, false, options);
|
||||
JavascriptObjectRepository.Register("SQLite", SQLite.Instance, true, options);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace VRCX
|
||||
CamelCaseJavascriptNames = false
|
||||
};
|
||||
Browser.JavascriptObjectRepository.Register("VRCX", VRCX.Instance, true, options);
|
||||
Browser.JavascriptObjectRepository.Register("SharedVariable", SharedVariable.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);
|
||||
|
||||
88
SharedVariable.cs
Normal file
88
SharedVariable.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
// Copyright(c) 2020 pypy. 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.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace VRCX
|
||||
{
|
||||
public class SharedVariable
|
||||
{
|
||||
public static SharedVariable Instance { get; private set; }
|
||||
private readonly ReaderWriterLockSlim m_MapLock;
|
||||
private readonly Dictionary<string, string> m_Map;
|
||||
|
||||
static SharedVariable()
|
||||
{
|
||||
Instance = new SharedVariable();
|
||||
}
|
||||
|
||||
public SharedVariable()
|
||||
{
|
||||
m_MapLock = new ReaderWriterLockSlim();
|
||||
m_Map = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_MapLock.EnterWriteLock();
|
||||
try
|
||||
{
|
||||
if (m_Map.Count > 0)
|
||||
{
|
||||
m_Map.Clear();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
m_MapLock.ExitWriteLock();
|
||||
}
|
||||
}
|
||||
|
||||
public bool Remove(string key)
|
||||
{
|
||||
m_MapLock.EnterWriteLock();
|
||||
try
|
||||
{
|
||||
return m_Map.Remove(key);
|
||||
}
|
||||
finally
|
||||
{
|
||||
m_MapLock.ExitWriteLock();
|
||||
}
|
||||
}
|
||||
|
||||
public string Get(string key)
|
||||
{
|
||||
m_MapLock.EnterReadLock();
|
||||
try
|
||||
{
|
||||
if (m_Map.TryGetValue(key, out string value) == true)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
m_MapLock.ExitReadLock();
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public void Set(string key, string value)
|
||||
{
|
||||
m_MapLock.EnterWriteLock();
|
||||
try
|
||||
{
|
||||
m_Map[key] = value;
|
||||
}
|
||||
finally
|
||||
{
|
||||
m_MapLock.ExitWriteLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,6 +132,7 @@
|
||||
<Compile Include="NoopDragHandler.cs" />
|
||||
<Compile Include="RenderHandler.cs" />
|
||||
<Compile Include="SQLite.cs" />
|
||||
<Compile Include="SharedVariable.cs" />
|
||||
<Compile Include="VRForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -47,9 +47,11 @@ namespace VRCX
|
||||
CamelCaseJavascriptNames = false
|
||||
};
|
||||
Browser1.JavascriptObjectRepository.Register("VRCX", VRCX.Instance, true, options);
|
||||
Browser1.JavascriptObjectRepository.Register("SharedVariable", SharedVariable.Instance, true, options);
|
||||
Browser1.JavascriptObjectRepository.Register("VRCXStorage", VRCXStorage.Instance, false, options);
|
||||
Browser1.JavascriptObjectRepository.Register("SQLite", SQLite.Instance, true, options);
|
||||
Browser2.JavascriptObjectRepository.Register("VRCX", VRCX.Instance, true, options);
|
||||
Browser2.JavascriptObjectRepository.Register("SharedVariable", SharedVariable.Instance, true, options);
|
||||
Browser2.JavascriptObjectRepository.Register("VRCXStorage", VRCXStorage.Instance, false, options);
|
||||
Browser2.JavascriptObjectRepository.Register("SQLite", SQLite.Instance, true, options);
|
||||
Browser1.IsBrowserInitializedChanged += (A, B) =>
|
||||
|
||||
Reference in New Issue
Block a user