quickwin 1.1.4 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.en.md +7 -3
  2. package/README.md +7 -3
  3. package/examples/exec_server.js +3535 -34
  4. package/examples/exec_server.ts +71 -26
  5. package/examples/exec_server_worker.js +45 -0
  6. package/examples/exec_server_worker.ts +39 -0
  7. package/examples/pdf_viewer.js +11 -10
  8. package/examples/setres.js +104 -0
  9. package/examples/setres.ts +120 -0
  10. package/examples/test_gallery.js +11 -10
  11. package/examples/test_react_lazy.js +11 -10
  12. package/examples/test_react_listbox.js +11 -10
  13. package/examples/test_root_window.js +11 -10
  14. package/examples/test_tab.js +11 -10
  15. package/lib/fetch.js +35 -7
  16. package/lib/fetch.ts +24 -4
  17. package/lib/text-measure.js +8 -6
  18. package/lib/text-measure.ts +8 -6
  19. package/main.js +46 -0
  20. package/package.json +2 -1
  21. package/quickwin.d.ts +2 -1
  22. package/qwin-nowasm-x86.exe +0 -0
  23. package/qwin-nowasm.exe +0 -0
  24. package/qwin-x86.exe +0 -0
  25. package/qwin.exe +0 -0
  26. package/test/run.js +4 -1
  27. package/test/run.ts +4 -1
  28. package/test/test_net_fetch.js +62 -0
  29. package/test/test_net_fetch.ts +72 -0
  30. package/test/test_react_complex.js +14 -13
  31. package/test/test_react_counter.js +11 -10
  32. package/test/test_react_flex.js +11 -10
  33. package/test/test_react_hidden.js +13 -12
  34. package/test/test_react_listview_link.js +11 -10
  35. package/test/test_react_render.js +11 -10
  36. package/test/test_wolfssl_read.js +201 -0
  37. package/test/test_wolfssl_read.ts +181 -0
  38. package/test/test_worker_concurrent.js +45 -0
  39. package/test/test_worker_concurrent.ts +56 -0
  40. package/test/test_worker_data_url.js +46 -0
  41. package/test/test_worker_data_url.ts +51 -0
@@ -15367,7 +15367,7 @@ var import_react_reconciler = __toESM(require_react_reconciler(), 1);
15367
15367
  var import_react = __toESM(require_react(), 1);
15368
15368
  var import_constants = __toESM(require_constants(), 1);
15369
15369
  import * as gui3 from "gui";
15370
- import * as os from "os";
15370
+ import * as os2 from "os";
15371
15371
 
15372
15372
  // _build/lib/react-qw/props.js
15373
15373
  import * as gui from "gui";
