Skip to content

Commit b60144c

Browse files
committed
refactor(api/{conduit,navigation,window}): promote 'socket:conduit', polyfill 'window.navigation, handle hide/close window events
1 parent 12db0e4 commit b60144c

File tree

16 files changed

+2537
-63
lines changed

16 files changed

+2537
-63
lines changed

api/README.md

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,7 +2869,7 @@ Retrieves the computed styles for a given element.
28692869
<!-- This file is generated by bin/docs-generator/api-module.js -->
28702870
<!-- Do not edit this file directly. -->
28712871

2872-
# [window](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L12)
2872+
# [window](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L13)
28732873

28742874

28752875
Provides ApplicationWindow class and methods
@@ -2878,131 +2878,131 @@ Retrieves the computed styles for a given element.
28782878
`socket:application` methods like `getCurrentWindow`, `createWindow`,
28792879
`getWindow`, and `getWindows`.
28802880
2881-
## [ApplicationWindow](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L35)
2881+
## [`ApplicationWindow` (extends `EventTarget`)](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L36)
28822882
28832883
Represents a window in the application
28842884
2885-
### [`id()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L69)
2885+
### [`id()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L98)
28862886
28872887
The unique ID of this window.
28882888
2889-
### [`index()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L77)
2889+
### [`index()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L106)
28902890
28912891
Get the index of the window
28922892
28932893
| Return Value | Type | Description |
28942894
| :--- | :--- | :--- |
28952895
| Not specified | number | the index of the window |
28962896
2897-
### [`hotkey()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L84)
2897+
### [`hotkey()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L113)
28982898
28992899
29002900
2901-
### [`channel()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L96)
2901+
### [`channel()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L125)
29022902
29032903
The broadcast channel for this window.
29042904
2905-
### [`size()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L104)
2905+
### [`size()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L133)
29062906
29072907
Get the size of the window
29082908
2909-
### [`position()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L119)
2909+
### [`position()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L148)
29102910
29112911
get the position of the window
29122912
2913-
### [`title()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L130)
2913+
### [`title()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L159)
29142914
29152915
get the title of the window
29162916
2917-
### [`token()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L137)
2917+
### [`token()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L166)
29182918
29192919
29202920
2921-
### [`status()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L145)
2921+
### [`status()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L174)
29222922
29232923
get the status of the window
29242924
2925-
### [`getSize()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L153)
2925+
### [`getSize()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L182)
29262926
29272927
Get the size of the window
29282928
29292929
| Return Value | Type | Description |
29302930
| :--- | :--- | :--- |
29312931
| Not specified | { width: number, height: number | } - the size of the window |
29322932
2933-
### [`getPosition()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L164)
2933+
### [`getPosition()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L193)
29342934
29352935
Get the position of the window
29362936
29372937
| Return Value | Type | Description |
29382938
| :--- | :--- | :--- |
29392939
| Not specified | { x: number, y: number | } - the position of the window |
29402940
2941-
### [`getTitle()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L175)
2941+
### [`getTitle()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L204)
29422942
29432943
Get the title of the window
29442944
29452945
| Return Value | Type | Description |
29462946
| :--- | :--- | :--- |
29472947
| Not specified | string | the title of the window |
29482948
2949-
### [`getStatus()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L183)
2949+
### [`getStatus()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L212)
29502950
29512951
Get the status of the window
29522952
29532953
| Return Value | Type | Description |
29542954
| :--- | :--- | :--- |
29552955
| Not specified | string | the status of the window |
29562956
2957-
### [`close()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L191)
2957+
### [`close()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L220)
29582958
29592959
Close the window
29602960
29612961
| Return Value | Type | Description |
29622962
| :--- | :--- | :--- |
29632963
| Not specified | Promise<object> | the options of the window |
29642964
2965-
### [`show()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L206)
2965+
### [`show()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L235)
29662966
29672967
Shows the window
29682968
29692969
| Return Value | Type | Description |
29702970
| :--- | :--- | :--- |
29712971
| Not specified | Promise<ipc.Result> | |
29722972
2973-
### [`hide()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L215)
2973+
### [`hide()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L244)
29742974
29752975
Hides the window
29762976
29772977
| Return Value | Type | Description |
29782978
| :--- | :--- | :--- |
29792979
| Not specified | Promise<ipc.Result> | |
29802980
2981-
### [`maximize()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L224)
2981+
### [`maximize()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L253)
29822982
29832983
Maximize the window
29842984
29852985
| Return Value | Type | Description |
29862986
| :--- | :--- | :--- |
29872987
| Not specified | Promise<ipc.Result> | |
29882988
2989-
### [`minimize()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L233)
2989+
### [`minimize()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L262)
29902990
29912991
Minimize the window
29922992
29932993
| Return Value | Type | Description |
29942994
| :--- | :--- | :--- |
29952995
| Not specified | Promise<ipc.Result> | |
29962996
2997-
### [`restore()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L242)
2997+
### [`restore()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L271)
29982998
29992999
Restore the window
30003000
30013001
| Return Value | Type | Description |
30023002
| :--- | :--- | :--- |
30033003
| Not specified | Promise<ipc.Result> | |
30043004
3005-
### [`setTitle(title)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L252)
3005+
### [`setTitle(title)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L281)
30063006
30073007
Sets the title of the window
30083008
@@ -3014,7 +3014,7 @@ Sets the title of the window
30143014
| :--- | :--- | :--- |
30153015
| Not specified | Promise<ipc.Result> | |
30163016
3017-
### [`setSize(opts)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L265)
3017+
### [`setSize(opts)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L294)
30183018
30193019
Sets the size of the window
30203020
@@ -3028,7 +3028,7 @@ Sets the size of the window
30283028
| :--- | :--- | :--- |
30293029
| Not specified | Promise<ipc.Result> | |
30303030
3031-
### [`setPosition(opts)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L308)
3031+
### [`setPosition(opts)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L337)
30323032
30333033
Sets the position of the window
30343034
@@ -3042,7 +3042,7 @@ Sets the position of the window
30423042
| :--- | :--- | :--- |
30433043
| Not specified | Promise<object> | |
30443044
3045-
### [`navigate(path)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L352)
3045+
### [`navigate(path)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L381)
30463046
30473047
Navigate the window to a given path
30483048
@@ -3054,15 +3054,15 @@ Navigate the window to a given path
30543054
| :--- | :--- | :--- |
30553055
| Not specified | Promise<ipc.Result> | |
30563056
3057-
### [`showInspector()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L361)
3057+
### [`showInspector()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L390)
30583058
30593059
Opens the Web Inspector for the window
30603060
30613061
| Return Value | Type | Description |
30623062
| :--- | :--- | :--- |
30633063
| Not specified | Promise<object> | |
30643064
3065-
### [`setBackgroundColor(opts)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L378)
3065+
### [`setBackgroundColor(opts)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L407)
30663066
30673067
Sets the background color of the window
30683068
@@ -3078,15 +3078,15 @@ Sets the background color of the window
30783078
| :--- | :--- | :--- |
30793079
| Not specified | Promise<object> | |
30803080
3081-
### [`getBackgroundColor()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L387)
3081+
### [`getBackgroundColor()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L416)
30823082
30833083
Gets the background color of the window
30843084
30853085
| Return Value | Type | Description |
30863086
| :--- | :--- | :--- |
30873087
| Not specified | Promise<object> | |
30883088
3089-
### [`setContextMenu(options)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L396)
3089+
### [`setContextMenu(options)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L425)
30903090
30913091
Opens a native context menu.
30923092
@@ -3098,7 +3098,7 @@ Opens a native context menu.
30983098
| :--- | :--- | :--- |
30993099
| Not specified | Promise<object> | |
31003100
3101-
### [`showOpenFilePicker(options)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L405)
3101+
### [`showOpenFilePicker(options)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L434)
31023102
31033103
Shows a native open file dialog.
31043104
@@ -3110,7 +3110,7 @@ Shows a native open file dialog.
31103110
| :--- | :--- | :--- |
31113111
| Not specified | Promise<string[]> | an array of file paths |
31123112
3113-
### [`showSaveFilePicker(options)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L423)
3113+
### [`showSaveFilePicker(options)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L452)
31143114
31153115
Shows a native save file dialog.
31163116
@@ -3122,7 +3122,7 @@ Shows a native save file dialog.
31223122
| :--- | :--- | :--- |
31233123
| Not specified | Promise<string[]> | an array of file paths |
31243124
3125-
### [`showDirectoryFilePicker(options)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L441)
3125+
### [`showDirectoryFilePicker(options)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L470)
31263126
31273127
Shows a native directory dialog.
31283128
@@ -3134,7 +3134,7 @@ Shows a native directory dialog.
31343134
| :--- | :--- | :--- |
31353135
| Not specified | Promise<string[]> | an array of file paths |
31363136
3137-
### [`send(options)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L466)
3137+
### [`send(options)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L495)
31383138
31393139
This is a high-level API that you should use instead of `ipc.request` when
31403140
you want to send a message to another window or to the backend.
@@ -3148,7 +3148,7 @@ This is a high-level API that you should use instead of `ipc.request` when
31483148
| options.event | string | | false | the event to send |
31493149
| options.value | string \| object | | true | the value to send |
31503150
3151-
### [`postMessage(data)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L507)
3151+
### [`postMessage(data)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L536)
31523152
31533153
Post a message to a window
31543154
TODO(@jwerle): research using `BroadcastChannel` instead
@@ -3161,7 +3161,7 @@ Post a message to a window
31613161
| :--- | :--- | :--- |
31623162
| Not specified | Promise | |
31633163
3164-
### [`openExternal(value)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L526)
3164+
### [`openExternal(value)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L555)
31653165
31663166
Opens an URL in the default application associated with the URL protocol,
31673167
such as 'https:' for the default web browser.
@@ -3174,7 +3174,7 @@ Opens an URL in the default application associated with the URL protocol,
31743174
| :--- | :--- | :--- |
31753175
| Not specified | Promise<{ url: string | >} |
31763176
3177-
### [`revealFile(value)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L541)
3177+
### [`revealFile(value)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L570)
31783178
31793179
Opens a file in the default file explorer.
31803180
@@ -3186,15 +3186,15 @@ Opens a file in the default file explorer.
31863186
| :--- | :--- | :--- |
31873187
| Not specified | Promise | |
31883188
3189-
### [`update()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L553)
3189+
### [`update()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L582)
31903190
31913191
Updates wnidow state
31923192
31933193
| Return Value | Type | Description |
31943194
| :--- | :--- | :--- |
31953195
| Not specified | Promise<ipc.Result> | |
31963196
3197-
### [`addListener(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L565)
3197+
### [`addListener(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L594)
31983198
31993199
Adds a listener to the window.
32003200
@@ -3203,7 +3203,7 @@ Adds a listener to the window.
32033203
| event | string | | false | the event to listen to |
32043204
| cb | function(*): void | | false | the callback to call |
32053205
3206-
### [`on(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L583)
3206+
### [`on(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L612)
32073207
32083208
Adds a listener to the window. An alias for `addListener`.
32093209
@@ -3212,7 +3212,7 @@ Adds a listener to the window. An alias for `addListener`.
32123212
| event | string | | false | the event to listen to |
32133213
| cb | function(*): void | | false | the callback to call |
32143214
3215-
### [`once(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L600)
3215+
### [`once(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L629)
32163216
32173217
Adds a listener to the window. The listener is removed after the first call.
32183218
@@ -3221,7 +3221,7 @@ Adds a listener to the window. The listener is removed after the first call.
32213221
| event | string | | false | the event to listen to |
32223222
| cb | function(*): void | | false | the callback to call |
32233223
3224-
### [`removeListener(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L616)
3224+
### [`removeListener(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L645)
32253225
32263226
Removes a listener from the window.
32273227
@@ -3230,15 +3230,15 @@ Removes a listener from the window.
32303230
| event | string | | false | the event to remove the listener from |
32313231
| cb | function(*): void | | false | the callback to remove |
32323232
3233-
### [`removeAllListeners(event)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L629)
3233+
### [`removeAllListeners(event)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L658)
32343234
32353235
Removes all listeners from the window.
32363236
32373237
| Argument | Type | Default | Optional | Description |
32383238
| :--- | :--- | :---: | :---: | :--- |
32393239
| event | string | | false | the event to remove the listeners from |
32403240
3241-
### [`off(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L645)
3241+
### [`off(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L674)
32423242
32433243
Removes a listener from the window. An alias for `removeListener`.
32443244

