Skip to content

Commit

Permalink
Core re-design - Up to 10ms event speed
Browse files Browse the repository at this point in the history
- No breaking change
- Re-design the events again to up speed to 10ms
- Fix URL links click
  • Loading branch information
hassandraga committed Oct 2, 2023
1 parent aade3f2 commit e7418ef
Show file tree
Hide file tree
Showing 7 changed files with 1,563 additions and 1,608 deletions.
2,131 changes: 1,084 additions & 1,047 deletions bridge/webui_bridge.h

Large diffs are not rendered by default.

32 changes: 27 additions & 5 deletions bridge/webui_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ class WebuiBridge {
this.#closeReason = reason
this.#closeValue = value
this.#ws.close()
if (reason === this.#HEADER_NAVIGATION) {
if (this.#log) {
console.log(
`WebUI -> Close -> Navigation to [${value}]`
)
}
this.#allowNavigation = true
globalThis.location.replace(this.#closeValue)
}
else {
if (this.#log) {
console.log(
`WebUI -> Close.`
)
}
}
}

#freezeUi() {
Expand Down Expand Up @@ -212,6 +228,8 @@ class WebuiBridge {
}

#start() {
this.#callPromiseID[0] = 0

if (this.#bindList.includes(this.#winNum + '/')) {
this.#hasEvents = true
}
Expand All @@ -224,7 +242,6 @@ class WebuiBridge {
this.#ws.onopen = () => {
this.#wsStatus = true
this.#wsStatusOnce = true
this.#callPromiseID[0] = 0
if (this.#log) console.log('WebUI -> Connected')
this.#clicksListener()
}
Expand All @@ -239,11 +256,9 @@ class WebuiBridge {
if (this.#closeReason === this.#HEADER_NAVIGATION) {
if (this.#log) {
console.log(
`WebUI -> Connection closed -> Navigation to [${this.#closeValue}]`
`WebUI -> Connection closed du to Navigation to [${this.#closeValue}]`
)
}
this.#allowNavigation = true
globalThis.location.replace(this.#closeValue)
} else {
if (this.#log) {
console.log(`WebUI -> Connection lost (${event.code})`)
Expand Down Expand Up @@ -485,13 +500,20 @@ class WebuiBridge {
#isExternalLink(url: string) {
return new URL(url).host === globalThis.location.host
}

#closeWindowTimer() {
setTimeout(function () {
globalThis.close()
}, 1000)
}

#toUint8(value: number): number {
return value & 0xFF;
}

#callPromise(fn: string, value: any) {
const callId = --this.#callPromiseID[0]
--this.#callPromiseID[0]
const callId = this.#toUint8(this.#callPromiseID[0])
if (this.#log) console.log(`WebUI -> Call [${fn}](${value}) (ID:${this.#callPromiseID[0]})`)

// Response Packet
Expand Down
3 changes: 3 additions & 0 deletions examples/C/call_c_from_js/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ int main() {
// Wait until all windows get closed
webui_wait();

// Free all memory resources (Optional)
webui_clean();

return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions examples/C/call_js_from_c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int main() {
" <br>"
" <button id=\"MyButton1\">Manual Count</button>"
" <br>"
" <button id=\"MyTest\" OnClick=\"AutoTest();\">Auto Count (Every 100ms)</button>"
" <button id=\"MyTest\" OnClick=\"AutoTest();\">Auto Count (Every 10ms)</button>"
" <br>"
" <button id=\"MyButton2\">Exit</button>"
" <script>"
Expand All @@ -78,7 +78,7 @@ int main() {
" count = number;"
" }"
" function AutoTest(number) {"
" setInterval(function(){ webui.call('MyButton1'); }, 100);"
" setInterval(function(){ webui.call('MyButton1'); }, 10);"
" }"
" </script>"
" </body>"
Expand Down
3 changes: 3 additions & 0 deletions examples/C/serve_a_folder/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ int main() {
// Wait until all windows get closed
webui_wait();

// Free all memory resources (Optional)
webui_clean();

return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions examples/C/text-editor/text-editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ int main() {
// Wait until all windows get closed
webui_wait();

// Free all memory resources (Optional)
webui_clean();

return 0;
}

Expand Down
Loading

0 comments on commit e7418ef

Please sign in to comment.