Skip to content

Commit 7583815

Browse files
authored
MappedFolder
1 parent 15dad27 commit 7583815

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

examples/017-MappedFolder.au3

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#AutoIt3Wrapper_UseX64=y
2+
#AutoIt3Wrapper_Run_AU3Check=Y
3+
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
4+
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
5+
6+
; 017-MappedFolder.au3
7+
8+
#include <GUIConstantsEx.au3>
9+
#include <WindowsConstants.au3>
10+
11+
#include "..\NetWebView2Lib.au3"
12+
13+
_Example()
14+
15+
Func _Example()
16+
Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc)
17+
#forceref $oMyError
18+
19+
#Region ; GUI CREATION
20+
21+
; Create the GUI
22+
Local $hGUI = GUICreate("WebView2 .NET Manager - MappedFolder Demo", 1000, 800, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN))
23+
GUISetBkColor(0x1A1A1A, $hGUI)
24+
25+
; Initialize WebView2 Manager and register events
26+
Local $oWebV2M = _NetWebView2_CreateManager()
27+
If @error Then Return SetError(@error, @extended, $oWebV2M)
28+
29+
; initialize browser - put it on the GUI
30+
Local $sProfileDirectory = @ScriptDir & "\NetWebView2Lib-UserDataFolder"
31+
_NetWebView2_Initialize($oWebV2M, $hGUI, $sProfileDirectory, 0, 0, 0, 0, True, True, 1.2, "0x2B2B2B")
32+
33+
; Now that it is Ready, we define Mapping & Scripts
34+
Local $sLocalFolder = @ScriptDir & "\MappedFolder"
35+
_NetWebView2_SetVirtualHostNameToFolderMapping($oWebV2M, "myapp.local", $sLocalFolder, 0)
36+
37+
; Finish Navigate
38+
_NetWebView2_Navigate($oWebV2M, "https://myapp.local/index.html")
39+
40+
; show the GUI after browser was fully initialized
41+
GUISetState(@SW_SHOW)
42+
43+
#EndRegion ; GUI CREATION
44+
45+
46+
#Region ; GUI Loop
47+
; Main Loop
48+
While 1
49+
Switch GUIGetMsg()
50+
Case $GUI_EVENT_CLOSE
51+
ExitLoop
52+
EndSwitch
53+
WEnd
54+
55+
Local $oJSBridge
56+
_NetWebView2_CleanUp($oWebV2M, $oJSBridge)
57+
GUIDelete($hGUI)
58+
#EndRegion ; GUI Loop
59+
60+
EndFunc ;==>_Example
61+

examples/MappedFolder/index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>1.5.1 Virtual Host Demo</title>
6+
<style>
7+
body { background: #1a1a1a; color: #00ff00; font-family: 'Courier New', Courier, monospace; text-align: center; padding-top: 50px; }
8+
.box { border: 2px solid #00ff00; display: inline-block; padding: 20px; border-radius: 10px; }
9+
</style>
10+
</head>
11+
<body>
12+
<div class="box">
13+
<h1>🏠 Virtual Host Mapping OK!</h1>
14+
<p>This file is served from a local folder via <b>https://myapp.local</b></p>
15+
<p id="script-status">Initialization Script Status: Waiting...</p>
16+
</div>
17+
<script>
18+
// This will be updated by the initialization script if it wasn't removed too fast
19+
window.setScriptStatus = function(status) {
20+
document.getElementById('script-status').innerText = "Initialization Script Status: " + status;
21+
};
22+
</script>
23+
</body>
24+
</html>

0 commit comments

Comments
 (0)