Skip to content

Commit 33eb55d

Browse files
authored
Merge pull request #89 from mlipok/patch-2
refactoring _NetWebView2_LoadWait() by adding __NetWebView2_WaitForReadyState()
2 parents 3eb5bd8 + 738ae00 commit 33eb55d

19 files changed

Lines changed: 1129 additions & 905 deletions

NetWebView2Lib.au3

Lines changed: 520 additions & 247 deletions
Large diffs are not rendered by default.

examples/000-NetJson.Parser.au3

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <Array.au3>
77
#include <MsgBoxConstants.au3>
8+
#include "..\NetWebView2Lib.au3"
89

910
; Global objects handler for COM objects
1011
Global $oMyError = ObjEvent("AutoIt.Error", _ErrFunc)
@@ -14,18 +15,19 @@ _Example()
1415
Exit
1516

1617
Func _Example()
17-
; Initialize the COM Object
18-
Local $oJson = ObjCreate("NetJson.Parser")
19-
If Not IsObj($oJson) Then
18+
ConsoleWrite(@CRLF & "=== STARTING NETJSON TUTORIAL ===" & @CRLF)
19+
20+
#Region ; 0. Initialize the COM Object
21+
Local $oJson = _NetJson_CreateParser()
22+
If @error Then
2023
MsgBox(16, "Error", "Could not create NetWebView2Lib.JsonParser. Make sure the DLL is registered.")
2124
Return
2225
EndIf
26+
#EndRegion ; 0. Initialize the COM Object
2327

24-
ConsoleWrite(@CRLF & "=== STARTING NETJSON TUTORIAL ===" & @CRLF)
2528

26-
; ---------------------------------------------------------
29+
#Region ; 1. PARSING & BASICS
2730
ConsoleWrite(@CRLF & "+> 1. PARSING & BASICS <+" & @CRLF)
28-
; ---------------------------------------------------------
2931
Local $sRaw = '{"user": "John", "roles": ["Admin", "Tester"], "active": true}'
3032
$oJson.Parse($sRaw)
3133
ConsoleWrite("Full JSON: " & $oJson.GetJson() & @CRLF)
@@ -34,20 +36,22 @@ Func _Example()
3436
If $oJson.Exists("user") Then
3537
ConsoleWrite("- User exists: " & $oJson.GetTokenValue("user") & @CRLF)
3638
EndIf
39+
#EndRegion ; 1. PARSING & BASICS
40+
3741

38-
; ---------------------------------------------------------
42+
#Region ; 2. ARRAY OPERATIONS
3943
ConsoleWrite(@CRLF & "+> 2. ARRAY OPERATIONS <+" & @CRLF)
40-
; ---------------------------------------------------------
4144
; Get length of the 'roles' array
4245
Local $iRolesCount = $oJson.GetArrayLength("roles")
4346
ConsoleWrite("- Roles count: " & $iRolesCount & @CRLF)
4447

4548
; Get specific element from array
4649
ConsoleWrite("- First role: " & $oJson.GetTokenValue("roles[0]") & @CRLF)
50+
#EndRegion ; 2. ARRAY OPERATIONS
4751

48-
; ---------------------------------------------------------
52+
53+
#Region ; 2b. DEEP PATH NOTATION (The Power of JSON Path)
4954
ConsoleWrite(@CRLF & "+> 2b. DEEP PATH NOTATION (The Power of JSON Path) <+" & @CRLF)
50-
; ---------------------------------------------------------
5155
Local $sComplex = '{"store": {"book": [{"title": "Coding 101", "price": 10}, {"title": "AutoIt Guru", "price": 25}], "location": "Athens"}}'
5256
$oJson.Parse($sComplex)
5357

@@ -63,17 +67,19 @@ Func _Example()
6367
If $oJson.Exists("store.location") Then
6468
ConsoleWrite("- Store Location: " & $oJson.GetTokenValue("store.location") & @CRLF)
6569
EndIf
70+
#EndRegion ; 2b. DEEP PATH NOTATION (The Power of JSON Path)
71+
6672

67-
; ---------------------------------------------------------
73+
#Region ; 3. MODIFICATION (SetTokenValue)
6874
ConsoleWrite(@CRLF & "+> 3. MODIFICATION (SetTokenValue) <+" & @CRLF)
69-
; ---------------------------------------------------------
7075
$oJson.SetTokenValue("user", "George")
7176
$oJson.SetTokenValue("active", "false") ; Note: Values are sent as strings
7277
ConsoleWrite("- Updated User: " & $oJson.GetTokenValue("user") & @CRLF)
78+
#EndRegion ; 3. MODIFICATION (SetTokenValue)
79+
7380

