|
1 | 1 | #AutoIt3Wrapper_UseX64=y |
2 | 2 | ; Html_Gui.au3 |
| 3 | +#include <Array.au3> |
| 4 | +#include <FileConstants.au3> |
3 | 5 | #include <GUIConstantsEx.au3> |
4 | 6 | #include <WindowsConstants.au3> |
5 | | -#include <Array.au3> |
6 | 7 |
|
7 | 8 | #include "..\NetWebView2Lib.au3" |
8 | 9 |
|
9 | 10 | ; Global variables for data management |
10 | 11 | Global $aMessages[0][3] |
11 | 12 | Global $sFilePath = @ScriptDir & "\messages.csv" |
12 | | -Global $hGUI |
13 | | - |
| 13 | +Global $hGUI, $oBridge, $idBlue, $idRed |
14 | 14 | Main() |
15 | 15 | Exit |
16 | 16 |
|
17 | 17 | Func Main() |
| 18 | + |
| 19 | + _Show_Form() |
| 20 | + |
| 21 | + ; Main Application Loop |
| 22 | + While 1 |
| 23 | + Switch GUIGetMsg() |
| 24 | + Case $GUI_EVENT_CLOSE |
| 25 | + _NetWebView2_CleanUp($_g_oWeb, $oBridge) |
| 26 | + ExitLoop |
| 27 | + |
| 28 | + Case $idBlue |
| 29 | + ; Update CSS variables dynamically via JavaScript |
| 30 | + _NetWebView2_ExecuteScript($_g_oWeb, "document.documentElement.style.setProperty('--accent-color', '#4db8ff');") |
| 31 | + _NetWebView2_ExecuteScript($_g_oWeb, "document.documentElement.style.setProperty('--btn-color', '#0078d7');") |
| 32 | + |
| 33 | + Case $idRed |
| 34 | + ; Update CSS variables dynamically via JavaScript |
| 35 | + _NetWebView2_ExecuteScript($_g_oWeb, "document.documentElement.style.setProperty('--accent-color', '#ff4d4d');") |
| 36 | + _NetWebView2_ExecuteScript($_g_oWeb, "document.documentElement.style.setProperty('--btn-color', '#d70000');") |
| 37 | + EndSwitch |
| 38 | + WEnd |
| 39 | + |
| 40 | +EndFunc ;==>Main |
| 41 | + |
| 42 | +Func _Show_Form() |
18 | 43 | ; Create GUI with resizing support |
19 | 44 | $hGUI = GUICreate("WebView2 Theme Switcher", 500, 480, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN)) |
20 | 45 | GUISetBkColor(0x1E1E1E) |
21 | 46 |
|
22 | | - Local $idBlue = GUICtrlCreateLabel("Blue Theme", 10, 10, 100, 30) |
| 47 | + $idBlue = GUICtrlCreateLabel("Blue Theme", 10, 10, 100, 30) |
23 | 48 | GUICtrlSetFont(-1, 12, Default, $GUI_FONTUNDER, "Segoe UI") |
24 | 49 | GUICtrlSetColor(-1, 0x0078D7) |
25 | 50 |
|
26 | | - Local $idRed = GUICtrlCreateLabel("Red Theme", 120, 10, 100, 30) |
| 51 | + $idRed = GUICtrlCreateLabel("Red Theme", 120, 10, 100, 30) |
27 | 52 | GUICtrlSetFont(-1, 12, Default, $GUI_FONTUNDER, "Segoe UI") |
28 | 53 | GUICtrlSetColor(-1, 0xFF0000) |
29 | 54 |
|
30 | 55 | ; Create WebView2 Manager object and register events |
31 | | - $_g_oWeb = _NetWebView2_CreateManager("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0", "__MyEVENTS_Manager_", "--allow-file-access-from-files") |
| 56 | + $_g_oWeb = _NetWebView2_CreateManager("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0", "__MyEVENTS_Manager_", "") |
32 | 57 |
|
33 | 58 | ; initialize browser - put it on the GUI |
34 | 59 | Local $sProfileDirectory = @TempDir & "\NetWebView2Lib-UserDataFolder" |
35 | 60 | _NetWebView2_Initialize($_g_oWeb, $hGUI, $sProfileDirectory, 0, 50, 500, 400, True, False, False, 1.1) |
36 | 61 |
|
37 | 62 | ; Create bridge object and register events |
38 | | - Local $oBridge = _NetWebView2_GetBridge($_g_oWeb, "__MyEVENTS_Bridge_") |
39 | | - #forceref $oBridge |
| 63 | + $oBridge = _NetWebView2_GetBridge($_g_oWeb, "__MyEVENTS_Bridge_") |
40 | 64 |
|
41 | 65 | $_g_oWeb.IsZoomControlEnabled = False |
42 | 66 | $_g_oWeb.IsScrollbarEnabled = False |
43 | 67 |
|
44 | 68 | ; Register the WM_SIZE message to handle window resizing |
45 | 69 | GUIRegisterMsg($WM_SIZE, WM_SIZE) |
46 | 70 |
|
47 | | - ; Main Application Loop |
48 | | - While 1 |
49 | | - Switch GUIGetMsg() |
50 | | - Case $GUI_EVENT_CLOSE |
51 | | - _NetWebView2_CleanUp($_g_oWeb, $oBridge) |
52 | | - ExitLoop |
| 71 | + Local $sHTML = "<html><head><meta charset='UTF-8'><style>:" & __FormCSS() & "</style></head><body>" & __FormHTML() & "</body></html>" |
| 72 | + $_g_oWeb.NavigateToString($sHTML) |
| 73 | + GUISetState(@SW_SHOW, $hGUI) |
53 | 74 |
|
54 | | - Case $idBlue |
55 | | - ; Update CSS variables dynamically via JavaScript |
56 | | - _NetWebView2_ExecuteScript($_g_oWeb, "document.documentElement.style.setProperty('--accent-color', '#4db8ff');") |
57 | | - _NetWebView2_ExecuteScript($_g_oWeb, "document.documentElement.style.setProperty('--btn-color', '#0078d7');") |
58 | | - |
59 | | - Case $idRed |
60 | | - ; Update CSS variables dynamically via JavaScript |
61 | | - _NetWebView2_ExecuteScript($_g_oWeb, "document.documentElement.style.setProperty('--accent-color', '#ff4d4d');") |
62 | | - _NetWebView2_ExecuteScript($_g_oWeb, "document.documentElement.style.setProperty('--btn-color', '#d70000');") |
63 | | - EndSwitch |
64 | | - WEnd |
65 | | - |
66 | | -EndFunc ;==>Main |
67 | | - |
68 | | -; Handles data received from the WebView2 Manager |
69 | | -Func __MyEVENTS_Manager_OnMessageReceived($sMessage) |
70 | | - ; Local error handler for COM objects |
71 | | - Local $oMyError = ObjEvent("AutoIt.Error", __HtmlGUI_ErrFunc) |
72 | | - #forceref $oMyError |
73 | | - |
74 | | - Local Static $bIsInitialized = False |
75 | | - If $sMessage = "INIT_READY" And Not $bIsInitialized Then |
76 | | - $bIsInitialized = True ; We note that we are finished. |
77 | | - Local $sHTML = "<html><head><meta charset='UTF-8'><style>:" & __FormCSS() & "</style></head><body>" & __FormHTML() & "</body></html>" |
78 | | - $_g_oWeb.NavigateToString($sHTML) |
79 | | - GUISetState(@SW_SHOW, $hGUI) |
80 | | - EndIf |
81 | | -EndFunc ;==>__MyEVENTS_Manager_OnMessageReceived |
| 75 | +EndFunc ;==>_Show_Form |
82 | 76 |
|
83 | 77 | ; Handles data received from the JavaScript 'postMessage' |
84 | 78 | Func __MyEVENTS_Bridge_OnMessageReceived($sMessage) |
@@ -106,7 +100,7 @@ Func __MyEVENTS_Bridge_OnMessageReceived($sMessage) |
106 | 100 | _ArrayAdd($aMessages, $sName & "|" & $sEmail & "|" & $sMsg) |
107 | 101 |
|
108 | 102 | ; Append data to CSV file safely |
109 | | - Local $hFile = FileOpen($sFilePath, 9) ; 1 (Write) + 8 (Create Path) |
| 103 | + Local $hFile = FileOpen($sFilePath, $FO_APPEND + $FO_CREATEPATH) |
110 | 104 | If $hFile <> -1 Then |
111 | 105 | ; Clean the message string for CSV compatibility (remove line breaks) |
112 | 106 | Local $sCleanMsg = StringReplace($sMsg, @CRLF, " ") |
|
0 commit comments