|
| 1 | +*--------------------------------------------------------------- |
| 2 | +. |
| 3 | +. Program Name: embed.pls |
| 4 | +. Description: PL/B AI HTML to file embedding |
| 5 | +. |
| 6 | +. Revision History: |
| 7 | +. |
| 8 | +. Date: 08/13/2025 SM |
| 9 | +. Original code |
| 10 | +. |
| 11 | + |
| 12 | + INCLUDE plbequ.inc |
| 13 | + INCLUDE plbmeth.inc |
| 14 | + INCLUDE plbstdlib.inc |
| 15 | + |
| 16 | +*--------------------------------------------------------------- |
| 17 | +. |
| 18 | +. Runtime status variables |
| 19 | +. |
| 20 | +isGui BOOLEAN |
| 21 | +isWebSrv BOOLEAN |
| 22 | +isPlbSrv BOOLEAN |
| 23 | +isWebview BOOLEAN |
| 24 | +isWebCliApp BOOLEAN |
| 25 | +isSmallScreen BOOLEAN |
| 26 | + |
| 27 | +*--------------------------------------------------------------- |
| 28 | +. |
| 29 | +. Global data |
| 30 | +. |
| 31 | +mainForm PLFORM embed.plf |
| 32 | +chatDtMessages DATATABLE |
| 33 | +Client CLIENT |
| 34 | + |
| 35 | + %ENCRYPTON |
| 36 | +apiKey INIT "Add your OpenAI API key here" |
| 37 | + %ENCRYPTOFF |
| 38 | + |
| 39 | +*................................................................ |
| 40 | +. |
| 41 | +. Code start |
| 42 | +. |
| 43 | + CALL Main |
| 44 | + WINHIDE |
| 45 | + LOOP |
| 46 | + EVENTWAIT |
| 47 | + REPEAT |
| 48 | + STOP |
| 49 | + |
| 50 | +*................................................................ |
| 51 | +. |
| 52 | +. Check what type of runtime support we have |
| 53 | +. |
| 54 | +CheckStatus LFUNCTION |
| 55 | + ENTRY |
| 56 | +runtimeData DIM 50 |
| 57 | +runtimeVersion DIM 5 |
| 58 | +unused DIM 1 |
| 59 | +plbRuntime DIM 9 |
| 60 | +WidthData DIM 5 |
| 61 | +checkWidth FORM 5 |
| 62 | + |
| 63 | + GETMODE *GUI=isGui // Check for character mode runtime |
| 64 | + IF (isGui) |
| 65 | + CLOCK VERSION,runtimeData // Check windows console |
| 66 | + UNPACK runtimeData,runtimeVersion,unused,plbRuntime |
| 67 | + CHOP plbRuntime |
| 68 | + |
| 69 | + IF (NOCASE plbRuntime == "PLBCON") |
| 70 | + CLEAR isGui |
| 71 | + ENDIF |
| 72 | + IF (NOCASE plbRuntime == "PLBWEBSV") |
| 73 | + SET isWebSrv |
| 74 | + ENDIF |
| 75 | + IF (NOCASE plbRuntime == "PLBSERVE") |
| 76 | + SET isPlbSrv |
| 77 | + ENDIF |
| 78 | + ENDIF |
| 79 | + |
| 80 | + IF (isGui) |
| 81 | + WINHIDE |
| 82 | + |
| 83 | + Client.Getstate Giving isWebCliApp Using $CLI_STATE_CORDOVA |
| 84 | + Client.Getstate Giving isWebview Using $CLI_STATE_BOOTSTRAP5 |
| 85 | + |
| 86 | + IF (isWebSrv) // Check for a small screen (such as iphone) |
| 87 | + Client.GetWinInfo Giving WidthData Using 0x2 |
| 88 | + MOVE WidthData To checkWidth |
| 89 | + MOVE (checkWidth <= 700) to isSmallScreen |
| 90 | + ENDIF |
| 91 | + ENDIF |
| 92 | + |
| 93 | + FUNCTIONEND |
| 94 | + |
| 95 | +*................................................................ |
| 96 | +. |
| 97 | +. Load a supporting HTML file |
| 98 | +. |
| 99 | +LoadSupportHtml LFUNCTION |
| 100 | +htmlCtl HTMLCONTROL ^ |
| 101 | +fileName DIM 250 |
| 102 | + ENTRY |
| 103 | +htmlFile FILE |
| 104 | +htmlBuffer DIM ^ |
| 105 | +fileSize INTEGER 4 |
| 106 | +fullFileName DIM 250 |
| 107 | +seq FORM "-1" |
| 108 | + |
| 109 | + EXCEPTSET NoFile IF IO |
| 110 | + OPEN htmlFile,fileName,Read |
| 111 | + |
| 112 | + GETFILE htmlFile,TxtName=fullFileName ; Read the registration file into a buffer |
| 113 | + FINDFILE fullFileName,FileSize=fileSize |
| 114 | + IF (!fileSize) |
| 115 | + INCR fileSize |
| 116 | + ENDIF |
| 117 | + |
| 118 | + DMAKE htmlBuffer,fileSize |
| 119 | + READ htmlFile,Seq;*ABSON,htmlBuffer |
| 120 | + htmlCtl.InnerHtml Using htmlBuffer,$HTML_HAS_EVENTS |
| 121 | + CLOSE htmlFile |
| 122 | + DFREE htmlBuffer |
| 123 | +noFile |
| 124 | + FUNCTIONEND |
| 125 | + |
| 126 | +*................................................................ |
| 127 | +. |
| 128 | +. SetFocus - set focus on prompt input area and set tab IDs |
| 129 | +. |
| 130 | +SetFocus LFUNCTION |
| 131 | + ENTRY |
| 132 | + |
| 133 | + SETFOCUS embed |
| 134 | + embed.UpdateEvents |
| 135 | + |
| 136 | + FUNCTIONEND |
| 137 | + |
| 138 | +*................................................................ |
| 139 | +. |
| 140 | +. Main - Main program entry point |
| 141 | +. |
| 142 | +Main LFUNCTION |
| 143 | + ENTRY |
| 144 | +result FORM 4 |
| 145 | +jsCall DIM 4096 |
| 146 | +decryptedApiKey DIM 200 |
| 147 | + |
| 148 | + CALL CheckStatus |
| 149 | + IF (!isGui) |
| 150 | + KEYIN "This runtime can't run this program. ",result |
| 151 | + STOP |
| 152 | + ENDIF |
| 153 | + |
| 154 | + IF (!isWebview) |
| 155 | + ALERT STOP,"This program requires WebView support.",result |
| 156 | + STOP |
| 157 | + ENDIF |
| 158 | + |
| 159 | + IF (isWebCliApp || isSmallScreen) // On smaller screens change to % positioning for left and width |
| 160 | + SETMODE *PERCENTCONVERT=1 |
| 161 | + ENDIF |
| 162 | + |
| 163 | + FORMLOAD mainForm |
| 164 | + |
| 165 | + CALL LoadSupportHtml USING embed,"embed_sup.html" |
| 166 | + CALL SetFocus |
| 167 | + |
| 168 | + embedMain.SetAsClient |
| 169 | + Client.SetUTF8Convert Using 0 |
| 170 | + |
| 171 | + MOVE apiKey,decryptedApiKey |
| 172 | + DECRYPT decryptedApiKey |
| 173 | + PACK jsCall Using "setApiKey('",decryptedApiKey,"');" // set and give API key to the script |
| 174 | + Client.jsrun USING jsCall |
| 175 | + Client.FlushMessages |
| 176 | + |
| 177 | + FUNCTIONEND |
0 commit comments