74-
; ---------------------------------------------------------
81+
#Region ; 4. FILE I/O
7582
ConsoleWrite(@CRLF & "+> 4. FILE I/O <+" & @CRLF)
76-
; ---------------------------------------------------------
7783
; Save current state to a file
7884
$oJson.SaveToFile(@ScriptDir & "\settings.json")
7985
ConsoleWrite("JSON saved to file." & @CRLF)
@@ -84,49 +90,51 @@ Func _Example()
8490

8591
$oJson.LoadFromFile(@ScriptDir & "\settings.json")
8692
ConsoleWrite("- Reloaded from file, User is: " & $oJson.GetTokenValue("user") & @CRLF)
93+
#EndRegion ; 4. FILE I/O
8794

88-
; ---------------------------------------------------------
95+
96+
#Region ; 5. FORMATTING (Pretty vs Minified)
8997
ConsoleWrite(@CRLF & "+> 5. FORMATTING (Pretty vs Minified) <+" & @CRLF)
90-
; ---------------------------------------------------------
9198
ConsoleWrite(@CRLF & "--- PRETTY JSON ---" & @CRLF)
9299
ConsoleWrite($oJson.GetPrettyJson() & @CRLF)
93100

94101
ConsoleWrite(@CRLF & "--- MINIFIED JSON ---" & @CRLF)
95102
ConsoleWrite($oJson.GetMinifiedJson() & @CRLF)
103+
#EndRegion ; 5. FORMATTING (Pretty vs Minified)
104+
96105

97-
; ---------------------------------------------------------
106+
#Region ; 6. ESCAPING TOOLS (Utility Methods)
98107
ConsoleWrite(@CRLF & "+> 6. ESCAPING TOOLS (Utility Methods) <+" & @CRLF)
99-
; ---------------------------------------------------------
100108
Local $sDirtyString = 'Hello "World" \ Name'
101109
Local $sEscaped = $oJson.EscapeString($sDirtyString)
102110
ConsoleWrite("- Escaped: " & $sEscaped & @CRLF)
103111
ConsoleWrite("- Unescaped: " & $oJson.UnescapeString($sEscaped) & @CRLF)
112+
#EndRegion ; 6. ESCAPING TOOLS (Utility Methods)
104113

105-
; ---------------------------------------------------------
114+
115+
#Region ; 7. ADVANCED DATA INTELLIGENCE (v1.4.1)
106116
ConsoleWrite(@CRLF & "+> 7. ADVANCED DATA INTELLIGENCE (v1.4.1) <+" & @CRLF)
107-
; ---------------------------------------------------------
108117

109-
; ---------------------------------------------------------
118+
#Region ; 7.1 MERGE EXAMPLE
110119
ConsoleWrite(@CRLF & "+> 7.1 MERGE EXAMPLE <+" & @CRLF)
111-
; ---------------------------------------------------------
112120
; Let's merge some new data into our current JSON
113121
Local $sUpdate = '{"user": "Admin_SmartUser", "preferences": {"theme": "Dark", "notifications": true}}'
114122
$oJson.Merge($sUpdate)
115123
ConsoleWrite("- After Merge (User Updated & Prefs Added): " & $oJson.GetTokenValue("user") & @CRLF)
116124
ConsoleWrite("- New Nested Value: " & $oJson.GetTokenValue("preferences.theme") & @CRLF)
125+
#EndRegion ; 7.1 MERGE EXAMPLE
117126

118-
; ---------------------------------------------------------
127+
#Region ; 7.2 TYPE CHECKING
119128
ConsoleWrite(@CRLF & "+> 7.2 TYPE CHECKING <+" & @CRLF)
120-
; ---------------------------------------------------------
121129
; Check what kind of data we have at a specific path
122130
Local $sThemeType = $oJson.GetTokenType("preferences")
123131
Local $sUserType = $oJson.GetTokenType("user")
124132
ConsoleWrite("- 'preferences' type: " & $sThemeType & @CRLF) ; Should return Object
125133
ConsoleWrite("- 'user' type: " & $sUserType & @CRLF) ; Should return String
134+
#EndRegion ; 7.2 TYPE CHECKING
126135

