Skip to content

Commit

Permalink
Fix event sources not starting and an error if the system language is…
Browse files Browse the repository at this point in the history
… not supported by CEF.
  • Loading branch information
ngld committed Aug 22, 2019
1 parent 480ab0c commit bac0d3f
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 25 deletions.
2 changes: 1 addition & 1 deletion HtmlRenderer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.1.1.0")]
[assembly: AssemblyVersion("3.1.2.0")]
18 changes: 14 additions & 4 deletions HtmlRenderer/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ public void SetVisible(bool visible)
{
if (this._browser != null && this._browser.IsBrowserInitialized)
{
// If this call is executed synchronously, CEF stops emitting OnPaint events.
// Sometimes, CEF stops emitting OnPaint events after this call.
// Not sure why, probably a timing issue.
// TODO: Debug this further. Will probably require debugging libcef.dll directly.
// Modifying _browser.Size immidiately after the WasHidden() call leads to a crash in libcef.dll,
// that might be a good place to start investigating.
Task.Run(() => this._browser.GetBrowserHost().WasHidden(!visible));
//Task.Run(() => this._browser.GetBrowserHost().WasHidden(!visible));
}
}

Expand Down Expand Up @@ -295,11 +295,21 @@ public static void Initialize(string pluginDirectory)
if (!initialized)
{
Cef.EnableHighDPISupport();


var lang = System.Globalization.CultureInfo.CurrentCulture.Name;
var langPak = Path.Combine(pluginDirectory, Environment.Is64BitProcess ? "x64" : "x86",
"locales", lang + ".pak");

// Fall back to en-US if we can't find the current locale.
if (!File.Exists(langPak))
{
lang = "en-US";
}

var cefSettings = new CefSettings
{
WindowlessRenderingEnabled = true,
Locale = System.Globalization.CultureInfo.CurrentCulture.Name,
Locale = lang,
CachePath = Path.Combine(pluginDirectory, "Cache"),
MultiThreadedMessageLoop = true,
#if DEBUG
Expand Down
2 changes: 1 addition & 1 deletion OverlayPlugin.Common/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.4.1.0")]
[assembly: AssemblyVersion("0.4.2.0")]
2 changes: 1 addition & 1 deletion OverlayPlugin.Core/Controls/WSConfigPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void genSslBtn_Click(object sender, EventArgs e)
genSslBtn.Enabled = false;
logDisplay.Text = "Generating SSL Certificate. Please wait...\r\n";

Task.Run((Action)GenSsl);
Task.Run(GenSsl);
}

private void GenSsl()
Expand Down
7 changes: 3 additions & 4 deletions OverlayPlugin.Core/EventDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ namespace RainbowMage.OverlayPlugin
{
class EventDispatcher
{
static Dictionary<string, Func<JObject, JObject>> handlers = new Dictionary<string, Func<JObject, JObject>>();
static Dictionary<string, Func<JObject, JToken>> handlers = new Dictionary<string, Func<JObject, JToken>>();
static Dictionary<string, List<IEventReceiver>> eventFilter = new Dictionary<string, List<IEventReceiver>>();

private static void Log(LogLevel level, string message, params object[] args)
{
PluginMain.Logger.Log(level, string.Format(message, args));
}

public static void RegisterHandler(string name, Func<JObject, JObject> handler)
public static void RegisterHandler(string name, Func<JObject, JToken> handler)
{
if (handlers.ContainsKey(name))
{
Expand Down Expand Up @@ -71,7 +71,6 @@ public static void DispatchEvent(JObject e)
throw new Exception(string.Format("Tried to dispatch unregistered event type \"{0}\"!", eventType));
}

var data = e.ToString(Formatting.None);
foreach (var receiver in eventFilter[eventType])
{
try
Expand All @@ -84,7 +83,7 @@ public static void DispatchEvent(JObject e)
}
}

public static JObject CallHandler(JObject e)
public static JToken CallHandler(JObject e)
{
var handlerName = e["call"].ToString();
if (!handlers.ContainsKey(handlerName))
Expand Down
3 changes: 1 addition & 2 deletions OverlayPlugin.Core/EventSourceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public abstract class EventSourceBase : IEventSource
{
public string Name { get; protected set; }

public event EventHandler<LogEventArgs> OnLog;
protected Timer timer;
protected ILogger logger;

Expand Down Expand Up @@ -65,7 +64,7 @@ protected void RegisterEventTypes(List<string> types)
EventDispatcher.RegisterEventTypes(types);
}

protected void RegisterEventHandler(string name, Func<JObject, JObject> handler)
protected void RegisterEventHandler(string name, Func<JObject, JToken> handler)
{
EventDispatcher.RegisterHandler(name, handler);
}
Expand Down
19 changes: 13 additions & 6 deletions OverlayPlugin.Core/OverlayApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class OverlayApi
public static event EventHandler<SendMessageEventArgs> SendMessage;
public static event EventHandler<SendMessageEventArgs> OverlayMessage;

IEventReceiver receiver;
IOverlay receiver;

public OverlayApi(IEventReceiver receiver)
public OverlayApi(IOverlay receiver)
{
this.receiver = receiver;
}
Expand All @@ -35,7 +35,14 @@ public void sendMessage(string target, string msg)

public void overlayMessage(string target, string msg)
{
OverlayMessage(this, new SendMessageEventArgs(target, msg));
if (target == receiver.Name)
{
receiver.OverlayMessage(msg);
}
else
{
OverlayMessage(this, new SendMessageEventArgs(target, msg));
}
}

public void endEncounter()
Expand Down Expand Up @@ -67,8 +74,8 @@ public void callHandler(string data, object callback)

foreach (var name in message["events"].ToList())
{
EventDispatcher.Subscribe(name.ToString(), receiver);
PluginMain.Logger.Log(LogLevel.Info, "{0}: Subscribed to {1}", ((OverlayBase<MiniParseOverlayConfig>)receiver).Name, name.ToString());
EventDispatcher.Subscribe(name.ToString(), (IEventReceiver) receiver);
PluginMain.Logger.Log(LogLevel.Info, "{0}: Subscribed to {1}", receiver.Name, name.ToString());
}
return;
} else if (handler == "unsubscribe")
Expand All @@ -81,7 +88,7 @@ public void callHandler(string data, object callback)

foreach (var name in message["events"].ToList())
{
EventDispatcher.Unsubscribe(name.ToString(), receiver);
EventDispatcher.Unsubscribe(name.ToString(), (IEventReceiver) receiver);
}
return;
}
Expand Down
9 changes: 6 additions & 3 deletions OverlayPlugin.Core/Overlays/MiniParseEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected override void Update()
{
if (CheckIsActReady())
{
/* // 最終更新時刻に変化がないなら更新を行わない
// 最終更新時刻に変化がないなら更新を行わない
if (this.prevEncounterId == ActGlobals.oFormActMain.ActiveZone.ActiveEncounter.EncId &&
this.prevEndDateTime == ActGlobals.oFormActMain.ActiveZone.ActiveEncounter.EndTime &&
this.prevEncounterActive == ActGlobals.oFormActMain.ActiveZone.ActiveEncounter.Active)
Expand All @@ -54,7 +54,7 @@ protected override void Update()
this.prevEncounterId = ActGlobals.oFormActMain.ActiveZone.ActiveEncounter.EncId;
this.prevEndDateTime = ActGlobals.oFormActMain.ActiveZone.ActiveEncounter.EndTime;
this.prevEncounterActive = ActGlobals.oFormActMain.ActiveZone.ActiveEncounter.Active;
*/

DispatchEvent(this.CreateJsonData());
}
}
Expand Down Expand Up @@ -141,7 +141,8 @@ private List<KeyValuePair<CombatantData, Dictionary<string, string>>> GetCombata
// プラグイン内で例外が発生してしまい、パフォーマンスが悪化するので代わりに空の文字列を挿入する
if (exportValuePair.Key == "Last10DPS" ||
exportValuePair.Key == "Last30DPS" ||
exportValuePair.Key == "Last60DPS")
exportValuePair.Key == "Last60DPS" ||
exportValuePair.Key == "Last180DPS")
{
if (!ally.Items[CombatantData.DamageTypeDataOutgoingDamage].Items.ContainsKey("All"))
{
Expand All @@ -160,6 +161,8 @@ private List<KeyValuePair<CombatantData, Dictionary<string, string>>> GetCombata
}
}

valueDict.Add("damageShield", "0");

lock (combatantList)
{
combatantList.Add(new KeyValuePair<CombatantData, Dictionary<string, string>>(ally, valueDict));
Expand Down
5 changes: 4 additions & 1 deletion OverlayPlugin.Core/PluginMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,21 +415,23 @@ private void LoadAddons()
/// </summary>
private void LoadConfig()
{
var found = true;
try
{
Config = PluginConfig.LoadJson(GetConfigPath());
}
catch (FileNotFoundException)
{
Config = null;
found = false;
}
catch (Exception e)
{
Config = null;
Logger.Log(LogLevel.Error, "LoadConfig: {0}", e);
}

if (Config == null)
if (!found)
{
try
{
Expand All @@ -451,6 +453,7 @@ private void LoadConfig()
foreach (var es in Registry.EventSources)
{
es.LoadConfig(Config);
es.Start();
}
}

Expand Down
2 changes: 1 addition & 1 deletion OverlayPlugin.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.4.1.0")]
[assembly: AssemblyVersion("0.4.2.0")]
2 changes: 1 addition & 1 deletion OverlayPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.4.1.0")]
[assembly: AssemblyVersion("0.4.2.0")]

0 comments on commit bac0d3f

Please sign in to comment.