Skip to content

Commit e70bcff

Browse files
committed
fix(api/{ipc,shared-worker}): fix ipc message ports
1 parent a7d2464 commit e70bcff

File tree

14 files changed

+683
-18616
lines changed

14 files changed

+683
-18616
lines changed

api/README.md

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Creates a new window and returns an instance of ApplicationWindow.
7575
| opts.maximizable | boolean | | true | deterime if the window can be maximized. |
7676
| opts.margin | number | | true | a margin around the webview. (Private) |
7777
| opts.radius | number | | true | a radius on the webview. (Private) |
78-
| opts.index | number | | false | the index of the window. |
78+
| opts.index | number | -1 | true | the index of the window, if not provided or the value is `-1`, then one will be assigned |
7979
| opts.path | string | | false | the path to the HTML file to load into the window. |
8080
| opts.title | string | | true | the title of the window. |
8181
| opts.titlebarStyle | string | | true | determines the style of the titlebar (MacOS only). |
@@ -102,23 +102,23 @@ Creates a new window and returns an instance of ApplicationWindow.
102102
| :--- | :--- | :--- |
103103
| Not specified | Promise<ApplicationWindow> | |
104104

105-
### [`radius()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L274)
105+
### [`radius()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L280)
106106

107107

108108

109-
### [`margin()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L279)
109+
### [`margin()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L285)
110110

111111

112112

113-
## [`getScreenSize()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L367)
113+
## [`getScreenSize()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L373)
114114

115115
Returns the current screen size.
116116

117117
| Return Value | Type | Description |
118118
| :--- | :--- | :--- |
119119
| Not specified | Promise<{ width: number, height: number | >} |
120120

121-
## [`getWindows(indices)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L398)
121+
## [`getWindows(indices)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L404)
122122

123123
Returns the ApplicationWindow instances for the given indices or all windows if no indices are provided.
124124

@@ -130,7 +130,7 @@ Returns the ApplicationWindow instances for the given indices or all windows if
130130
| :--- | :--- | :--- |
131131
| Not specified | Promise<ApplicationWindowList> | |
132132

133-
## [`getWindow(index)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L452)
133+
## [`getWindow(index)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L458)
134134

135135
Returns the ApplicationWindow instance for the given index
136136

@@ -142,15 +142,15 @@ Returns the ApplicationWindow instance for the given index
142142
| :--- | :--- | :--- |
143143
| Not specified | Promise<ApplicationWindow> | the ApplicationWindow instance or null if the window does not exist |
144144

145-
## [`getCurrentWindow()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L462)
145+
## [`getCurrentWindow()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L468)
146146

147147
Returns the ApplicationWindow instance for the current window.
148148

149149
| Return Value | Type | Description |
150150
| :--- | :--- | :--- |
151151
| Not specified | Promise<ApplicationWindow> | |
152152

153-
## [`exit(code)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L471)
153+
## [`exit(code)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L477)
154154

155155
Quits the backend process and then quits the render process, the exit code used is the final exit code to the OS.
156156

@@ -162,7 +162,7 @@ Quits the backend process and then quits the render process, the exit code used
162162
| :--- | :--- | :--- |
163163
| Not specified | Promise<ipc.Result> | |
164164

165-
## [`setSystemMenu(options)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L568)
165+
## [`setSystemMenu(options)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L574)
166166

167167
Set the native menu for the app.
168168

