From b87eea227930613561ad0fe241d1752e429eec10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lipok?= <11089482+mlipok@users.noreply.github.com> Date: Sun, 18 Jan 2026 02:54:04 +0100 Subject: [PATCH 1/4] Update NetWebView2Lib.au3 --- NetWebView2Lib.au3 | 254 +++++---------------------------------------- 1 file changed, 24 insertions(+), 230 deletions(-) diff --git a/NetWebView2Lib.au3 b/NetWebView2Lib.au3 index cec703d..ed46414 100644 --- a/NetWebView2Lib.au3 +++ b/NetWebView2Lib.au3 @@ -1,3 +1,6 @@ +#Region ; *** Dynamically added Include files *** +#include ; added:01/18/26 02:35:43 +#EndRegion ; *** Dynamically added Include files *** ;~ #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Run_AU3Check=Y @@ -8,19 +11,30 @@ #include #include - ; Global objects Global $_g_hNetWebView2Lib_DLL = '' Global $_g_oWeb Global $g_DebugInfo = True -_Example() #Region ; NetWebView2Lib UDF Func _NetWebView2_StartUp($sDLLFileFullPath) + $sDLLFileFullPath = _WinAPI_PathCanonicalize($sDLLFileFullPath) +;~ ConsoleWrite($sDLLFileFullPath & @CRLF) $_g_hNetWebView2Lib_DLL = DllOpen($sDLLFileFullPath) + +;~ ConsoleWrite("! " & VarGetType($_g_hNetWebView2Lib_DLL) & @CRLF) +;~ ConsoleWrite("! " & $_g_hNetWebView2Lib_DLL & @CRLF) + If $_g_hNetWebView2Lib_DLL = -1 Then + __NetWebView2_Log(@ScriptLineNumber, 'Error loading AcitevX DLL : ' & $_g_hNetWebView2Lib_DLL) + Return SetError(1, @extended, $_g_hNetWebView2Lib_DLL) + EndIf Return SetError(@error, @extended, $_g_hNetWebView2Lib_DLL) EndFunc ;==>_NetWebView2_StartUp +Func _NetWebView2_ShutDown() + DllClose($_g_hNetWebView2Lib_DLL) +EndFunc ;==>_NetWebView2_ShutDown + ; #FUNCTION# ==================================================================================================================== ; Name ..........: _NetWebView2_CreateManager ; Description ...: @@ -37,8 +51,10 @@ EndFunc ;==>_NetWebView2_StartUp Func _NetWebView2_CreateManager() Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler #forceref $oMyError - Local $oWebV2M = ObjCreate("NetWebView2.Manager", "{CCB12345-6789-4ABC-DEF0-1234567890AB}", $_g_hNetWebView2Lib_DLL) ; NOT REGISTERED VERSION + Local $oWebV2M = ObjCreate("NetWebView2.Manager") ; REGISTERED VERSION +;~ Local $oWebV2M = ObjCreate("NetWebView2.Manager", "{CCB12345-6789-4ABC-DEF0-1234567890AB}", $_g_hNetWebView2Lib_DLL) ; NOT REGISTERED VERSION ;~ _NetWebView2_ObjName_FlagsValue($oWebV2M) + If @error Then __NetWebView2_Log(@ScriptLineNumber, "! [NetWebView2Lib]: Manager Creation ERROR") Return SetError(@error, @extended, $oWebV2M) EndFunc ;==>_NetWebView2_CreateManager @@ -59,7 +75,8 @@ Func _NetJson_CreateParser($sInitialJson = "{}") Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler #forceref $oMyError If $sInitialJson = "" Or $sInitialJson = Default Then $sInitialJson = "{}" - Local $oParser = ObjCreate("NetJson.Parser", "{D1E2F3A4-B5C6-4D7E-8F9A-0B1C2D3E4F5A}", $_g_hNetWebView2Lib_DLL) ; NOT REGISTERED VERSION + Local $oParser = ObjCreate("NetJson.Parser") ; REGISTERED VERSION +;~ Local $oParser = ObjCreate("NetJson.Parser", "{D1E2F3A4-B5C6-4D7E-8F9A-0B1C2D3E4F5A}", $_g_hNetWebView2Lib_DLL) ; NOT REGISTERED VERSION If Not IsObj($oParser) Then Return SetError(1, 0, 0) $oParser.Parse($sInitialJson) Return $oParser @@ -235,14 +252,14 @@ Func __NetWebView2_JSEvents_OnMessageReceived($sMsg) If UBound($aClickData) >= 2 Then Local $sKey = StringStripWS($aClickData[0], 3) Local $sVal = StringStripWS($aClickData[1], 3) - __NetWebView2_Log(@ScriptLineNumber, "+++ [JavaScriptEvents]: Property: " & $sKey & " | Value: " & $sVal & @CRLF) + __NetWebView2_Log(@ScriptLineNumber, "+++ [JavaScriptEvents]: Property: " & $sKey & " | Value: " & $sVal) EndIf Case "COM_TEST" - __NetWebView2_Log(@ScriptLineNumber, "- [JavaScriptEvents]: Status: Legacy COM_TEST: " & $sData & @CRLF) + __NetWebView2_Log(@ScriptLineNumber, "- [JavaScriptEvents]: Status: Legacy COM_TEST: " & $sData) Case "ERROR" - __NetWebView2_Log(@ScriptLineNumber, "! [JavaScriptEvents]: Status: " & $sData & @CRLF) + __NetWebView2_Log(@ScriptLineNumber, "! [JavaScriptEvents]: Status: " & $sData) EndSwitch EndIf EndFunc ;==>__NetWebView2_JSEvents_OnMessageReceived @@ -256,226 +273,3 @@ EndFunc ;==>__NetWebView2_WebEvents_OnContextMenuRequested #EndRegion ; === EVENT HANDLERS === #EndRegion ; NetWebView2Lib UDF - -#Region ; UDF TESTING EXAMPLE -Func _Example() - Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) - #forceref $oMyError - ; Create GUI with resizing support - Local $hGUI = GUICreate("WebView2AutoIt JSON Viewer", 500, 650, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN)) - GUISetBkColor(0x2B2B2B, $hGUI) - - ; GUI Controls for JSON Tree interaction - Local $idExpand = GUICtrlCreateLabel("Expand All", 10, 10, 90, 30) - GUICtrlSetFont(-1, 12, Default, $GUI_FONTUNDER, "Segoe UI") - GUICtrlSetResizing(-1, $GUI_DOCKALL) - GUICtrlSetColor(-1, 0x00FF00) ; Green - - Local $idCollapse = GUICtrlCreateLabel("Collapse All", 110, 10, 90, 30) - GUICtrlSetFont(-1, 12, Default, $GUI_FONTUNDER, "Segoe UI") - GUICtrlSetResizing(-1, $GUI_DOCKALL) - GUICtrlSetColor(-1, 0xFF4D4D) ; Red - - Local $idFind = GUICtrlCreateLabel("Search", 210, 10, 60, 30) - GUICtrlSetFont(-1, 12, Default, $GUI_FONTUNDER, "Segoe UI") - GUICtrlSetResizing(-1, $GUI_DOCKALL) - GUICtrlSetColor(-1, 0xFFD700) ; Gold - - Local $idLoadFile = GUICtrlCreateLabel("Load JSON", 280, 10, 90, 30) - GUICtrlSetFont(-1, 12, Default, $GUI_FONTUNDER, "Segoe UI") - GUICtrlSetResizing(-1, $GUI_DOCKALL) - GUICtrlSetColor(-1, 0x00CCFF) ; Light Blue - - _NetWebView2_StartUp(@ScriptDir & '\bin\NetWebView2Lib.dll') - - ; Initialize WebView2 Manager and register events - Local $oWebV2M = _NetWebView2_CreateManager() - $_g_oWeb = $oWebV2M - If @error Then Return SetError(@error, @extended, $oWebV2M) - - ObjEvent($oWebV2M, "__NetWebView2_WebEvents_", "IWebViewEvents") - - ; Important: Pass $hGUI in parentheses to maintain Pointer type for COM - Local $sProfileDirectory = @TempDir & "\NetWebView2Lib-UserDataFolder" - $oWebV2M.Initialize($hGUI, $sProfileDirectory, 0, 50, 500, 600) - - ; Initialize JavaScript Bridge - Local $oJS = $oWebV2M.GetBridge() - ObjEvent($oJS, "__NetWebView2_JSEvents_", "IBridgeEvents") - - ; Wait for WebView2 to be ready - Do - Sleep(50) - Until $oWebV2M.IsReady - - ; WebView2 Configuration - $oWebV2M.SetAutoResize(True) ; Using SetAutoResize(True) to skip WM_SIZE - $oWebV2M.BackColor = "0x2B2B2B" - $oWebV2M.AreDevToolsEnabled = True ; Allow F12 - $oWebV2M.ZoomFactor = 1.2 - - ; Initial JSON display - Local $sMyJson = '{"Game": "Witcher 3", "ID": 1, "Meta": {"Developer": "CD Projekt", "Year": 2015 }, "Tags": ["RPG", "Open World"]}' - - _Web_jsonTree($oWebV2M, $sMyJson) ; 🏆 https://github.com/summerstyle/jsonTreeViewer - - GUISetState(@SW_SHOW) - - Local $sLastSearch = "" - - ; Main Application Loop - While 1 - Switch GUIGetMsg() - Case $GUI_EVENT_CLOSE - Exit - - Case $idExpand - ; Call JavaScript expand method on the global tree object - $oWebV2M.ExecuteScript("if(window.tree) window.tree.expand();") - - Case $idCollapse - ; Call JavaScript collapse method - $oWebV2M.ExecuteScript("if(window.tree) window.tree.collapse();") - - Case $idFind - Local $sInput = InputBox("JSON Search", "Enter key or value:", $sLastSearch, "", 200, 130, Default, Default, Default, $hGUI) - If Not @error And StringLen(StringStripWS($sInput, 3)) > 0 Then - $sLastSearch = StringStripWS($sInput, 3) - _Web_jsonTreeFind($oWebV2M, $sLastSearch, False) ; New search - EndIf - - Case $idLoadFile - Local $sFilePath = FileOpenDialog("Select JSON File", @ScriptDir, "JSON Files (*.json;*.txt)", 1) - If Not @error Then - Local $sFileData = FileRead($sFilePath) - If $sFileData <> "" Then - _Web_jsonTree($oWebV2M, $sFileData) ; Re-render tree with new data - __NetWebView2_Log(@ScriptLineNumber, "+ Loaded JSON from: " & $sFilePath) - EndIf - EndIf - - EndSwitch - WEnd - - If IsObj($oWebV2M) Then $oWebV2M.Cleanup() - $oWebV2M = 0 - $oJS = 0 - -EndFunc ;==>Main - -#Region ; === UTILS === - -; #FUNCTION# ==================================================================================================================== -; Name...........: _Web_jsonTree -; Description....: Renders JSON data using the jsonTree library by summerstyle. -; Author.........: summerstyle (https://github.com/summerstyle/jsonTreeViewer) -; Integration....: Adapted for AutoIt WebView2 -; =============================================================================================================================== -Func _Web_jsonTree(ByRef $oWebV2M, $sJson) - ; 1. Prepare JSON (Minify to prevent script errors from line breaks) - Local $oJSON = _NetJson_CreateParser($sJson) -;~ _NetWebView2_ObjName_FlagsValue($oJSON) - $sJson = $oJSON.GetMinifiedJson() - - ; 2. Load local library files - Local $sJsLib = FileRead(@ScriptDir & "\examples\v1.4.2_jsonTree\JS_Lib\jsonTree.js") - Local $sCssLib = FileRead(@ScriptDir & "\examples\v1.4.2_jsonTree\JS_Lib\jsonTreeDark.css") - - ; 3. Build HTML with embedded Logic - Local $sHTML = "" & _ - "
" & _ - "
" & _ - " Powered by jsonTree" & _ - "
" & _ - "" - - ; 4. Navigate to the generated HTML - $oWebV2M.NavigateToString($sHTML) - __NetWebView2_Log(@ScriptLineNumber, "+ JSON Tree Rendered & Listeners Active") -EndFunc ;==>_Web_jsonTree - -; #FUNCTION# ==================================================================================================================== -; Name...........: _Web_jsonTreeFind -; Description....: Searches for a string in labels and values and highlights matching nodes. -; Parameters.....: $sSearch - The string to find -; =============================================================================================================================== -Func _Web_jsonTreeFind(ByRef $oWebV2M, $sSearch, $bNext = False) - Local $sJS = _ - "var term = '" & $sSearch & "'.toLowerCase();" & _ - "if (!window.searchIndices || window.lastTerm !== term) {" & _ - " window.searchIndices = [];" & _ - " window.currentSearchIndex = -1;" & _ - " window.lastTerm = term;" & _ - "}" & _ - "" & _ - "/* 1. If it's a new search, find all targets */" & _ - "if (!" & StringLower($bNext) & " || window.searchIndices.length === 0) {" & _ - " document.querySelectorAll('.jsontree_node_marked').forEach(el => el.classList.remove('jsontree_node_marked', 'jsontree_node_active'));" & _ - " var targets = document.querySelectorAll('.jsontree_label, .jsontree_value');" & _ - " window.searchIndices = [];" & _ - " targets.forEach(function(el) {" & _ - " var text = el.innerText.toLowerCase();" & _ - " var isBracket = (text === '{' || text === '}' || text === '[' || text === ']' || text === '{ }' || text === '[ ]');" & _ - " if (!isBracket && (el.classList.contains('jsontree_label') || el.children.length === 0) && text.includes(term)) {" & _ - " el.classList.add('jsontree_node_marked');" & _ - " window.searchIndices.push(el);" & _ - " }" & _ - " });" & _ - "}" & _ - "" & _ - "/* 2. Move to next index */" & _ - "if (window.searchIndices.length > 0) {" & _ - " /* Remove active class from previous */" & _ - " if (window.currentSearchIndex >= 0) window.searchIndices[window.currentSearchIndex].classList.remove('jsontree_node_active');" & _ - " " & _ - " window.currentSearchIndex++;" & _ - " if (window.currentSearchIndex >= window.searchIndices.length) window.currentSearchIndex = 0;" & _ - " " & _ - " var activeEl = window.searchIndices[window.currentSearchIndex];" & _ - " activeEl.classList.add('jsontree_node_active');" & _ - " " & _ - " /* Expand parents of active element */" & _ - " var p = activeEl.closest('.jsontree_node');" & _ - " while (p && p.id !== 'tree-container') {" & _ - " if (p.classList.contains('jsontree_node_complex')) p.classList.add('jsontree_node_expanded');" & _ - " p = p.parentElement;" & _ - " }" & _ - " activeEl.scrollIntoView({behavior: 'smooth', block: 'center'});" & _ - "}" - - ; Replace the AutoIt variable $bNext with JS boolean -;~ $sJS = StringReplace($sJS, "$bNext", ($bNext ? "true" : "false")) - ConsoleWrite("$sJS=" & $sJS & @CRLF) - $oWebV2M.ExecuteScript($sJS) -EndFunc ;==>_Web_jsonTreeFind -#EndRegion ; === UTILS === -#EndRegion ; UDF TESTING EXAMPLE From a632f41b110284342e14678c3d7f5bb2e7d5707c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lipok?= <11089482+mlipok@users.noreply.github.com> Date: Sun, 18 Jan 2026 02:54:30 +0100 Subject: [PATCH 2/4] Update jsonTree.au3 --- examples/v1.4.2_jsonTree/jsonTree.au3 | 208 +++++++------------------- 1 file changed, 55 insertions(+), 153 deletions(-) diff --git a/examples/v1.4.2_jsonTree/jsonTree.au3 b/examples/v1.4.2_jsonTree/jsonTree.au3 index e4d2da3..c3f449d 100644 --- a/examples/v1.4.2_jsonTree/jsonTree.au3 +++ b/examples/v1.4.2_jsonTree/jsonTree.au3 @@ -1,24 +1,24 @@ #AutoIt3Wrapper_UseX64=y +;~ #AutoIt3Wrapper_UseX64=n +#AutoIt3Wrapper_Run_AU3Check=Y +#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y +#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 + ; Html_Gui.au3 +#include #include #include -#include +#include "..\..\NetWebView2Lib.au3" -; Register exit function to ensure clean WebView2 shutdown -OnAutoItExitRegister("_ExitApp") -; Global objects -Global $oWeb, $oJS -Global $oMyError = ObjEvent("AutoIt.Error", "_ErrFunc") ; COM Error Handler -Global $g_DebugInfo = True -Global $g_sProfilePath = @ScriptDir & "\UserDataFolder" -Global $hGUI +_Example() -Main() - -Func Main() +#Region ; UDF TESTING EXAMPLE +Func _Example() + Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) + #forceref $oMyError ; Create GUI with resizing support - $hGUI = GUICreate("WebView2AutoIt JSON Viewer", 500, 650, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN)) + Local $hGUI = GUICreate("WebView2AutoIt JSON Viewer", 500, 650, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN)) GUISetBkColor(0x2B2B2B, $hGUI) ; GUI Controls for JSON Tree interaction @@ -42,32 +42,41 @@ Func Main() GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlSetColor(-1, 0x00CCFF) ; Light Blue +;~ Local $sActiveX_Dll = @ScriptDir & '\..\..\bin\NetWebView2Lib.dll' +;~ _NetWebView2_StartUp($sActiveX_Dll) + _NetWebView2_StartUp('Z:\!!!_SVN_AU3\UDF_Forum\Other_Members\Official_AutoIt_Forum\NetWebView2Lib-main\bin\NetWebView2Lib.dll') + If @error Then Return SetError(@error, @extended, -1) + ; Initialize WebView2 Manager and register events - $oWeb = ObjCreate("NetWebView2.Manager") - ObjEvent($oWeb, "WebEvents_", "IWebViewEvents") + Local $oWebV2M = _NetWebView2_CreateManager() + $_g_oWeb = $oWebV2M + If @error Then Return SetError(@error, @extended, $oWebV2M) + + ObjEvent($oWebV2M, "__NetWebView2_WebEvents_", "IWebViewEvents") ; Important: Pass $hGUI in parentheses to maintain Pointer type for COM - $oWeb.Initialize(($hGUI), $g_sProfilePath, 0, 50, 500, 600) + Local $sProfileDirectory = @TempDir & "\NetWebView2Lib-UserDataFolder" + $oWebV2M.Initialize($hGUI, $sProfileDirectory, 0, 50, 500, 600) ; Initialize JavaScript Bridge - $oJS = $oWeb.GetBridge() - ObjEvent($oJS, "JavaScript_", "IBridgeEvents") + Local $oJS = $oWebV2M.GetBridge() + ObjEvent($oJS, "__NetWebView2_JSEvents_", "IBridgeEvents") ; Wait for WebView2 to be ready Do Sleep(50) - Until $oWeb.IsReady + Until $oWebV2M.IsReady ; WebView2 Configuration - $oWeb.SetAutoResize(True) ; Using SetAutoResize(True) to skip WM_SIZE - $oWeb.BackColor = "0x2B2B2B" - $oWeb.AreDevToolsEnabled = True ; Allow F12 - $oWeb.ZoomFactor = 1.2 + $oWebV2M.SetAutoResize(True) ; Using SetAutoResize(True) to skip WM_SIZE + $oWebV2M.BackColor = "0x2B2B2B" + $oWebV2M.AreDevToolsEnabled = True ; Allow F12 + $oWebV2M.ZoomFactor = 1.2 ; Initial JSON display Local $sMyJson = '{"Game": "Witcher 3", "ID": 1, "Meta": {"Developer": "CD Projekt", "Year": 2015 }, "Tags": ["RPG", "Open World"]}' - _Web_jsonTree($oWeb, $sMyJson) ; 🏆 https://github.com/summerstyle/jsonTreeViewer + _Web_jsonTree($oWebV2M, $sMyJson) ; 🏆 https://github.com/summerstyle/jsonTreeViewer GUISetState(@SW_SHOW) @@ -81,17 +90,17 @@ Func Main() Case $idExpand ; Call JavaScript expand method on the global tree object - $oWeb.ExecuteScript("if(window.tree) window.tree.expand();") + $oWebV2M.ExecuteScript("if(window.tree) window.tree.expand();") Case $idCollapse ; Call JavaScript collapse method - $oWeb.ExecuteScript("if(window.tree) window.tree.collapse();") + $oWebV2M.ExecuteScript("if(window.tree) window.tree.collapse();") Case $idFind Local $sInput = InputBox("JSON Search", "Enter key or value:", $sLastSearch, "", 200, 130, Default, Default, Default, $hGUI) If Not @error And StringLen(StringStripWS($sInput, 3)) > 0 Then $sLastSearch = StringStripWS($sInput, 3) - _Web_jsonTreeFind($sLastSearch, False) ; New search + _Web_jsonTreeFind($oWebV2M, $sLastSearch, False) ; New search EndIf Case $idLoadFile @@ -99,139 +108,38 @@ Func Main() If Not @error Then Local $sFileData = FileRead($sFilePath) If $sFileData <> "" Then - _Web_jsonTree($oWeb, $sFileData) ; Re-render tree with new data - __DW("+ Loaded JSON from: " & $sFilePath & @CRLF) + _Web_jsonTree($oWebV2M, $sFileData) ; Re-render tree with new data + __NetWebView2_Log(@ScriptLineNumber, "+ Loaded JSON from: " & $sFilePath) EndIf EndIf EndSwitch WEnd -EndFunc ;==>Main - -#Region ; === EVENT HANDLERS === - -; Handles native WebView2 events -Func WebEvents_OnMessageReceived($sMsg) - __DW("+++ [WebEvents]: " & (StringLen($sMsg) > 150 ? StringLeft($sMsg, 150) & "..." : $sMsg) & @CRLF, 0) - Local $iSplitPos = StringInStr($sMsg, "|") - Local $sCommand = $iSplitPos ? StringStripWS(StringLeft($sMsg, $iSplitPos - 1), 3) : $sMsg - Local $sData = $iSplitPos ? StringTrimLeft($sMsg, $iSplitPos) : "" - Local $aParts - - Switch $sCommand - Case "INIT_READY" - $oWeb.ExecuteScript('window.chrome.webview.postMessage(JSON.stringify({ "type": "COM_TEST", "status": "OK" }));') - - Case "WINDOW_RESIZED" - $aParts = StringSplit($sData, "|") - If $aParts[0] >= 2 Then - Local $iW = Int($aParts[1]), $iH = Int($aParts[2]) - ; Filter minor resize glitches - If $iW > 50 And $iH > 50 Then __DW("WINDOW_RESIZED : " & $iW & "x" & $iH & @CRLF) - EndIf - EndSwitch -EndFunc ;==>WebEvents_OnMessageReceived - -; Handles custom messages from JavaScript (window.chrome.webview.postMessage) -Func JavaScript_OnMessageReceived($sMsg) - __DW(">>> [JavaScript]: " & (StringLen($sMsg) > 150 ? StringLeft($sMsg, 150) & "..." : $sMsg) & @CRLF, 0) - Local $sFirstChar = StringLeft($sMsg, 1) - - ; 1. Modern JSON Messaging - If $sFirstChar = "{" Or $sFirstChar = "[" Then - __DW("+> : Processing JSON message..." & @CRLF) - Local $oJson = ObjCreate("NetJson.Parser") - If Not IsObj($oJson) Then Return ConsoleWrite("!> Error: Failed to create NetJson object." & @CRLF) - - $oJson.Parse($sMsg) - Local $sJobType = $oJson.GetTokenValue("type") - - Switch $sJobType - Case "COM_TEST" - __DW("- COM_TEST Confirmed: " & $oJson.GetTokenValue("status") & @CRLF) - EndSwitch - - Else - ; 2. Legacy / Native Pipe-Delimited Messaging - __DW("+> : Processing Delimited message..." & @CRLF, 0) - Local $sCommand, $sData, $iSplitPos - $iSplitPos = StringInStr($sMsg, "|") - 1 - - If $iSplitPos < 0 Then - $sCommand = StringStripWS($sMsg, 3) - $sData = "" - Else - $sCommand = StringStripWS(StringLeft($sMsg, $iSplitPos), 3) - $sData = StringTrimLeft($sMsg, $iSplitPos + 1) - EndIf - - Switch $sCommand - Case "JSON_CLICKED" - Local $aClickData = StringSplit($sData, "=", 2) ; Split "Key = Value" - If UBound($aClickData) >= 2 Then - Local $sKey = StringStripWS($aClickData[0], 3) - Local $sVal = StringStripWS($aClickData[1], 3) - __DW("+++ Property: " & $sKey & " | Value: " & $sVal & @CRLF) - EndIf - Case "COM_TEST" - __DW("- Status: Legacy COM_TEST: " & $sData & @CRLF) - - Case "ERROR" - __DW("! Status: " & $sData & @CRLF) - EndSwitch - EndIf -EndFunc ;==>JavaScript_OnMessageReceived - -Func WebEvents_OnContextMenuRequested($sLink, $iX, $iY, $sSelection) - #forceref $sLink, $iX, $iY, $sSelection -EndFunc ;==>WebEvents_OnContextMenuRequested + If IsObj($oWebV2M) Then $oWebV2M.Cleanup() + $oWebV2M = 0 + $oJS = 0 + _NetWebView2_ShutDown() -#EndRegion ; === EVENT HANDLERS === +EndFunc ;==>Main #Region ; === UTILS === -Func _ErrFunc($oError) ; Global COM Error Handler - ConsoleWrite('@@ Line(' & $oError.scriptline & ') : COM Error Number: (0x' & Hex($oError.number, 8) & ') ' & $oError.windescription & @CRLF) -EndFunc ;==>_ErrFunc - -; Debug Write utility -Func __DW($sString, $iErrorNoLineNo = 1, $iLine = @ScriptLineNumber, $iError = @error, $iExtended = @extended) - If Not $g_DebugInfo Then Return SetError($iError, $iExtended, 0) - Local $iReturn - If $iErrorNoLineNo = 1 Then - If $iError Then - $iReturn = ConsoleWrite("@@(" & $iLine & ") :: @error:" & $iError & ", @extended:" & $iExtended & ", " & $sString) - Else - $iReturn = ConsoleWrite("+>(" & $iLine & ") :: " & $sString) - EndIf - Else - $iReturn = ConsoleWrite($sString) - EndIf - Return SetError($iError, $iExtended, $iReturn) -EndFunc ;==>__DW - -Func _NetJson_New($sInitialJson = "{}") - Local $oParser = ObjCreate("NetJson.Parser") - If Not IsObj($oParser) Then Return SetError(1, 0, 0) - If $sInitialJson <> "" Then $oParser.Parse($sInitialJson) - Return $oParser -EndFunc ;==>_NetJson_New - ; #FUNCTION# ==================================================================================================================== ; Name...........: _Web_jsonTree ; Description....: Renders JSON data using the jsonTree library by summerstyle. ; Author.........: summerstyle (https://github.com/summerstyle/jsonTreeViewer) ; Integration....: Adapted for AutoIt WebView2 ; =============================================================================================================================== -Func _Web_jsonTree(ByRef $oWeb, $sJson) +Func _Web_jsonTree(ByRef $oWebV2M, $sJson) ; 1. Prepare JSON (Minify to prevent script errors from line breaks) - Local $oJsonObj = _NetJson_New($sJson) - $sJson = $oJsonObj.GetMinifiedJson() + Local $oJSON = _NetJson_CreateParser($sJson) +;~ _NetWebView2_ObjName_FlagsValue($oJSON) + $sJson = $oJSON.GetMinifiedJson() ; 2. Load local library files - Local $sJsLib = FileRead(@ScriptDir & "\JS_Lib\jsonTree.js") - Local $sCssLib = FileRead(@ScriptDir & "\JS_Lib\jsonTreeDark.css") + Local $sJsLib = FileRead(@ScriptDir & ".\JS_Lib\jsonTree.js") + Local $sCssLib = FileRead(@ScriptDir & ".\JS_Lib\jsonTreeDark.css") ; 3. Build HTML with embedded Logic Local $sHTML = "