private void PrepareWebsite(object sender, BrowserLoadEventArgs e) { lastLoadedUrl = e.Url; Config.Url = e.Url; Overlay.Renderer.SetZoomLevel(Config.Zoom / 100.0); if (Config.ActwsCompatibility) { var shimMsg = Resources.ActwsShimEnabled; // Install a fake WebSocket so we can directly call the event handler. ExecuteScript(@"(function() { let realWS = window.WebSocket; let queue = []; window.__OverlayPlugin_ws_faker = (msg) => queue.push(msg); window.WebSocket = function(url) { if (url.indexOf('ws://127.0.0.1/fake/') > -1) { window.__OverlayPlugin_ws_faker = (msg) => { if (this.onmessage) this.onmessage({ data: JSON.stringify(msg) }); }; this.close = () => null; console.log(" + JsonConvert.SerializeObject(shimMsg) + @"); if (queue !== null) { setTimeout(() => { queue.forEach(__OverlayPlugin_ws_faker); queue = null; }, 100); } } else { return new realWS(url); } }; })();"); Subscribe("CombatData"); Subscribe("LogLine"); Subscribe("ChangeZone"); Subscribe("ChangePrimaryPlayer"); // ACTWS overlays always accept input focus. SetAcceptFocus(true); } else { // Subscriptions are cleared on page navigation so we have to restore this after every load. modernApi = false; Subscribe("CombatData"); Subscribe("LogLine"); // Reset the focus setting to make sure that a previously loaded overlay doesn't affect a different one. SetAcceptFocus(false); } }
private void FinishLoading(object sender, BrowserLoadEventArgs e) { if (Config.ActwsCompatibility) { var charName = JsonConvert.SerializeObject(FFXIVRepository.GetPlayerName() ?? "YOU"); var charID = JsonConvert.SerializeObject(FFXIVRepository.GetPlayerID()); ExecuteScript("__OverlayPlugin_ws_faker({ type: 'broadcast', msgtype: 'SendCharName', msg: { charName: " + charName + ", charID: " + charID + " }});"); } }
private void FinishLoading(object sender, BrowserLoadEventArgs e) { if (Config.ActwsCompatibility) { var charName = JsonConvert.SerializeObject(repository.GetPlayerName() ?? "YOU"); var charID = JsonConvert.SerializeObject(repository.GetPlayerID()); ExecuteScript(@"var msg = { charName: " + charName + ", charID: " + charID + @" }; if (window.__OverlayPlugin_ws_faker) { __OverlayPlugin_ws_faker({ type: 'broadcast', msgtype: 'SendCharName', msg }); } else { window.__OverlayPlugin_char_msg = msg; }"); } if (Preview) { try { var pluginPath = container.Resolve<PluginMain>().PluginDirectory; #if DEBUG var previewPath = Path.Combine(pluginPath, "libs", "resources", "preview.json"); #else var previewPath = Path.Combine(pluginPath, "resources", "preview.json"); #endif var eventData = JObject.Parse(File.ReadAllText(previewPath)); // Since we can't be sure when the overlay is ready to receive events, we'll just send one // per second (which is the same rate the real events are sent at). previewTimer = new System.Threading.Timer((state) => { HandleEvent(eventData); ExecuteScript("document.dispatchEvent(new CustomEvent('onExampleShowcase', null));"); }, null, TimeSpan.Zero, TimeSpan.FromSeconds(1)); } catch (Exception ex) { logger.Log(LogLevel.Error, $"{Name}: Failed to load preview data: {ex}"); } } if (e.Url.StartsWith("about:blank") && e.Url != Config.Url) { base.Navigate(Config.Url); } }
private void PrepareWebsite(object sender, BrowserLoadEventArgs e) { if (Config.ActwsCompatibility) { // Install a fake WebSocket so we can directly call the event handler. ExecuteScript(@"(function() { let realWS = window.WebSocket; let queue = []; window.__OverlayPlugin_ws_faker = (msg) => queue.push(msg); window.WebSocket = function(url) { if (url.indexOf('ws://127.0.0.1/fake/') > -1) { window.__OverlayPlugin_ws_faker = (msg) => { if (this.onmessage) this.onmessage({ data: JSON.stringify(msg) }); }; console.log('ACTWS compatibility shim enabled.'); if (queue !== null) { setTimeout(() => { queue.forEach(__OverlayPlugin_ws_faker); queue = null; }, 100); } } else { return new realWS(url); } }; })();"); Subscribe("CombatData"); Subscribe("LogLine"); Subscribe("ChangeZone"); Subscribe("ChangePrimaryPlayer"); } else { // Subscriptions are cleared on page navigation so we have to restore this after every load. modernApi = false; Subscribe("CombatData"); Subscribe("LogLine"); } }
private void PrepareWebsite(object sender, BrowserLoadEventArgs e) { if (e.Url.StartsWith("about:blank")) { return; } lastLoadedUrl = e.Url; Config.Url = e.Url; // Reset page-specific state Overlay.Renderer.SetZoomLevel(Config.Zoom / 100.0); ModernApi = false; if (Config.ForceWhiteBackground) { ExecuteScript("document.body.style.backgroundColor = 'white';"); } if (Config.ActwsCompatibility) { Overlay.SetAcceptFocus(!Config.NoFocus); var shimMsg = Resources.ActwsShimEnabled; // Install a fake WebSocket so we can directly call the event handler. ExecuteScript(@"(function() { let realWS = window.WebSocket; let queue = []; window.__OverlayPlugin_ws_faker = (msg) => queue.push(msg); window.overlayWindowId = 'ACTWS_shim'; window.WebSocket = function(url) { if (url.indexOf('ws://127.0.0.1/') > -1) { window.__OverlayPlugin_ws_faker = (msg) => { if (this.onmessage) this.onmessage({ data: JSON.stringify(msg) }); }; this.close = () => null; this.send = (msg) => { if (msg === '.') return; msg = JSON.parse(msg); switch (msg.msgtype) { case 'Capture': OverlayPluginApi.makeScreenshot(); break; case 'RequestEnd': OverlayPluginApi.endEncounter(); break; } }; console.log(" + JsonConvert.SerializeObject(shimMsg) + @"); if (queue !== null) { setTimeout(() => { queue.forEach(__OverlayPlugin_ws_faker); queue = null; if (window.__OverlayPlugin_char_msg) this.__OverlayPlugin_ws_faker(window.__OverlayPlugin_char_msg); }, 100); } } else { return new realWS(url); } }; })();"); Subscribe("CombatData"); Subscribe("LogLine"); Subscribe("ChangeZone"); Subscribe("ChangePrimaryPlayer"); } else { // Reset page-specific state Overlay.SetAcceptFocus(false); // Subscriptions are cleared on page navigation so we have to restore this after every load. Subscribe("CombatData"); Subscribe("LogLine"); } }
private void OnBrowserLoad(object sender, BrowserLoadEventArgs e) { lastHour = -1; lastVisible = null; }
/// <summary> /// ブラウザロード時に設定情報を渡す /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnBrowserLoad(object sender, BrowserLoadEventArgs e) { var config = JsonUtil.CreateJsonData(this.Config.AddonConfig); ExecuteScript($"loaded({config})"); }