@@ -257,11 +257,11 @@ Set the native menu for the app.
257257
| :--- | :--- | :--- |
258258
| Not specified | Promise<ipc.Result> | |
259259
260-
## [`setTrayMenu()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L575)
260+
## [`setTrayMenu()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L581)
261261
262262
An alias to setSystemMenu for creating a tary menu
263263
264-
## [`setSystemMenuItemEnabled(value)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L584)
264+
## [`setSystemMenuItemEnabled(value)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L590)
265265
266266
Set the enabled state of the system menu.
267267
@@ -273,31 +273,31 @@ Set the enabled state of the system menu.
273273
| :--- | :--- | :--- |
274274
| Not specified | Promise<ipc.Result> | |
275275
276-
## [`isPaused()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L592)
276+
## [`isPaused()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L598)
277277
278278
Predicate function to determine if application is in a "paused" state.
279279
280280
| Return Value | Type | Description |
281281
| :--- | :--- | :--- |
282282
| Not specified | boolean | |
283283
284-
## [runtimeVersion](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L600)
284+
## [runtimeVersion](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L606)
285285
286286
Socket Runtime version.
287287
288-
## [debug](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L606)
288+
## [debug](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L612)
289289
290290
Runtime debug flag.
291291
292-
## [config](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L612)
292+
## [config](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L618)
293293
294294
Application configuration.
295295
296-
## [backend](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L617)
296+
## [backend](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L623)
297297
298298
The application's backend instance.
299299
300-
### [`open(opts)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L623)
300+
### [`open(opts)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L629)
301301
302302
303303
@@ -310,7 +310,7 @@ The application's backend instance.
310310
| :--- | :--- | :--- |
311311
| Not specified | Promise<ipc.Result> | |
312312
313-
### [`close()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L631)
313+
### [`close()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/application.js#L637)
314314
315315
316316
@@ -1788,60 +1788,63 @@ Sends an async IPC command request with parameters.
17881788
This is a `FunctionDeclaration` named `inflateIPCMessageTransfers` in `api/ipc.js`, it's exported but undocumented.
17891789
17901790
1791-
## [`findIPCMessageTransfers()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L1762)
1791+
## [`findIPCMessageTransfers(transfers, object)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L1767)
17921792
1793-
This is a `FunctionDeclaration` named `findIPCMessageTransfers` in `api/ipc.js`, it's exported but undocumented.
17941793
17951794
1796-
## [ports](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L1821)
1797-
1798-
This is a `VariableDeclaration` named `ports` in `api/ipc.js`, it's exported but undocumented.
1795+
| Argument | Type | Default | Optional | Description |
1796+
| :--- | :--- | :---: | :---: | :--- |
1797+
| transfers | Set<any> | | false | |
1798+
| object | any | | false | |
17991799
1800+
| Return Value | Type | Description |
1801+
| :--- | :--- | :--- |
1802+
| Not specified | any | |
18001803
1801-
## [`IPCMessagePort` (extends `MessagePort`)](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L1823)
1804+
## [`IPCMessagePort` (extends `MessagePort`)](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L1812)
18021805
18031806
This is a `ClassDeclaration` named ``IPCMessagePort` (extends `MessagePort`)` in `api/ipc.js`, it's exported but undocumented.
18041807

18051808

1806-
## [`IPCMessageChannel` (extends `MessageChannel`)](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2061)
1809+
## [`IPCMessageChannel` (extends `MessageChannel`)](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2066)
18071810

18081811
This is a `ClassDeclaration` named ``IPCMessageChannel` (extends `MessageChannel`)` in `api/ipc.js`, it's exported but undocumented.
18091812
18101813
1811-
## [`IPCBroadcastChannel` (extends `EventTarget`)](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2102)
1814+
## [`IPCBroadcastChannel` (extends `EventTarget`)](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2136)
18121815
18131816
This is a `ClassDeclaration` named ``IPCBroadcastChannel` (extends `EventTarget`)` in `api/ipc.js`, it's exported but undocumented.
18141817

18151818

1816-
### [undefined](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2108)
1819+
### [undefined](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2142)
18171820

18181821

18191822

1820-
### [undefined](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2115)
1823+
### [undefined](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2149)
18211824

18221825

18231826

1824-
### [undefined](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2120)
1827+
### [undefined](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2154)
18251828

18261829

18271830

1828-
### [undefined](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2125)
1831+
### [undefined](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2159)
18291832

18301833

18311834

1832-
### [undefined](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2130)
1835+
### [undefined](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2164)
18331836

18341837

18351838

1836-
### [undefined](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2135)
1839+
### [undefined](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2169)
18371840

18381841

18391842

1840-
### [undefined](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2140)
1843+
### [undefined](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2174)
18411844

18421845

18431846

1844-
### [`constructor(name, )`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2146)
1847+
### [`constructor(name, )`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2180)
18451848

18461849

18471850

@@ -1850,23 +1853,23 @@ This is a `ClassDeclaration` named ``IPCBroadcastChannel` (extends `EventTarget`
18501853
| name | string | | false | |
18511854
| (Position 0) | { origin?: string | } options | false | |
18521855

1853-
### [`onmessage()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2171)
1856+
### [`onmessage()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2205)
18541857

18551858

18561859

1857-
### [`onmessageerror()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2188)
1860+
### [`onmessageerror()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2222)
18581861

18591862

18601863

1861-
### [`onerror()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2205)
1864+
### [`onerror()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2239)
18621865

18631866

18641867

1865-
### [event](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2253)
1868+
### [event](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2287)
18661869

18671870