127-
; ---------------------------------------------------------
136+
#Region ; 7.3 SEARCH (JSONPath)
128137
ConsoleWrite(@CRLF & "+> 7.3 SEARCH (JSONPath) <+" & @CRLF)
129-
; ---------------------------------------------------------
130138
; $..* Returns everything in a flat list (all values).
131139
; $.store.book[*].author Returns all authors in the book array.
132140
; $..book[0] Returns the first book, wherever the book array is.
@@ -145,18 +153,18 @@ Func _Example()
145153
; Expected result: ["AutoIt Guru"]
146154
Local $sFullObjects = $oJson.Search("$..book[?(@.price > 15)]")
147155
ConsoleWrite("- Full Objects : " & $sFullObjects & @CRLF)
156+
#EndRegion ; 7.3 SEARCH (JSONPath)
148157

149-
; ---------------------------------------------------------
158+
#Region ; 7.4 FLATTEN
150159
ConsoleWrite(@CRLF & "+> 7.4 FLATTEN <+" & @CRLF)
151-
; ---------------------------------------------------------
152160
; Convert the complex nested structure into a flat key-value list
153161
Local $sFlatJson = $oJson.Flatten()
154162
ConsoleWrite("- FLATTENED VIEW (Key.Path = Value)" & @CRLF)
155163
ConsoleWrite($sFlatJson & @CRLF)
164+
#EndRegion ; 7.4 FLATTEN
156165

157-
; ---------------------------------------------------------
166+
#Region ; 7.5 REMOVE TOKEN
158167
ConsoleWrite(@CRLF & "+> 7.5 REMOVE TOKEN <+" & @CRLF)
159-
; ---------------------------------------------------------
160168
; Remove the 'preferences' object completely
161169
Local $bRemoved = $oJson.RemoveToken("preferences")
162170

@@ -172,18 +180,18 @@ Func _Example()
172180
Else
173181
ConsoleWrite("- Verify existence: Gone! (Success)" & @CRLF)
174182
EndIf
183+
#EndRegion ; 7.5 REMOVE TOKEN
175184

176-
; ---------------------------------------------------------
185+
#Region ; 7.6 CLONE LOGIC
177186
ConsoleWrite(@CRLF & "+> 7.6 CLONE LOGIC <+" & @CRLF)
178-
; ---------------------------------------------------------
179187
; Check if we can backup our data
180188
If $oJson.CloneTo("BackupInstance") Then
181189
ConsoleWrite("- Data integrity check for cloning: OK" & @CRLF)
182190
EndIf
191+
#EndRegion ; 7.6 CLONE LOGIC
183192

184-
; ---------------------------------------------------------
193+
#Region ; 7.7 FLATTEN TO TABLE (_ArrayFromString ready)
185194
ConsoleWrite(@CRLF & "+> 7.7 FLATTEN TO TABLE (_ArrayFromString ready) <+" & @CRLF)
186-
; ---------------------------------------------------------
187195
Local $sTable = $oJson.FlattenToTable("|", @CRLF)
188196
Local $aFinalGrid = _ArrayFromString($sTable, "|", @CRLF, True)
189197

@@ -194,14 +202,16 @@ Func _Example()
194202
ConsoleWrite($i & ") " & $aFinalGrid[$i][0] & " = " & $aFinalGrid[$i][1] & @CRLF)
195203
Next
196204
EndIf
205+
#EndRegion ; 7.7 FLATTEN TO TABLE (_ArrayFromString ready)
197206

198-
; ---------------------------------------------------------
199-
ConsoleWrite(@CRLF & "--- TUTORIAL COMPLETED ---" & @CRLF)
200-
; ---------------------------------------------------------
201-
; Clean up object
207+
#EndRegion ; 7. ADVANCED DATA INTELLIGENCE (v1.4.1)
208+
209+
210+
#Region ; 8. Clean up object
202211
$oJson = Null
212+
#EndRegion ; 8. Clean up object
203213

204-
; ---------------------------------------------------------
214+
ConsoleWrite(@CRLF & "--- TUTORIAL COMPLETED ---" & @CRLF)
205215

206216
EndFunc ;==>_Example
207217

examples/001-BasicDemo.au3

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
Main()
1313