@@ -15488,6 +15488,7 @@ function calculateFlexLayout(flex, parentW, parentH, children) {
15488
15488
 
15489
15489
  // _build/lib/text-measure.js
15490
15490
  import * as ffi from "ffi";
15491
+ import * as os from "os";
15491
15492
  import * as win from "win";
15492
15493
  import * as gui2 from "gui";
15493
15494
  function loadProc(lib, name) {
@@ -15504,7 +15505,7 @@ var DrawTextW = loadProc(user32, "DrawTextW");
15504
15505
  var GetDC = loadProc(user32, "GetDC");
15505
15506
  var ReleaseDC = loadProc(user32, "ReleaseDC");
15506
15507
  var SelectObject = loadProc(gdi32, "SelectObject");
15507
- var FFI_TYPE_UINT642 = ffi.FFI_TYPE_UINT64;
15508
+ var FFI_HND = os.arch === "ia32" ? ffi.FFI_TYPE_UINT32 : ffi.FFI_TYPE_UINT64;
15508
15509
  var FFI_S32 = ffi.FFI_TYPE_SINT32;
15509
15510
  var FFI_PTR = ffi.FFI_TYPE_POINTER;
15510
15511
  function measureText(hdc, text, maxWidth) {
@@ -15512,14 +15513,14 @@ function measureText(hdc, text, maxWidth) {
15512
15513
  const rect = new ArrayBuffer(16);
15513
15514
  const dv = new DataView(rect);
15514
15515
  dv.setInt32(8, maxWidth, true);
15515
- ffi.ffiCall(DrawTextW, [FFI_TYPE_UINT642, FFI_PTR, FFI_S32, FFI_PTR, FFI_S32], [
15516
+ ffi.ffiCall(DrawTextW, [FFI_HND, FFI_PTR, FFI_S32, FFI_PTR, FFI_S32], [
15516
15517
  hdc,
15517
15518
  textBuf,
15518
15519
  -1,
15519
15520
  rect,
15520
15521
  1024
15521
15522
  /* gui.DrawTextFlag.CALCRECT */
15522
- ], FFI_TYPE_UINT642);
15523
+ ], FFI_S32);
15523
15524
  return { width: dv.getInt32(8, true), height: dv.getInt32(12, true) };
15524
15525
  }
15525
15526
  function getButtonIdealSize(hwnd2) {
@@ -15529,15 +15530,15 @@ function getButtonIdealSize(hwnd2) {
15529
15530
  return { width: dv.getInt32(0, true), height: dv.getInt32(4, true) };
15530
15531
  }
15531
15532
  function measureTextForHwnd(hwnd2, text) {
15532
- const hdc = ffi.ffiCall(GetDC, [FFI_TYPE_UINT642], [hwnd2], FFI_TYPE_UINT642);
15533
+ const hdc = ffi.ffiCall(GetDC, [FFI_HND], [hwnd2], FFI_HND);
15533
15534
  if (!hdc)
15534
15535
  return { width: 0, height: 0 };
15535
15536
  const hFont = gui2.SendMessage(hwnd2, 49, 0, 0);
15536
- const oldFont = hFont ? ffi.ffiCall(SelectObject, [FFI_TYPE_UINT642, FFI_TYPE_UINT642], [hdc, hFont], FFI_TYPE_UINT642) : 0;
15537
+ const oldFont = hFont ? ffi.ffiCall(SelectObject, [FFI_HND, FFI_HND], [hdc, hFont], FFI_HND) : 0;
15537
15538
  const result = measureText(hdc, text, 0);
15538
15539
  if (hFont)
15539
- ffi.ffiCall(SelectObject, [FFI_TYPE_UINT642, FFI_TYPE_UINT642], [hdc, oldFont], FFI_TYPE_UINT642);
15540
- ffi.ffiCall(ReleaseDC, [FFI_TYPE_UINT642, FFI_TYPE_UINT642], [hwnd2, hdc], FFI_S32);
15540
+ ffi.ffiCall(SelectObject, [FFI_HND, FFI_HND], [hdc, oldFont], FFI_HND);
15541
+ ffi.ffiCall(ReleaseDC, [FFI_HND, FFI_HND], [hwnd2, hdc], FFI_S32);
15541
15542
  const wr = gui2.GetWindowRect(hwnd2);
15542
15543
  const cr = gui2.GetClientRect(hwnd2);
15543
15544
  if (wr && cr) {
@@ -15850,10 +15851,10 @@ var hostConfig = {
15850
15851
  clearContainer(_container) {
15851
15852
  },
15852
15853
  scheduleTimeout(fn, delay) {
15853
- return os.setTimeout(fn, delay);
15854
+ return os2.setTimeout(fn, delay);
15854
15855
  },
15855
15856
  cancelTimeout(id) {
15856
- os.clearTimeout?.(id);
15857
+ os2.clearTimeout?.(id);
15857
15858
  },
15858
15859
  noTimeout: -1,
15859
15860
  supportsMutation: true,
@@ -15366,7 +15366,7 @@ var import_react_reconciler = __toESM(require_react_reconciler(), 1);
15366
15366
  var import_react = __toESM(require_react(), 1);
15367
15367
  var import_constants = __toESM(require_constants(), 1);
15368
15368
  import * as gui3 from "gui";
15369
- import * as os from "os";
15369
+ import * as os2 from "os";
15370
15370
 
15371
15371
  // _build/lib/react-qw/props.js
15372
15372
  import * as gui from "gui";
@@ -15487,6 +15487,7 @@ function calculateFlexLayout(flex, parentW, parentH, children) {
15487
15487
 
15488
15488
  // _build/lib/text-measure.js
15489
15489
  import * as ffi from "ffi";
15490
+ import * as os from "os";
15490
15491
  import * as win from "win";
15491
15492
  import * as gui2 from "gui";
15492
15493
  function loadProc(lib, name) {
@@ -15503,7 +15504,7 @@ var DrawTextW = loadProc(user32, "DrawTextW");
15503
15504
  var GetDC = loadProc(user32, "GetDC");
15504
15505
  var ReleaseDC = loadProc(user32, "ReleaseDC");
15505
15506
  var SelectObject = loadProc(gdi32, "SelectObject");
15506
- var FFI_TYPE_UINT642 = ffi.FFI_TYPE_UINT64;
15507
+ var FFI_HND = os.arch === "ia32" ? ffi.FFI_TYPE_UINT32 : ffi.FFI_TYPE_UINT64;
15507
15508
  var FFI_S32 = ffi.FFI_TYPE_SINT32;
15508
15509
  var FFI_PTR = ffi.FFI_TYPE_POINTER;
15509
15510
  function measureText(hdc, text, maxWidth) {
@@ -15511,14 +15512,14 @@ function measureText(hdc, text, maxWidth) {
15511
15512
  const rect = new ArrayBuffer(16);
15512
15513
  const dv = new DataView(rect);
15513
15514
  dv.setInt32(8, maxWidth, true);
15514
- ffi.ffiCall(DrawTextW, [FFI_TYPE_UINT642, FFI_PTR, FFI_S32, FFI_PTR, FFI_S32], [
15515
+ ffi.ffiCall(DrawTextW, [FFI_HND, FFI_PTR, FFI_S32, FFI_PTR, FFI_S32], [
15515
15516
  hdc,
15516
15517
  textBuf,
15517
15518
  -1,
15518
15519
  rect,
15519
15520
  1024
15520
15521
  /* gui.DrawTextFlag.CALCRECT */
15521
- ], FFI_TYPE_UINT642);
15522
+ ], FFI_S32);
15522
15523
  return { width: dv.getInt32(8, true), height: dv.getInt32(12, true) };
15523
15524
  }
15524
15525
  function getButtonIdealSize(hwnd) {
@@ -15528,15 +15529,15 @@ function getButtonIdealSize(hwnd) {
15528
15529
  return { width: dv.getInt32(0, true), height: dv.getInt32(4, true) };
15529
15530
  }
15530
15531
  function measureTextForHwnd(hwnd, text) {
15531
- const hdc = ffi.ffiCall(GetDC, [FFI_TYPE_UINT642], [hwnd], FFI_TYPE_UINT642);
15532
+ const hdc = ffi.ffiCall(GetDC, [FFI_HND], [hwnd], FFI_HND);
15532
15533
  if (!hdc)
15533
15534
  return { width: 0, height: 0 };
15534
15535
  const hFont = gui2.SendMessage(hwnd, 49, 0, 0);
15535
- const oldFont = hFont ? ffi.ffiCall(SelectObject, [FFI_TYPE_UINT642, FFI_TYPE_UINT642], [hdc, hFont], FFI_TYPE_UINT642) : 0;
15536
+ const oldFont = hFont ? ffi.ffiCall(SelectObject, [FFI_HND, FFI_HND], [hdc, hFont], FFI_HND) : 0;
15536
15537
  const result = measureText(hdc, text, 0);
15537
15538
  if (hFont)
15538
- ffi.ffiCall(SelectObject, [FFI_TYPE_UINT642, FFI_TYPE_UINT642], [hdc, oldFont], FFI_TYPE_UINT642);
15539
- ffi.ffiCall(ReleaseDC, [FFI_TYPE_UINT642, FFI_TYPE_UINT642], [hwnd, hdc], FFI_S32);
15539
+ ffi.ffiCall(SelectObject, [FFI_HND, FFI_HND], [hdc, oldFont], FFI_HND);
15540
+ ffi.ffiCall(ReleaseDC, [FFI_HND, FFI_HND], [hwnd, hdc], FFI_S32);
15540
15541
  const wr = gui2.GetWindowRect(hwnd);
15541
15542
  const cr = gui2.GetClientRect(hwnd);
15542
15543
  if (wr && cr) {
@@ -15849,10 +15850,10 @@ var hostConfig = {
15849
15850
  clearContainer(_container) {
15850
15851
  },
15851
15852
  scheduleTimeout(fn, delay) {
15852
- return os.setTimeout(fn, delay);
15853
+ return os2.setTimeout(fn, delay);
15853
15854
  },
15854
15855
  cancelTimeout(id) {
15855
- os.clearTimeout?.(id);
15856
+ os2.clearTimeout?.(id);
15856
15857
  },
15857
15858
  noTimeout: -1,
15858
15859
  supportsMutation: true,
@@ -15367,7 +15367,7 @@ var import_react_reconciler = __toESM(require_react_reconciler(), 1);
15367
15367
  var import_react = __toESM(require_react(), 1);
15368
15368
  var import_constants = __toESM(require_constants(), 1);
15369
15369
  import * as gui3 from "gui";
15370
- import * as os from "os";
15370
+ import * as os2 from "os";
15371
15371
 
15372
15372
  // _build/lib/react-qw/props.js
15373
15373
  import * as gui from "gui";
@@ -15488,6 +15488,7 @@ function calculateFlexLayout(flex, parentW, parentH, children) {
15488
15488
 
15489
15489
  // _build/lib/text-measure.js
15490
15490
  import * as ffi from "ffi";
15491
+ import * as os from "os";
15491
15492
  import * as win from "win";
15492
15493
  import * as gui2 from "gui";
15493
15494
  function loadProc(lib, name) {
@@ -15504,7 +15505,7 @@ var DrawTextW = loadProc(user32, "DrawTextW");
15504
15505
  var GetDC = loadProc(user32, "GetDC");
15505
15506
  var ReleaseDC = loadProc(user32, "ReleaseDC");
15506
15507
  var SelectObject = loadProc(gdi32, "SelectObject");
15507
- var FFI_TYPE_UINT642 = ffi.FFI_TYPE_UINT64;
15508
+ var FFI_HND = os.arch === "ia32" ? ffi.FFI_TYPE_UINT32 : ffi.FFI_TYPE_UINT64;
15508
15509
  var FFI_S32 = ffi.FFI_TYPE_SINT32;
15509
15510
  var FFI_PTR = ffi.FFI_TYPE_POINTER;
15510
15511
  function measureText(hdc, text, maxWidth) {
@@ -15512,14 +15513,14 @@ function measureText(hdc, text, maxWidth) {
15512
15513
  const rect = new ArrayBuffer(16);
15513
15514
  const dv = new DataView(rect);
15514
15515
  dv.setInt32(8, maxWidth, true);
15515
- ffi.ffiCall(DrawTextW, [FFI_TYPE_UINT642, FFI_PTR, FFI_S32, FFI_PTR, FFI_S32], [
15516
+ ffi.ffiCall(DrawTextW, [FFI_HND, FFI_PTR, FFI_S32, FFI_PTR, FFI_S32], [
15516
15517
  hdc,
15517
15518
  textBuf,
15518
15519
  -1,
15519
15520
  rect,
15520
15521
  1024
15521
15522
  /* gui.DrawTextFlag.CALCRECT */
15522
- ], FFI_TYPE_UINT642);
15523
+ ], FFI_S32);
15523
15524
  return { width: dv.getInt32(8, true), height: dv.getInt32(12, true) };
15524
15525
  }
15525
15526
  function getButtonIdealSize(hwnd2) {
@@ -15529,15 +15530,15 @@ function getButtonIdealSize(hwnd2) {
15529
15530
  return { width: dv.getInt32(0, true), height: dv.getInt32(4, true) };
15530
15531
  }
15531
15532
  function measureTextForHwnd(hwnd2, text) {
15532
- const hdc = ffi.ffiCall(GetDC, [FFI_TYPE_UINT642], [hwnd2], FFI_TYPE_UINT642);
15533
+ const hdc = ffi.ffiCall(GetDC, [FFI_HND], [hwnd2], FFI_HND);
15533
15534
  if (!hdc)
15534
15535
  return { width: 0, height: 0 };
15535
15536
  const hFont = gui2.SendMessage(hwnd2, 49, 0, 0);
15536
- const oldFont = hFont ? ffi.ffiCall(SelectObject, [FFI_TYPE_UINT642, FFI_TYPE_UINT642], [hdc, hFont], FFI_TYPE_UINT642) : 0;
15537
+ const oldFont = hFont ? ffi.ffiCall(SelectObject, [FFI_HND, FFI_HND], [hdc, hFont], FFI_HND) : 0;
15537
15538
  const result = measureText(hdc, text, 0);
15538
15539
  if (hFont)
15539
- ffi.ffiCall(SelectObject, [FFI_TYPE_UINT642, FFI_TYPE_UINT642], [hdc, oldFont], FFI_TYPE_UINT642);
15540
- ffi.ffiCall(ReleaseDC, [FFI_TYPE_UINT642, FFI_TYPE_UINT642], [hwnd2, hdc], FFI_S32);
15540
+ ffi.ffiCall(SelectObject, [FFI_HND, FFI_HND], [hdc, oldFont], FFI_HND);
15541
+ ffi.ffiCall(ReleaseDC, [FFI_HND, FFI_HND], [hwnd2, hdc], FFI_S32);
15541
15542
  const wr = gui2.GetWindowRect(hwnd2);
15542
15543
  const cr = gui2.GetClientRect(hwnd2);
15543
15544
  if (wr && cr) {
@@ -15850,10 +15851,10 @@ var hostConfig = {
15850
15851
  clearContainer(_container) {
15851
15852
  },
15852
15853
  scheduleTimeout(fn, delay) {
15853
- return os.setTimeout(fn, delay);
15854
+ return os2.setTimeout(fn, delay);
15854
15855
  },
15855
15856
  cancelTimeout(id) {
15856
- os.clearTimeout?.(id);
15857
+ os2.clearTimeout?.(id);
15857
15858
  },
15858
15859
  noTimeout: -1,
15859
15860
  supportsMutation: true,
package/lib/fetch.js CHANGED
@@ -81,6 +81,10 @@ async function fetchRequest(req) {
81
81
  let receivedBytes = 0;
82
82
  const cleanupSocket = () => {
83
83
  state = ST_DONE;
84
+ if (timerId) {
85
+ clearTimeout(timerId);
86
+ timerId = undefined;
87
+ }
84
88
  if (ssl) {
85
89
  wolfssl.wolfSSL_free(ssl);
86
90
  ssl = null;
@@ -100,12 +104,38 @@ async function fetchRequest(req) {
100
104
  timerId = undefined;
101
105
  }
102
106
  };
107
+ const armTimeout = () => {
108
+ if (timerId) {
109
+ clearTimeout(timerId);
110
+ timerId = undefined;
111
+ }
112
+ timerId = setTimeout(() => {
113
+ timerId = undefined;
114
+ if (state === ST_DONE)
115
+ return;
116
+ if (!resolved) {
117
+ doReject(new Error('Request timeout'));
118
+ return;
119
+ }
120
+ if (state === ST_RECV_BODY && stream && _controller) {
121
+ try {
122
+ _controller.error(new Error('Body timeout'));
123
+ }
124
+ catch { /* already closed */ }
125
+ stream = null;
126
+ cleanupSocket();
127
+ }
128
+ }, timeout);
129
+ };
103
130
  const doResolve = (response) => {
104
- if (!resolved) {
105
- resolved = true;
131
+ if (resolved)
132
+ return;
133
+ resolved = true;
134
+ if (state === ST_DONE)
106
135
  cleanup();
107
- resolve(response);
108
- }
136
+ else
137
+ armTimeout();
138
+ resolve(response);
109
139
  };
110
140
  const doReject = (error) => {
111
141
  if (!resolved) {
@@ -115,9 +145,7 @@ async function fetchRequest(req) {
115
145
  reject(error);
116
146
  }
117
147
  };
118
- timerId = setTimeout(() => {
119
- doReject(new Error('Request timeout'));
120
- }, timeout);
148
+ armTimeout();
121
149
  s = sock.socket();
122
150
  if (s < 0) {
123
151
  doReject(new Error('Failed to create socket'));
package/lib/fetch.ts CHANGED
@@ -107,6 +107,7 @@ async function fetchRequest(req: RequestImpl): Promise<ResponseImpl> {
107
107
 
108
108
  const cleanupSocket = (): void => {
109
109
  state = ST_DONE
110
+ if (timerId) { clearTimeout(timerId); timerId = undefined }
110
111
  if (ssl) { wolfssl.wolfSSL_free(ssl); ssl = null }
111
112
  if (ctx) { wolfssl.wolfSSL_CTX_free(ctx); ctx = null }
112
113
  if (s !== null && s >= 0) { sock.closesocket(s); s = null }
@@ -116,17 +117,36 @@ async function fetchRequest(req: RequestImpl): Promise<ResponseImpl> {
116
117
  if (timerId) { clearTimeout(timerId); timerId = undefined }
117
118
  }
118
119
 
120
+ const armTimeout = (): void => {
121
+ if (timerId) { clearTimeout(timerId); timerId = undefined }
122
+ timerId = setTimeout(() => {
123
+ timerId = undefined
124
+ if (state === ST_DONE) return
125
+ if (!resolved) {
126
+ doReject(new Error('Request timeout'))
127
+ return
128
+ }
129
+ if (state === ST_RECV_BODY && stream && _controller) {
130
+ try { _controller.error(new Error('Body timeout')) } catch { /* already closed */ }
131
+ stream = null
132
+ cleanupSocket()
133
+ }
134
+ }, timeout)
135
+ }
136
+
119
137
  const doResolve = (response: ResponseImpl): void => {
120
- if (!resolved) { resolved = true; cleanup(); resolve(response) }
138
+ if (resolved) return
139
+ resolved = true
140
+ if (state === ST_DONE) cleanup()
141
+ else armTimeout()
142
+ resolve(response)
121
143
  }
122
144
 
123
145
  const doReject = (error: Error): void => {
124
146
  if (!resolved) { resolved = true; cleanup(); cleanupSocket(); reject(error) }
125
147
  }
126
148
 
127
- timerId = setTimeout(() => {
128
- doReject(new Error('Request timeout'))
129
- }, timeout)
149
+ armTimeout()
130
150
 
131
151
  s = sock.socket()
132
152
  if (s < 0) { doReject(new Error('Failed to create socket')); return }
@@ -1,4 +1,5 @@
1
1
  import * as ffi from 'ffi';
2
+ import * as os from 'os';
2
3
  import * as win from 'win';
3
4
  import * as gui from 'gui';
4
5
  function loadProc(lib, name) {
@@ -15,7 +16,8 @@ const DrawTextW = loadProc(user32, 'DrawTextW');
15
16
  const GetDC = loadProc(user32, 'GetDC');
16
17
  const ReleaseDC = loadProc(user32, 'ReleaseDC');
17
18
  const SelectObject = loadProc(gdi32, 'SelectObject');
18
- const FFI_TYPE_UINT64 = ffi.FFI_TYPE_UINT64;
19
+ // 句柄宽度随架构:ia32 上 HDC/HWND 是 32-bit,错用 UINT64 会导致 DrawTextW 参数错位、测宽为 0
20
+ const FFI_HND = os.arch === 'ia32' ? ffi.FFI_TYPE_UINT32 : ffi.FFI_TYPE_UINT64;
19
21
  const FFI_S32 = ffi.FFI_TYPE_SINT32;
20
22
  const FFI_PTR = ffi.FFI_TYPE_POINTER;
21
23
  export function measureText(hdc, text, maxWidth) {
@@ -23,7 +25,7 @@ export function measureText(hdc, text, maxWidth) {
23
25
  const rect = new ArrayBuffer(16);
24
26
  const dv = new DataView(rect);
25
27
  dv.setInt32(8, maxWidth, true);
26
- ffi.ffiCall(DrawTextW, [FFI_TYPE_UINT64, FFI_PTR, FFI_S32, FFI_PTR, FFI_S32], [hdc, textBuf, -1, rect, 1024 /* gui.DrawTextFlag.CALCRECT */], FFI_TYPE_UINT64);
28
+ ffi.ffiCall(DrawTextW, [FFI_HND, FFI_PTR, FFI_S32, FFI_PTR, FFI_S32], [hdc, textBuf, -1, rect, 1024 /* gui.DrawTextFlag.CALCRECT */], FFI_S32);
27
29
  return { width: dv.getInt32(8, true), height: dv.getInt32(12, true) };
28
30
  }
29
31
  export function getButtonIdealSize(hwnd) {
@@ -33,15 +35,15 @@ export function getButtonIdealSize(hwnd) {
33
35
  return { width: dv.getInt32(0, true), height: dv.getInt32(4, true) };
34
36
  }
35
37
  export function measureTextForHwnd(hwnd, text) {
36
- const hdc = ffi.ffiCall(GetDC, [FFI_TYPE_UINT64], [hwnd], FFI_TYPE_UINT64);
38
+ const hdc = ffi.ffiCall(GetDC, [FFI_HND], [hwnd], FFI_HND);
37
39
  if (!hdc)
38
40
  return { width: 0, height: 0 };
39
41
  const hFont = gui.SendMessage(hwnd, 49 /* gui.WmMsg.GETFONT */, 0, 0);
40
- const oldFont = hFont ? ffi.ffiCall(SelectObject, [FFI_TYPE_UINT64, FFI_TYPE_UINT64], [hdc, hFont], FFI_TYPE_UINT64) : 0;
42
+ const oldFont = hFont ? ffi.ffiCall(SelectObject, [FFI_HND, FFI_HND], [hdc, hFont], FFI_HND) : 0;
41
43
  const result = measureText(hdc, text, 0);
42
44
  if (hFont)
43
- ffi.ffiCall(SelectObject, [FFI_TYPE_UINT64, FFI_TYPE_UINT64], [hdc, oldFont], FFI_TYPE_UINT64);
44
- ffi.ffiCall(ReleaseDC, [FFI_TYPE_UINT64, FFI_TYPE_UINT64], [hwnd, hdc], FFI_S32);
45
+ ffi.ffiCall(SelectObject, [FFI_HND, FFI_HND], [hdc, oldFont], FFI_HND);
46
+ ffi.ffiCall(ReleaseDC, [FFI_HND, FFI_HND], [hwnd, hdc], FFI_S32);
45
47
  const wr = gui.GetWindowRect(hwnd);
46
48
  const cr = gui.GetClientRect(hwnd);
47
49
  if (wr && cr) {
@@ -1,4 +1,5 @@
1
1
  import * as ffi from 'ffi'
2
+ import * as os from 'os'
2
3
  import * as win from 'win'
3
4
  import * as gui from 'gui'
4
5
 
@@ -16,7 +17,8 @@ const GetDC = loadProc(user32, 'GetDC')
16
17
  const ReleaseDC = loadProc(user32, 'ReleaseDC')
17
18
  const SelectObject = loadProc(gdi32, 'SelectObject')
18
19
 
19
- const FFI_TYPE_UINT64 = ffi.FFI_TYPE_UINT64
20
+ // 句柄宽度随架构:ia32 上 HDC/HWND 是 32-bit,错用 UINT64 会导致 DrawTextW 参数错位、测宽为 0
21
+ const FFI_HND = os.arch === 'ia32' ? ffi.FFI_TYPE_UINT32 : ffi.FFI_TYPE_UINT64
20
22
  const FFI_S32 = ffi.FFI_TYPE_SINT32
21
23
  const FFI_PTR = ffi.FFI_TYPE_POINTER
22
24
 
@@ -25,7 +27,7 @@ export function measureText(hdc: number, text: string, maxWidth: number): { widt
25
27
  const rect = new ArrayBuffer(16)
26
28
  const dv = new DataView(rect)
27
29
  dv.setInt32(8, maxWidth, true)
28
- ffi.ffiCall(DrawTextW, [FFI_TYPE_UINT64, FFI_PTR, FFI_S32, FFI_PTR, FFI_S32], [hdc, textBuf, -1, rect, gui.DrawTextFlag.CALCRECT], FFI_TYPE_UINT64)
30
+ ffi.ffiCall(DrawTextW, [FFI_HND, FFI_PTR, FFI_S32, FFI_PTR, FFI_S32], [hdc, textBuf, -1, rect, gui.DrawTextFlag.CALCRECT], FFI_S32)
29
31
  return { width: dv.getInt32(8, true), height: dv.getInt32(12, true) }
30
32
  }
31
33
 
@@ -37,13 +39,13 @@ export function getButtonIdealSize(hwnd: gui.HWND): { width: number; height: num
37
39
  }
38
40
 
39
41
  export function measureTextForHwnd(hwnd: gui.HWND, text: string): { width: number; height: number } {
40
- const hdc = ffi.ffiCall(GetDC, [FFI_TYPE_UINT64], [hwnd], FFI_TYPE_UINT64)
42
+ const hdc = ffi.ffiCall(GetDC, [FFI_HND], [hwnd], FFI_HND)
41
43
  if (!hdc) return { width: 0, height: 0 }
42
44
  const hFont = gui.SendMessage(hwnd, gui.WmMsg.GETFONT, 0, 0)
43
- const oldFont = hFont ? ffi.ffiCall(SelectObject, [FFI_TYPE_UINT64, FFI_TYPE_UINT64], [hdc, hFont], FFI_TYPE_UINT64) : 0
45
+ const oldFont = hFont ? ffi.ffiCall(SelectObject, [FFI_HND, FFI_HND], [hdc, hFont], FFI_HND) : 0
44
46
  const result = measureText(hdc, text, 0)
45
- if (hFont) ffi.ffiCall(SelectObject, [FFI_TYPE_UINT64, FFI_TYPE_UINT64], [hdc, oldFont], FFI_TYPE_UINT64)
46
- ffi.ffiCall(ReleaseDC, [FFI_TYPE_UINT64, FFI_TYPE_UINT64], [hwnd, hdc], FFI_S32)
47
+ if (hFont) ffi.ffiCall(SelectObject, [FFI_HND, FFI_HND], [hdc, oldFont], FFI_HND)
48
+ ffi.ffiCall(ReleaseDC, [FFI_HND, FFI_HND], [hwnd, hdc], FFI_S32)
47
49
  const wr = gui.GetWindowRect(hwnd)
48
50
  const cr = gui.GetClientRect(hwnd)
49
51
  if (wr && cr) {
package/main.js ADDED
@@ -0,0 +1,46 @@
1
+ import { CallWindowProc, CreateSystemDpiFont, CreateWindow as CreateWindowWithoutScale, DefWindowProc, GetScaleFactor, GetWindowLongPtr, GetWindowText, RegisterClass, SendMessage, SetWindowProc, ShowWindow, } from "gui";
2
+ const scaleFactor = GetScaleFactor();
3
+ const dpiFont = CreateSystemDpiFont();
4
+ if (!dpiFont)
5
+ throw new Error('Failed to create DPI font');
6
+ const CreateWindow = (className, title, style, x, y, cx, cy, parent, id) => {
7
+ let hwnd = CreateWindowWithoutScale(className, title, style, x * scaleFactor, y * scaleFactor, cx * scaleFactor, cy * scaleFactor, parent, id);
8
+ if (hwnd)
9
+ SendMessage(hwnd, 48 /* WmMsg.SETFONT */, dpiFont, 1);
10
+ return hwnd;
11
+ };
12
+ let btn = null;
13
+ let edit = null;
14
+ let list = null;
15
+ function wndProc(hwnd, msg, wParam, lParam) {
16
+ if (msg === 1 /* WmMsg.CREATE */) {
17
+ btn = CreateWindow("BUTTON", "添加", 1073741824 /* WindowStyle.CHILD */ | 268435456 /* WindowStyle.VISIBLE */ | 0 /* ButtonStyle.PUSHBUTTON */, 120, 10, 80, 30, hwnd, null);
18
+ edit = CreateWindow("EDIT", "", 1073741824 /* WindowStyle.CHILD */ | 268435456 /* WindowStyle.VISIBLE */ | 8388608 /* WindowStyle.BORDER */, 10, 10, 100, 20, hwnd, null);
19
+ list = CreateWindow("LISTBOX", "", 1073741824 /* WindowStyle.CHILD */ | 268435456 /* WindowStyle.VISIBLE */ | 8388608 /* WindowStyle.BORDER */, 10, 40, 200, 100, hwnd, null);
20
+ if (!btn)
21
+ return 0;
22
+ const oldProc = GetWindowLongPtr(btn, -4 /* Gwlp.WNDPROC */);
23
+ SetWindowProc(btn, (hwnd, msg, wParam, lParam) => {
24
+ if (msg == 513 /* WmMsg.LBUTTONDOWN */) {
25
+ if (!edit)
26
+ return 0;
27
+ if (!list)
28
+ return 0;
29
+ const text = GetWindowText(edit);
30
+ if (text.trim())
31
+ SendMessage(list, 384 /* LbMsg.ADDSTRING */, 0, text);
32
+ return 0;
33
+ }
34
+ return CallWindowProc(oldProc, hwnd, msg, wParam, lParam);
35
+ });
36
+ return 0;
37
+ }
38
+ else if (msg === 273 /* WmMsg.COMMAND */) {
39
+ return 0;
40
+ }
41
+ return DefWindowProc(hwnd, msg, wParam, lParam);
42
+ }
43
+ RegisterClass("MainWindow", wndProc);
44
+ var hwnd = CreateWindow("MainWindow", "Todo List", 13565952 /* WindowStyle.OVERLAPPEDWINDOW */, 0, 0, 600, 400, null, null);
45
+ if (hwnd)
46
+ ShowWindow(hwnd);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "quickwin",
4
- "version": "1.1.4",
4
+ "version": "1.2.1",
5
5
  "description": "QuickJS Win32 runtime — GUI, networking, WASM, FFI, and more",
6
6
  "bin": {
7
7
  "quickwin": "qwin.exe",
@@ -18,6 +18,7 @@
18
18
  "qwin-nowasm.exe",
19
19
  "qwin-x86.exe",
20
20
  "qwin-nowasm-x86.exe",
21
+ "main.js",
21
22
  "lib/",
22
23
  "test/",
23
24
  "examples/",
package/quickwin.d.ts CHANGED
@@ -330,7 +330,7 @@ declare module "os" {
330
330
  const S_IFREG: number;
331
331
 
332
332
  class Worker {
333
- /** Constructor to create a new thread (worker) with an API close to the `WebWorkers`. `module_filename` is a string specifying the module filename which is executed in the newly created thread. */
333
+ /** Constructor to create a new thread (worker) with an API close to the `WebWorkers`. `module_filename` is a file path, `http(s)://` URL, or `data:text/javascript;base64,...` URL executed in the newly created thread. */
334
334
  constructor(module_filename: string);
335
335
  /** Send a message to the corresponding worker. `msg` is cloned in the destination worker using an algorithm similar to the `HTML` structured clone algorithm. */
336
336
  postMessage(msg: unknown): void;
@@ -386,6 +386,7 @@ declare module "wolfssl" {
386
386
  function wolfSSL_connect(ssl: WOLFSSL): number;
387
387
  function wolfSSL_shutdown(ssl: WOLFSSL): number;
388
388
  function wolfSSL_write(ssl: WOLFSSL, buf: ArrayBuffer): number;
389
+ /** 成功返回 ArrayBuffer;EOF/暂无数据/错误返回 null(区分用 wolfSSL_get_error:6=ZERO_RETURN 关闭,2=WANT_READ) */
389
390
  function wolfSSL_read(ssl: WOLFSSL, sz: number): ArrayBuffer | null;
390
391
  function wolfSSL_get_error(ssl: WOLFSSL, ret: number): number;
391
392
  function wolfSSL_UseSNI(ssl: WOLFSSL, type: SniType, name: string, len?: number): number;
Binary file
package/qwin-nowasm.exe CHANGED
Binary file
package/qwin-x86.exe CHANGED
Binary file
package/qwin.exe CHANGED
Binary file
package/test/run.js CHANGED
@@ -24,6 +24,7 @@ const suiteDefs = [
24
24
  { name: 'mupdf-render', file: './test_mupdf_render.js', tags: ['wasm', 'mupdf'] },
25
25
  { name: 'ffi', file: './test_ffi.js', tags: [] },
26
26
  { name: 'net-fetch', file: './test_net_fetch.js', tags: ['net'] },
27
+ { name: 'net-wolfssl-read', file: './test_wolfssl_read.js', tags: ['net'] },
27
28
  { name: 'net-websocket', file: './test_net_websocket.js', tags: ['net'] },
28
29
  { name: 'net-event', file: './test_net_event.js', tags: ['net'] },
29
30
  { name: 'http-server', file: './test_http_server.js', tags: ['net'] },
@@ -34,7 +35,9 @@ const suiteDefs = [
34
35
  { name: 'worker', file: './test_worker.js', tags: [] },
35
36
  { name: 'worker-wasm', file: './test_worker_wasm_concurrent.js', tags: ['wasm'] },
36
37
  { name: 'worker-http', file: './test_worker_net.js', tags: ['net'] },
37
- { name: 'worker-fetch', file: './test_worker_fetch.js', tags: ['net'] }
38
+ { name: 'worker-fetch', file: './test_worker_fetch.js', tags: ['net'] },
39
+ { name: 'worker-concurrent', file: './test_worker_concurrent.js', tags: [] },
40
+ { name: 'worker-data-url', file: './test_worker_data_url.js', tags: [] }
38
41
  ];
39
42
  async function main() {
40
43
  const filter = scriptArgs.length > 1 ? scriptArgs[1] : '';
package/test/run.ts CHANGED
@@ -28,6 +28,7 @@ const suiteDefs = [
28
28
  { name: 'mupdf-render', file: './test_mupdf_render.js', tags: ['wasm', 'mupdf'] },
29
29
  { name: 'ffi', file: './test_ffi.js', tags: [] },
30
30
  { name: 'net-fetch', file: './test_net_fetch.js', tags: ['net'] },
31
+ { name: 'net-wolfssl-read', file: './test_wolfssl_read.js', tags: ['net'] },
31
32
  { name: 'net-websocket', file: './test_net_websocket.js', tags: ['net'] },
32
33
  { name: 'net-event', file: './test_net_event.js', tags: ['net'] },
33
34
  { name: 'http-server', file: './test_http_server.js', tags: ['net'] },
@@ -38,7 +39,9 @@ const suiteDefs = [
38
39
  { name: 'worker', file: './test_worker.js', tags: [] },
39
40
  { name: 'worker-wasm', file: './test_worker_wasm_concurrent.js', tags: ['wasm'] },
40
41
  { name: 'worker-http', file: './test_worker_net.js', tags: ['net'] },
41
- { name: 'worker-fetch', file: './test_worker_fetch.js', tags: ['net'] }
42
+ { name: 'worker-fetch', file: './test_worker_fetch.js', tags: ['net'] },
43
+ { name: 'worker-concurrent', file: './test_worker_concurrent.js', tags: [] },
44
+ { name: 'worker-data-url', file: './test_worker_data_url.js', tags: [] }
42
45
  ]
43
46
 
44
47
  async function main(): Promise<void> {
@@ -1,5 +1,6 @@
1
1
  import '../lib/fetch.js';
2
2
  import * as std from 'std';
3
+ import * as os from 'os';
3
4
  export const suite = {
4
5
  name: 'net-fetch',
5
6
  run: async (t) => {
@@ -255,5 +256,66 @@ export const suite = {
255
256
  else {
256
257
  assert('https endpoint reachable', false);
257
258
  }
259
+ // ── large HTTPS body (wolfSSL_read null regression) ──
260
+ // Pre-fix: wolfSSL_read returned number -1 on WANT_READ →
261
+ // receivedBytes became NaN → stream never closed → hang.
262
+ t.section('large HTTPS body');
263
+ {
264
+ const LARGE = 200000;
265
+ try {
266
+ const r = await Promise.race([
267
+ fetch(`https://localhost:18924/large/${LARGE}`, { timeout: 15000 }),
268
+ new Promise((_, rej) => os.setTimeout(() => rej(new Error('Body hang watchdog 15s')), 15000))
269
+ ]);
270
+ assert('large HTTPS status 200', r.status === 200);
271
+ const buf = await Promise.race([
272
+ r.arrayBuffer(),
273
+ new Promise((_, rej) => os.setTimeout(() => rej(new Error('arrayBuffer hang watchdog 15s')), 15000))
274
+ ]);
275
+ assert('large HTTPS byteLength exact', buf.byteLength === LARGE);
276
+ }
277
+ catch (e) {
278
+ assert('large HTTPS completed without hang (' + String(e.message) + ')', false);
279
+ }
280
+ }
281
+ // ── large HTTP body (sock.recv path same null contract) ──
282
+ t.section('large HTTP body');
283
+ {
284
+ const LARGE = 200000;
285
+ try {
286
+ const r = await Promise.race([
287
+ fetch(`http://localhost:18923/large/${LARGE}`, { timeout: 15000 }),
288
+ new Promise((_, rej) => os.setTimeout(() => rej(new Error('Body hang watchdog 15s')), 15000))
289
+ ]);
290
+ assert('large HTTP status 200', r.status === 200);
291
+ const buf = await Promise.race([
292
+ r.arrayBuffer(),
293
+ new Promise((_, rej) => os.setTimeout(() => rej(new Error('arrayBuffer hang watchdog 15s')), 15000))
294
+ ]);
295
+ assert('large HTTP byteLength exact', buf.byteLength === LARGE);
296
+ }
297
+ catch (e) {
298
+ assert('large HTTP completed (' + String(e.message) + ')', false);
299
+ }
300
+ }
301
+ // ── body timeout after headers (armTimeout after doResolve) ──
302
+ t.section('HTTPS body timeout');
303
+ {
304
+ let rejected = false;
305
+ let msg = '';
306
+ try {
307
+ const r = await fetch('https://localhost:18924/stall', { timeout: 2000 });
308
+ await Promise.race([
309
+ r.arrayBuffer(),
310
+ new Promise((_, rej) => os.setTimeout(() => rej(new Error('Body timeout')), 8000))
311
+ ]);
312
+ }
313
+ catch (e) {
314
+ rejected = true;
315
+ msg = String(e.message);
316
+ }
317
+ assert('stall body rejects (timeout)', rejected);
318
+ assert('stall error mentions timeout', /timeout/i.test(msg));
319
+ }
258
320
  }
259
321
  };