18681871

1869-
### [`addEventListener(type, callback, , type, callback, )`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2286)
1872+
### [`addEventListener(type, callback, , type, callback, )`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/ipc.js#L2320)
18701873

18711874

18721875

@@ -3195,19 +3198,15 @@ Opens a file in the default file explorer.
31953198
| :--- | :--- | :--- |
31963199
| Not specified | Promise | |
31973200
3198-
### [`update(title)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L547)
3201+
### [`update()`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L546)
31993202
32003203
Updates wnidow state
32013204
3202-
| Argument | Type | Default | Optional | Description |
3203-
| :--- | :--- | :---: | :---: | :--- |
3204-
| title | string | | false | the title of the window |
3205-
32063205
| Return Value | Type | Description |
32073206
| :--- | :--- | :--- |
32083207
| Not specified | Promise<ipc.Result> | |
32093208
3210-
### [`addListener(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L559)
3209+
### [`addListener(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L558)
32113210
32123211
Adds a listener to the window.
32133212
@@ -3216,7 +3215,7 @@ Adds a listener to the window.
32163215
| event | string | | false | the event to listen to |
32173216
| cb | function(*): void | | false | the callback to call |
32183217
3219-
### [`on(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L577)
3218+
### [`on(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L576)
32203219
32213220
Adds a listener to the window. An alias for `addListener`.
32223221
@@ -3225,7 +3224,7 @@ Adds a listener to the window. An alias for `addListener`.
32253224
| event | string | | false | the event to listen to |
32263225
| cb | function(*): void | | false | the callback to call |
32273226
3228-
### [`once(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L594)
3227+
### [`once(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L593)
32293228
32303229
Adds a listener to the window. The listener is removed after the first call.
32313230
@@ -3234,7 +3233,7 @@ Adds a listener to the window. The listener is removed after the first call.
32343233
| event | string | | false | the event to listen to |
32353234
| cb | function(*): void | | false | the callback to call |
32363235
3237-
### [`removeListener(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L610)
3236+
### [`removeListener(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L609)
32383237
32393238
Removes a listener from the window.
32403239
@@ -3243,15 +3242,15 @@ Removes a listener from the window.
32433242
| event | string | | false | the event to remove the listener from |
32443243
| cb | function(*): void | | false | the callback to remove |
32453244
3246-
### [`removeAllListeners(event)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L623)
3245+
### [`removeAllListeners(event)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L622)
32473246
32483247
Removes all listeners from the window.
32493248
32503249
| Argument | Type | Default | Optional | Description |
32513250
| :--- | :--- | :---: | :---: | :--- |
32523251
| event | string | | false | the event to remove the listeners from |
32533252
3254-
### [`off(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L639)
3253+
### [`off(event, cb)`](https://github.com/socketsupply/socket/blob/v0.6.0-rc.8/api/window.js#L638)
32553254
32563255
Removes a listener from the window. An alias for `removeListener`.
32573256

api/application.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export function getCurrentWindowIndex () {
218218
* @param {boolean=} opts.maximizable - deterime if the window can be maximized.
219219
* @param {number} [opts.margin] - a margin around the webview. (Private)
220220
* @param {number} [opts.radius] - a radius on the webview. (Private)
221-
* @param {number} opts.index - the index of the window.
221+
* @param {number=} [opts.index = -1] - the index of the window, if not provided or the value is `-1`, then one will be assigned
222222
* @param {string} opts.path - the path to the HTML file to load into the window.
223223
* @param {string=} opts.title - the title of the window.
224224
* @param {string=} opts.titlebarStyle - determines the style of the titlebar (MacOS only).
@@ -249,7 +249,7 @@ export async function createWindow (opts) {
249249

250250
// default values
251251
const options = {
252-
targetWindowIndex: opts.index,
252+
targetWindowIndex: Number.isFinite(opts.index) ? opts.index : -1,
253253
url: formatURL(opts.path),
254254
index: globalThis.__args.index,
255255
title: opts.title ?? '',
@@ -269,6 +269,10 @@ export async function createWindow (opts) {
269269
shouldPreferServiceWorker: Boolean(opts.shouldPreferServiceWorker ?? false),
270270
// @ts-ignore
271271
reserved: Boolean(opts.reserved),
272+
// @ts-ignore
273+
unique: Boolean(opts.unique),
274+
// @ts-ignore
275+
token: opts.token || '',
272276
/**
273277
* @private
274278
* @type {number}

0 commit comments

Comments
 (0)