api/ai/chat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Context, Model } from './llm.js'
22
import { MessageEvent } from '../events.js'
3-
import { Conduit } from '../internal/conduit.js'
3+
import { Conduit } from '../conduit.js'
44
import { Buffer } from '../buffer.js'
55
import { rand64 } from '../crypto.js'
66
import process from '../process.js'

api/conduit.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* global CloseEvent, ErrorEvent, MessageEvent, WebSocket */
2-
import diagnostics from '../diagnostics.js'
3-
import { sleep } from '../timers.js'
4-
import client from '../application/client.js'
5-
import hooks from '../hooks.js'
6-
import ipc from '../ipc.js'
7-
import gc from '../gc.js'
2+
import diagnostics from './diagnostics.js'
3+
import { sleep } from './timers.js'
4+
import client from './application/client.js'
5+
import hooks from './hooks.js'
6+
import ipc from './ipc.js'
7+
import gc from './gc.js'
88

99
/**
1010
* Predicate state to determine if application is paused.

api/dgram.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { isArrayBufferView, isFunction, noop } from './util.js'
1414
import { murmur3, rand64 } from './crypto.js'
1515
import { InternalError } from './errors.js'
1616
import { AsyncResource } from './async/resource.js'
17-
import { Conduit } from './internal/conduit.js'
1817
import { EventEmitter } from './events.js'
18+
import { Conduit } from './conduit.js'
1919
import diagnostics from './diagnostics.js'
2020
import { Buffer } from './buffer.js'
2121
import { isIPv4 } from './ip.js'

api/fs/handle.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,13 @@ export class FileHandle extends EventEmitter {
882882

883883
buffer = Buffer.from(buffer).subarray(offset, offset + length)
884884

885+
if (buffer.byteLength === 0) {
886+
return {
887+
buffer,
888+
bytesWritten: 0
889+
}
890+
}
891+
885892
const params = { id: this.id, offset: position }
886893
const result = await ipc.write('fs.write', params, buffer, {
887894
timeout,

0 commit comments

Comments
 (0)