1414
Func Main()
15+
ConsoleWrite("! MicrosoftEdgeWebview2 : version check: " & _NetWebView2_IsAlreadyInstalled() & ' ERR=' & @error & ' EXT=' & @extended & @CRLF)
16+
1517
Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc)
1618
#forceref $oMyError
1719

@@ -32,31 +34,39 @@ Func Main()
3234
If @error Then Return SetError(@error, @extended, $oWebV2M)
3335

3436
Local $sProfileDirectory = @ScriptDir & "\NetWebView2Lib-UserDataFolder"
35-
_NetWebView2_Initialize($oWebV2M, $hGUI, $sProfileDirectory, 0, 0, 0, 0, True, True, True, 1.2, "0x2B2B2B")
37+
_NetWebView2_Initialize($oWebV2M, $hGUI, $sProfileDirectory, 0, 0, 0, 0, True, True, 1.2, "0x2B2B2B", False)
3638
If @error Then Return SetError(@error, @extended, $oWebV2M)
3739

38-
__Example_Log(@ScriptLineNumber, "After: _NetWebView2_Initialize()")
40+
__Example_Log(@ScriptLineNumber, "After: _NetWebView2_Initialize()" & @CRLF)
3941

4042
; navigate to HTML string - full fill the object with your own offline content - without downloading any content
43+
ConsoleWrite(@CRLF)
44+
45+
__Example_Log(@ScriptLineNumber, "Before: _NetWebView2_NavigateToString()")
4146
_NetWebView2_NavigateToString($oWebV2M, __GetDemoHTML())
47+
__Example_Log(@ScriptLineNumber, "After: _NetWebView2_NavigateToString()" & @CRLF)
4248
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'Watch Point - AFTER:' & @CRLF & 'navigate to string')
4349

4450
GUISetState(@SW_HIDE, $hGUI)
4551
WinMove($hGUI, '', Default, Default, 1100, 800)
4652

4753
; navigate to a given URL - online content
48-
_NetWebView2_Navigate($oWebV2M, 'https://www.microsoft.com', $NETWEBVIEW2_MESSAGE__TITLE_CHANGED, 5 * 1000)
54+
__Example_Log(@ScriptLineNumber, "Before: https://www.microsoft.com")
55+
_NetWebView2_Navigate($oWebV2M, 'https://www.microsoft.com', $NETWEBVIEW2_MESSAGE__TITLE_CHANGED, "", 5 * 1000)
56+
__Example_Log(@ScriptLineNumber, "After: https://www.microsoft.com" & @CRLF)
4957
GUISetState(@SW_SHOW, $hGUI)
5058
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'Watch Point - AFTER:' & @CRLF & 'navigate to a given URL - online content')
5159

5260
; navigate to fake/broken url
53-
_NetWebView2_Navigate($oWebV2M, 'htpppps://www.microsoft.com', $NETWEBVIEW2_MESSAGE__TITLE_CHANGED, 5 * 1000)
61+
__Example_Log(@ScriptLineNumber, "Before: htpppps://www.microsoft.com")
62+
_NetWebView2_Navigate($oWebV2M, 'htpppps://www.microsoft.com', $NETWEBVIEW2_MESSAGE__TITLE_CHANGED, "", 5 * 1000)
63+
__Example_Log(@ScriptLineNumber, "After: htpppps://www.microsoft.com" & @CRLF)
5464
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'Watch Point - AFTER:' & @CRLF & 'navigate to fake/broken url')
5565

5666
; navigate to fake not ex url
5767
__Example_Log(@ScriptLineNumber, "Before: https://w2ww.microsoft.com")
58-
_NetWebView2_Navigate($oWebV2M, 'https://w2ww.microsoft.com', $NETWEBVIEW2_MESSAGE__TITLE_CHANGED, 5 * 1000)
59-
__Example_Log(@ScriptLineNumber, "After: https://w2ww.microsoft.com")
68+
_NetWebView2_Navigate($oWebV2M, 'https://w2ww.microsoft.com', $NETWEBVIEW2_MESSAGE__TITLE_CHANGED, "", 5 * 1000)
69+
__Example_Log(@ScriptLineNumber, "After: https://w2ww.microsoft.com" & @CRLF)
6070
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'Watch Point - AFTER:' & @CRLF & 'navigate to fake/broken url' & @CRLF & 'HostNameNotResolved')
6171

6272
; Main Loop

0 commit comments

Comments
 (0)