Add config file

This commit is contained in:
glax 2024-04-16 20:55:18 +02:00
parent 208e3b7958
commit a723b029b4
2 changed files with 32 additions and 1 deletions

21
OBSBlur/Config.cs Normal file
View File

@ -0,0 +1,21 @@
using System.Text.Json.Serialization;
// ReSharper disable FieldCanBeMadeReadOnly.Global
// ReSharper disable ConvertToConstant.Global
namespace OBSBlur;
public struct Config
{
[JsonRequired]
public string ObsWebsocketUrl = "ws://localhost:4444";
[JsonRequired]
public string ObsWebsocketPassword = "";
[JsonRequired]
public string[] EnabledScenes = { "Desktop" };
[JsonRequired]
public string[] BlurPrograms = { "Discord", "thunderbird", "Signal" };
public Config()
{
}
}

View File

@ -1,9 +1,19 @@
using GlaxLogger;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using OBSBlur;
using OBSBlur.OBS;
string configFilePath = "config.json";
Logger logger = new (filteredLevel: LogLevel.Trace, consoleOut: Console.Out);
Blur _ = new ("ws://localhost:4444", "", new []{"Desktop"}, new []{ "Discord", "VRCX", "thunderbird", "Signal" }, logger);
Config config = File.Exists(configFilePath) switch
{
true => JsonConvert.DeserializeObject<Config>(File.ReadAllText(configFilePath)),
_ => new Config()
};
File.WriteAllText(configFilePath, JsonConvert.SerializeObject(config));
Blur _ = new (config.ObsWebsocketUrl, config.ObsWebsocketPassword, config.EnabledScenes, config.BlurPrograms, logger);
while (true)
Thread.Sleep(100);