Skip to content

Commit

Permalink
async VRCXStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
Natsumi-sama committed Jan 7, 2023
1 parent e7e2960 commit 3fca544
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 26 deletions.
10 changes: 7 additions & 3 deletions App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>

<System.Windows.Forms.ApplicationConfigurationSection>
<add key="DpiAwareness" value="PerMonitorV2" />
</System.Windows.Forms.ApplicationConfigurationSection>
</configuration>
7 changes: 3 additions & 4 deletions CefService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ internal void Init()
{
CachePath = Path.Combine(Program.AppDataDirectory, "cache"),
UserDataPath = Path.Combine(Program.AppDataDirectory, "userdata"),
IgnoreCertificateErrors = true,
LogSeverity = LogSeverity.Disable,
WindowlessRenderingEnabled = true,
PersistSessionCookies = true,
Expand All @@ -34,16 +33,16 @@ internal void Init()
SchemeHandlerFactory = new FolderSchemeHandlerFactory(Application.StartupPath + "/../../../html")
});*/

// cefSettings.CefCommandLineArgs.Add("allow-universal-access-from-files");
// cefSettings.CefCommandLineArgs.Add("ignore-certificate-errors");
cefSettings.CefCommandLineArgs.Add("disable-plugins");
// cefSettings.CefCommandLineArgs.Add("disable-plugins");
cefSettings.CefCommandLineArgs.Add("disable-spell-checking");
cefSettings.CefCommandLineArgs.Add("disable-pdf-extension");
cefSettings.CefCommandLineArgs["autoplay-policy"] = "no-user-gesture-required";
// cefSettings.CefCommandLineArgs.Add("allow-universal-access-from-files");
cefSettings.CefCommandLineArgs.Add("disable-web-security");
cefSettings.SetOffScreenRenderingBestPerformanceArgs();

CefSharpSettings.WcfEnabled = true; // TOOD: REMOVE THIS LINE YO
// CefSharpSettings.WcfEnabled = true; // TOOD: REMOVE THIS LINE YO (needed for synchronous configRepository)
CefSharpSettings.ShutdownOnExit = false;

// Enable High-DPI support on Windows 7 or newer
Expand Down
2 changes: 1 addition & 1 deletion Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void ApplyJavascriptBindings(IJavascriptObjectRepository repositor
repository.Register("AppApi", AppApi.Instance, true);
repository.Register("SharedVariable", SharedVariable.Instance, false);
repository.Register("WebApi", WebApi.Instance, true);
repository.Register("VRCXStorage", VRCXStorage.Instance, false);
repository.Register("VRCXStorage", VRCXStorage.Instance, true);
repository.Register("SQLite", SQLite.Instance, true);
repository.Register("LogWatcher", LogWatcher.Instance, true);
repository.Register("Discord", Discord.Instance, true);
Expand Down
8 changes: 1 addition & 7 deletions app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<assemblyIdentity version="1.0.0.0" name="CefSharp.MinimalExample.Offscreen.app" />

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
Expand All @@ -28,13 +29,6 @@
</security>
</trustInfo>

<asmv3:application>
<asmv3:windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of all Windows versions that this application is designed to work with.
Expand Down
28 changes: 17 additions & 11 deletions html/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ speechSynthesis.getVoices();
'launchAsDesktop'
];
for (var _key of legacyConfigKeys) {
configRepository.setBool(_key, VRCXStorage.Get(_key) === 'true');
configRepository.setBool(
_key,
(await VRCXStorage.Get(_key)) === 'true'
);
}
configRepository.setBool('migrate_config_20201101', true);
}
Expand All @@ -80,9 +83,9 @@ speechSynthesis.getVoices();
}
});

VRCXStorage.GetArray = function (key) {
VRCXStorage.GetArray = async function (key) {
try {
var array = JSON.parse(this.Get(key));
var array = JSON.parse(await this.Get(key));
if (Array.isArray(array)) {
return array;
}
Expand All @@ -96,9 +99,9 @@ speechSynthesis.getVoices();
this.Set(key, JSON.stringify(value));
};

VRCXStorage.GetObject = function (key) {
VRCXStorage.GetObject = async function (key) {
try {
var object = JSON.parse(this.Get(key));
var object = JSON.parse(await this.Get(key));
if (object === Object(object)) {
return object;
}
Expand Down Expand Up @@ -7058,7 +7061,7 @@ speechSynthesis.getVoices();
};

$app.methods.migrateMemos = async function () {
var json = JSON.parse(VRCXStorage.GetAll());
var json = JSON.parse(await VRCXStorage.GetAll());
database.begin();
for (var line in json) {
if (line.substring(0, 8) === 'memo_usr') {
Expand Down Expand Up @@ -8368,7 +8371,7 @@ speechSynthesis.getVoices();
}
$app.vrInit();
// remove old data from json file and migrate to SQLite
if (VRCXStorage.Get(`${args.json.id}_friendLogUpdatedAt`)) {
if (await VRCXStorage.Get(`${args.json.id}_friendLogUpdatedAt`)) {
VRCXStorage.Remove(`${args.json.id}_feedTable`);
$app.migrateMemos();
$app.migrateFriendLog(args.json.id);
Expand Down Expand Up @@ -12089,10 +12092,10 @@ speechSynthesis.getVoices();
this.friendLogInitStatus = true;
};

$app.methods.migrateFriendLog = function (userId) {
$app.methods.migrateFriendLog = async function (userId) {
VRCXStorage.Remove(`${userId}_friendLogUpdatedAt`);
VRCXStorage.Remove(`${userId}_friendLog`);
this.friendLogTable.data = VRCXStorage.GetArray(
this.friendLogTable.data = await VRCXStorage.GetArray(
`${userId}_friendLogTable`
);
database.addFriendLogHistoryArray(this.friendLogTable.data);
Expand Down Expand Up @@ -12996,12 +12999,15 @@ speechSynthesis.getVoices();
'VRCX_StartAtWindowsStartup'
);
$app.data.isStartAsMinimizedState =
VRCXStorage.Get('VRCX_StartAsMinimizedState') === 'true';
(await VRCXStorage.Get('VRCX_StartAsMinimizedState')) === 'true';
$app.data.isCloseToTray = VRCXStorage.Get('VRCX_CloseToTray') === 'true';
if (configRepository.getBool('VRCX_CloseToTray')) {
// move back to JSON
$app.data.isCloseToTray = configRepository.getBool('VRCX_CloseToTray');
VRCXStorage.Set('VRCX_CloseToTray', $app.data.isCloseToTray.toString());
await VRCXStorage.Set(
'VRCX_CloseToTray',
$app.data.isCloseToTray.toString()
);
configRepository.remove('VRCX_CloseToTray');
}
var saveVRCXWindowOption = function () {
Expand Down
18 changes: 18 additions & 0 deletions html/src/repository/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ function transformKey(key) {
return String(key).toLowerCase();
}

function waitSynchronous(promise) {
if (typeof promise !== 'object' || promise === null) {
return promise;
}
console.log('waitSynchronous', promise);
while (true) {
var state = promise.getState();
if (state === 'resolved') {
return promise.get();
}
if (state === 'rejected') {
return null;
}
}
}

class SharedRepository {
remove(key) {
var _key = transformKey(key);
Expand All @@ -12,6 +28,8 @@ class SharedRepository {

getString(key, defaultValue = null) {
var _key = transformKey(key);
// var get = SharedVariable.Get(_key);
// var value = waitSynchronous(get);
var value = SharedVariable.Get(_key);
if (value === null) {
return defaultValue;
Expand Down

0 comments on commit 3fca544

Please sign in to comment.