@krate/app 0.0.0-stage → 0.5.0-rc.7
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.
- package/LICENSE +201 -0
- package/README.md +88 -2
- package/dist/automation.d.ts +11 -0
- package/dist/automation.d.ts.map +1 -0
- package/dist/automation.js +27 -0
- package/dist/badge.d.ts +13 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +34 -0
- package/dist/chrome.d.ts +90 -0
- package/dist/chrome.d.ts.map +1 -0
- package/dist/chrome.js +133 -0
- package/dist/client.d.ts +26 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +545 -0
- package/dist/clipboard.d.ts +19 -0
- package/dist/clipboard.d.ts.map +1 -0
- package/dist/clipboard.js +51 -0
- package/dist/cookies.d.ts +44 -0
- package/dist/cookies.d.ts.map +1 -0
- package/dist/cookies.js +45 -0
- package/dist/crash.d.ts +35 -0
- package/dist/crash.d.ts.map +1 -0
- package/dist/crash.js +28 -0
- package/dist/db.d.ts +14 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +23 -0
- package/dist/dialog.d.ts +36 -0
- package/dist/dialog.d.ts.map +1 -0
- package/dist/dialog.js +23 -0
- package/dist/downloads.d.ts +35 -0
- package/dist/downloads.d.ts.map +1 -0
- package/dist/downloads.js +30 -0
- package/dist/driver.d.ts +190 -0
- package/dist/driver.d.ts.map +1 -0
- package/dist/driver.js +637 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +11 -0
- package/dist/events.d.ts +6 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +47 -0
- package/dist/extension.d.ts +10 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +25 -0
- package/dist/fakehost.d.ts +18 -0
- package/dist/fakehost.d.ts.map +1 -0
- package/dist/fakehost.js +199 -0
- package/dist/fs.d.ts +26 -0
- package/dist/fs.d.ts.map +1 -0
- package/dist/fs.js +38 -0
- package/dist/host.d.ts +4 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +25 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/kv.d.ts +6 -0
- package/dist/kv.d.ts.map +1 -0
- package/dist/kv.js +19 -0
- package/dist/lifecycle.d.ts +22 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +85 -0
- package/dist/login.d.ts +10 -0
- package/dist/login.d.ts.map +1 -0
- package/dist/login.js +8 -0
- package/dist/media.d.ts +50 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +70 -0
- package/dist/menu.d.ts +71 -0
- package/dist/menu.d.ts.map +1 -0
- package/dist/menu.js +114 -0
- package/dist/mock.d.ts +14 -0
- package/dist/mock.d.ts.map +1 -0
- package/dist/mock.js +47 -0
- package/dist/notify.d.ts +25 -0
- package/dist/notify.d.ts.map +1 -0
- package/dist/notify.js +32 -0
- package/dist/offscreen.d.ts +24 -0
- package/dist/offscreen.d.ts.map +1 -0
- package/dist/offscreen.js +27 -0
- package/dist/os.d.ts +20 -0
- package/dist/os.d.ts.map +1 -0
- package/dist/os.js +43 -0
- package/dist/page.d.ts +69 -0
- package/dist/page.d.ts.map +1 -0
- package/dist/page.js +61 -0
- package/dist/permission.d.ts +5 -0
- package/dist/permission.d.ts.map +1 -0
- package/dist/permission.js +18 -0
- package/dist/port.d.ts +35 -0
- package/dist/port.d.ts.map +1 -0
- package/dist/port.js +159 -0
- package/dist/power.d.ts +19 -0
- package/dist/power.d.ts.map +1 -0
- package/dist/power.js +35 -0
- package/dist/remote.d.ts +156 -0
- package/dist/remote.d.ts.map +1 -0
- package/dist/remote.js +115 -0
- package/dist/screen.d.ts +25 -0
- package/dist/screen.d.ts.map +1 -0
- package/dist/screen.js +23 -0
- package/dist/shortcut.d.ts +2 -0
- package/dist/shortcut.d.ts.map +1 -0
- package/dist/shortcut.js +44 -0
- package/dist/testing.d.ts +6 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +9 -0
- package/dist/theme.d.ts +12 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +13 -0
- package/dist/tray.d.ts +18 -0
- package/dist/tray.d.ts.map +1 -0
- package/dist/tray.js +23 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/updater.d.ts +36 -0
- package/dist/updater.d.ts.map +1 -0
- package/dist/updater.js +58 -0
- package/dist/window.d.ts +154 -0
- package/dist/window.d.ts.map +1 -0
- package/dist/window.js +205 -0
- package/dist/wire.d.ts +26 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +328 -0
- package/dist/worker-host.d.ts +6 -0
- package/dist/worker-host.d.ts.map +1 -0
- package/dist/worker-host.js +36 -0
- package/dist/worker.d.ts +62 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +86 -0
- package/package.json +188 -3
package/dist/page.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Web contents of a view: print, find in page, zoom and capture. Needs the
|
|
2
|
+
// "page" permission. A view is named by its id (a window id is its primary
|
|
3
|
+
// view); omit it for the view the call comes from.
|
|
4
|
+
import { call } from "./index.js";
|
|
5
|
+
import { subscribe } from "./events.js";
|
|
6
|
+
/** print opens the system print dialog for the view. */
|
|
7
|
+
function pagePrint(view = "") {
|
|
8
|
+
return call("krate/page.print", [view]);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* printToPdf renders the view to a PDF and resolves to its bytes. Write them
|
|
12
|
+
* with @krate/app/fs.writeFile, or hand them to Go host code.
|
|
13
|
+
*/
|
|
14
|
+
function pagePrintToPdf(options = {}) {
|
|
15
|
+
const { view = "", pageSize, margins, landscape, printBackground } = options;
|
|
16
|
+
const o = { landscape: landscape ?? false, printBackground: printBackground ?? false };
|
|
17
|
+
if (typeof pageSize === "string")
|
|
18
|
+
o.pageSize = pageSize;
|
|
19
|
+
else if (pageSize) {
|
|
20
|
+
o.pageWidth = pageSize.width;
|
|
21
|
+
o.pageHeight = pageSize.height;
|
|
22
|
+
}
|
|
23
|
+
if (margins) {
|
|
24
|
+
o.margins = { top: margins.top ?? 0, right: margins.right ?? 0, bottom: margins.bottom ?? 0, left: margins.left ?? 0 };
|
|
25
|
+
}
|
|
26
|
+
return call("krate/page.printToPdf", [view, o]);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* find searches for text, highlights the first match and reports the match
|
|
30
|
+
* count through onFind. Call it again with `continue: true` to step through
|
|
31
|
+
* the matches.
|
|
32
|
+
*/
|
|
33
|
+
function pageFind(text, options = {}) {
|
|
34
|
+
const { view = "", backward, matchCase, noWrap } = options;
|
|
35
|
+
return call("krate/page.find", [
|
|
36
|
+
view,
|
|
37
|
+
text,
|
|
38
|
+
{ backward: backward ?? false, matchCase: matchCase ?? false, noWrap: noWrap ?? false, continue: options.continue ?? false },
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
/** stopFind clears the highlight of the search. */
|
|
42
|
+
function pageStopFind(view = "") {
|
|
43
|
+
return call("krate/page.stopFind", [view]);
|
|
44
|
+
}
|
|
45
|
+
/** onFind calls fn with the result of every find until the returned function is called. */
|
|
46
|
+
function pageOnFind(fn, opts) {
|
|
47
|
+
return subscribe("krate/page.findEvents", fn, opts);
|
|
48
|
+
}
|
|
49
|
+
/** zoom resolves to the zoom factor of the view; 1 is 100 percent. */
|
|
50
|
+
function pageZoom(view = "") {
|
|
51
|
+
return call("krate/page.zoom", [view]);
|
|
52
|
+
}
|
|
53
|
+
/** setZoom sets the zoom factor, between 0.25 and 5. Ctrl/Cmd plus, minus and 0 also change it. */
|
|
54
|
+
function pageSetZoom(factor, view = "") {
|
|
55
|
+
return call("krate/page.setZoom", [view, factor]);
|
|
56
|
+
}
|
|
57
|
+
/** capture resolves to a PNG of the visible area of the view. */
|
|
58
|
+
function pageCapture(view = "") {
|
|
59
|
+
return call("krate/page.capture", [view]);
|
|
60
|
+
}
|
|
61
|
+
export { pagePrint as print, pagePrintToPdf as printToPdf, pageFind as find, pageStopFind as stopFind, pageOnFind as onFind, pageZoom as zoom, pageSetZoom as setZoom, pageCapture as capture };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type Permission = "os:info" | "kv" | "db" | "fs" | "fs:read" | "os:secrets" | "os:secrets.read" | "shell:openExternal" | "net" | (string & {});
|
|
2
|
+
export declare function query(name: Permission): Promise<boolean>;
|
|
3
|
+
export declare function isPermissionDenied(e: unknown): boolean;
|
|
4
|
+
export declare function deniedPermission(e: unknown): string | undefined;
|
|
5
|
+
//# sourceMappingURL=permission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission.d.ts","sourceRoot":"","sources":["../src/permission.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,SAAS,GACT,YAAY,GACZ,iBAAiB,GACjB,oBAAoB,GACpB,KAAK,GACL,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAGlB,wBAAgB,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAExD;AAGD,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAEtD;AAGD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAI/D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Ask the host which permissions this app has. Host id krate/permission.query,
|
|
2
|
+
// always allowed.
|
|
3
|
+
import { call, isKrateError } from "./index.js";
|
|
4
|
+
// True when app.json grants the permission (or a permission that implies it).
|
|
5
|
+
export function query(name) {
|
|
6
|
+
return call("krate/permission.query", [name], { dedupe: true });
|
|
7
|
+
}
|
|
8
|
+
// True when e is the error a call fails with when its permission is missing.
|
|
9
|
+
export function isPermissionDenied(e) {
|
|
10
|
+
return isKrateError(e) && e.code === "permission_denied";
|
|
11
|
+
}
|
|
12
|
+
// The permission a denied call lacked, or undefined for any other error.
|
|
13
|
+
export function deniedPermission(e) {
|
|
14
|
+
if (!isPermissionDenied(e))
|
|
15
|
+
return undefined;
|
|
16
|
+
const d = e.data;
|
|
17
|
+
return typeof d?.permission === "string" ? d.permission : undefined;
|
|
18
|
+
}
|
package/dist/port.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface PortEnds {
|
|
2
|
+
a: string;
|
|
3
|
+
b: string;
|
|
4
|
+
}
|
|
5
|
+
export interface PortMessageEvent<T = unknown> {
|
|
6
|
+
type: "message";
|
|
7
|
+
data: T;
|
|
8
|
+
}
|
|
9
|
+
export interface PortCloseEvent {
|
|
10
|
+
type: "close";
|
|
11
|
+
}
|
|
12
|
+
type Listener<E> = (e: E) => void;
|
|
13
|
+
export declare class Port {
|
|
14
|
+
#private;
|
|
15
|
+
readonly id: string;
|
|
16
|
+
onmessage: Listener<PortMessageEvent> | null;
|
|
17
|
+
onclose: Listener<PortCloseEvent> | null;
|
|
18
|
+
constructor(id: string);
|
|
19
|
+
get closed(): boolean;
|
|
20
|
+
postMessage(data: unknown): Promise<void>;
|
|
21
|
+
start(): void;
|
|
22
|
+
addEventListener(type: "message", fn: Listener<PortMessageEvent>): void;
|
|
23
|
+
addEventListener(type: "close", fn: Listener<PortCloseEvent>): void;
|
|
24
|
+
removeEventListener(type: "message" | "close", fn: Listener<never>): void;
|
|
25
|
+
close(): Promise<void>;
|
|
26
|
+
detach(): void;
|
|
27
|
+
}
|
|
28
|
+
export declare function createChannel(): Promise<{
|
|
29
|
+
port1: Port;
|
|
30
|
+
port2: Port;
|
|
31
|
+
}>;
|
|
32
|
+
export declare function transferPort(port: Port | string, to: string): Promise<void>;
|
|
33
|
+
export declare function portFromId(id: string): Port;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=port.d.ts.map
|
|
@@ -0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,IAAI,CAAA;CAAE,CAAC,CAG3E;AAOD,wBAAsB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIjF;AAGD,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAE3C"}
|
package/dist/port.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
12
|
+
var _Port_instances, _Port_listeners, _Port_abort, _Port_closed, _Port_dispatchMessage, _Port_finish;
|
|
13
|
+
// Message channels between windows, views and workers. Needs the "port"
|
|
14
|
+
// permission to create channels and the "port:receive" permission to use an
|
|
15
|
+
// end that was handed to this page.
|
|
16
|
+
//
|
|
17
|
+
// The engines give two top-level webviews no way to share a MessagePort, so a
|
|
18
|
+
// Port here is an object backed by the shell: messages go to the other end
|
|
19
|
+
// directly, without host code relaying them, and carry the same values as host
|
|
20
|
+
// calls (JSON, Uint8Array, Date, Map, Set). Inside one page the browser's own
|
|
21
|
+
// MessageChannel works as usual and is not replaced.
|
|
22
|
+
import { call, stream } from "./index.js";
|
|
23
|
+
import { isKrateError } from "./errors.js";
|
|
24
|
+
// A Port is one end of a channel. Setting onmessage or calling start() begins
|
|
25
|
+
// delivery; messages posted by the other end before that are queued by the
|
|
26
|
+
// shell (up to 1024 messages or 16 MiB).
|
|
27
|
+
export class Port {
|
|
28
|
+
constructor(id) {
|
|
29
|
+
_Port_instances.add(this);
|
|
30
|
+
this.onmessage = null;
|
|
31
|
+
this.onclose = null;
|
|
32
|
+
_Port_listeners.set(this, { message: new Set(), close: new Set() });
|
|
33
|
+
_Port_abort.set(this, void 0);
|
|
34
|
+
_Port_closed.set(this, false);
|
|
35
|
+
this.id = id;
|
|
36
|
+
// MessagePort starts when onmessage is first assigned; poll cheaply via a
|
|
37
|
+
// property so the common pattern port.onmessage = fn just works.
|
|
38
|
+
let handler = null;
|
|
39
|
+
Object.defineProperty(this, "onmessage", {
|
|
40
|
+
get: () => handler,
|
|
41
|
+
set: (fn) => {
|
|
42
|
+
handler = fn;
|
|
43
|
+
if (fn)
|
|
44
|
+
this.start();
|
|
45
|
+
},
|
|
46
|
+
enumerable: true,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
get closed() {
|
|
50
|
+
return __classPrivateFieldGet(this, _Port_closed, "f");
|
|
51
|
+
}
|
|
52
|
+
// postMessage sends a value to the other end. The promise rejects when the
|
|
53
|
+
// channel is closed, this page does not hold the end, or the other end has
|
|
54
|
+
// too many unread messages (code "port_full").
|
|
55
|
+
postMessage(data) {
|
|
56
|
+
return call("krate/port.post", [this.id, data]);
|
|
57
|
+
}
|
|
58
|
+
// start begins delivering messages. It is safe to call more than once.
|
|
59
|
+
start() {
|
|
60
|
+
if (__classPrivateFieldGet(this, _Port_abort, "f") || __classPrivateFieldGet(this, _Port_closed, "f"))
|
|
61
|
+
return;
|
|
62
|
+
const ac = (__classPrivateFieldSet(this, _Port_abort, new AbortController(), "f"));
|
|
63
|
+
void (async () => {
|
|
64
|
+
let sawClose = false;
|
|
65
|
+
try {
|
|
66
|
+
for await (const ev of stream("krate/port.listen", [this.id], { signal: ac.signal })) {
|
|
67
|
+
if (ev.closed) {
|
|
68
|
+
sawClose = true;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
__classPrivateFieldGet(this, _Port_instances, "m", _Port_dispatchMessage).call(this, ev.data);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
if (!ac.signal.aborted && !(isKrateError(e) && e.code === "not_found"))
|
|
76
|
+
console.error(e);
|
|
77
|
+
}
|
|
78
|
+
// A stream that ended without a close means the end moved away or the
|
|
79
|
+
// channel is gone; treat both as closed for this page.
|
|
80
|
+
if (!ac.signal.aborted || sawClose)
|
|
81
|
+
__classPrivateFieldGet(this, _Port_instances, "m", _Port_finish).call(this);
|
|
82
|
+
})();
|
|
83
|
+
}
|
|
84
|
+
addEventListener(type, fn) {
|
|
85
|
+
__classPrivateFieldGet(this, _Port_listeners, "f")[type].add(fn);
|
|
86
|
+
if (type === "message")
|
|
87
|
+
this.start();
|
|
88
|
+
}
|
|
89
|
+
removeEventListener(type, fn) {
|
|
90
|
+
__classPrivateFieldGet(this, _Port_listeners, "f")[type].delete(fn);
|
|
91
|
+
}
|
|
92
|
+
// close ends the channel for both ends. The other end reads what is queued,
|
|
93
|
+
// then sees the close.
|
|
94
|
+
async close() {
|
|
95
|
+
if (__classPrivateFieldGet(this, _Port_closed, "f"))
|
|
96
|
+
return;
|
|
97
|
+
__classPrivateFieldGet(this, _Port_abort, "f")?.abort();
|
|
98
|
+
__classPrivateFieldGet(this, _Port_instances, "m", _Port_finish).call(this);
|
|
99
|
+
try {
|
|
100
|
+
await call("krate/port.close", [this.id]);
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
if (!(isKrateError(e) && e.code === "not_found"))
|
|
104
|
+
throw e;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// detach stops this page from listening without closing the channel. It is
|
|
108
|
+
// what transfer() does before the end moves.
|
|
109
|
+
detach() {
|
|
110
|
+
__classPrivateFieldGet(this, _Port_abort, "f")?.abort();
|
|
111
|
+
__classPrivateFieldSet(this, _Port_abort, undefined, "f");
|
|
112
|
+
__classPrivateFieldSet(this, _Port_closed, true, "f");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
_Port_listeners = new WeakMap(), _Port_abort = new WeakMap(), _Port_closed = new WeakMap(), _Port_instances = new WeakSet(), _Port_dispatchMessage = function _Port_dispatchMessage(data) {
|
|
116
|
+
const ev = { type: "message", data };
|
|
117
|
+
for (const fn of [...__classPrivateFieldGet(this, _Port_listeners, "f").message, ...(this.onmessage ? [this.onmessage] : [])]) {
|
|
118
|
+
try {
|
|
119
|
+
fn(ev);
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
console.error(e);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, _Port_finish = function _Port_finish() {
|
|
126
|
+
if (__classPrivateFieldGet(this, _Port_closed, "f"))
|
|
127
|
+
return;
|
|
128
|
+
__classPrivateFieldSet(this, _Port_closed, true, "f");
|
|
129
|
+
const ev = { type: "close" };
|
|
130
|
+
for (const fn of [...__classPrivateFieldGet(this, _Port_listeners, "f").close, ...(this.onclose ? [this.onclose] : [])]) {
|
|
131
|
+
try {
|
|
132
|
+
fn(ev);
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
console.error(e);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
// createChannel makes a channel; this page holds both ends. Hand one to a
|
|
140
|
+
// window, view or worker with transferPort and keep the other.
|
|
141
|
+
export async function createChannel() {
|
|
142
|
+
const ends = await call("krate/port.channel", []);
|
|
143
|
+
return { port1: new Port(ends.a), port2: new Port(ends.b) };
|
|
144
|
+
}
|
|
145
|
+
// transferPort hands an end to a window or view (its id from window.list and
|
|
146
|
+
// window.views, or window.thisView in that page), a worker ("worker:<id>") or
|
|
147
|
+
// "" for host code. Afterwards this page can no longer use the end. Tell the
|
|
148
|
+
// receiver the port's id (for example with window.postMessage) and have it call
|
|
149
|
+
// portFromId. The receiver must have the "port:receive" permission.
|
|
150
|
+
export async function transferPort(port, to) {
|
|
151
|
+
const id = typeof port === "string" ? port : port.id;
|
|
152
|
+
await call("krate/port.transfer", [id, to]);
|
|
153
|
+
if (typeof port !== "string")
|
|
154
|
+
port.detach();
|
|
155
|
+
}
|
|
156
|
+
// portFromId wraps an end that was transferred to this page.
|
|
157
|
+
export function portFromId(id) {
|
|
158
|
+
return new Port(id);
|
|
159
|
+
}
|
package/dist/power.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type SubscribeOptions } from "./events.js";
|
|
2
|
+
export interface PowerState {
|
|
3
|
+
onBattery: boolean;
|
|
4
|
+
idleSeconds: number;
|
|
5
|
+
locked: boolean;
|
|
6
|
+
idleState: "active" | "idle" | "locked" | "unknown";
|
|
7
|
+
}
|
|
8
|
+
export type PowerEventKind = "suspend" | "resume" | "lock" | "unlock" | "ac" | "battery" | "idle" | "active";
|
|
9
|
+
export interface PowerEvent {
|
|
10
|
+
kind: PowerEventKind;
|
|
11
|
+
}
|
|
12
|
+
export declare function powerState(): Promise<PowerState>;
|
|
13
|
+
export declare function idleTime(): Promise<number>;
|
|
14
|
+
export declare function setIdleThreshold(seconds: number): Promise<void>;
|
|
15
|
+
export declare function preventSleep(reason: string, display?: boolean): Promise<string>;
|
|
16
|
+
export declare function allowSleep(id: string): Promise<void>;
|
|
17
|
+
export declare function onPowerEvent(fn: (e: PowerEvent) => void, opts?: SubscribeOptions): () => void;
|
|
18
|
+
export declare function onPower(kind: PowerEventKind, fn: () => void, opts?: SubscribeOptions): () => void;
|
|
19
|
+
//# sourceMappingURL=power.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"power.d.ts","sourceRoot":"","sources":["../src/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+
import { call } from "./index.js";
|
|
4
|
+
import { subscribe } from "./events.js";
|
|
5
|
+
export function powerState() {
|
|
6
|
+
return call("krate/power.state", []);
|
|
7
|
+
}
|
|
8
|
+
// idleTime resolves the seconds since the last input, or -1 when the platform
|
|
9
|
+
// cannot tell.
|
|
10
|
+
export function idleTime() {
|
|
11
|
+
return call("krate/power.idleTime", []);
|
|
12
|
+
}
|
|
13
|
+
// setIdleThreshold makes "idle" and "active" events fire when the idle time
|
|
14
|
+
// crosses it. 0 turns them off (the default).
|
|
15
|
+
export function setIdleThreshold(seconds) {
|
|
16
|
+
return call("krate/power.setIdleThreshold", [seconds]);
|
|
17
|
+
}
|
|
18
|
+
// preventSleep keeps the system awake (and the display on, with display)
|
|
19
|
+
// until allowSleep(id) or until the app exits. Resolves the blocker id.
|
|
20
|
+
export function preventSleep(reason, display = false) {
|
|
21
|
+
return call("krate/power.preventSleep", [reason, display]);
|
|
22
|
+
}
|
|
23
|
+
export function allowSleep(id) {
|
|
24
|
+
return call("krate/power.allowSleep", [id]);
|
|
25
|
+
}
|
|
26
|
+
export function onPowerEvent(fn, opts) {
|
|
27
|
+
return subscribe("krate/power.events", fn, opts);
|
|
28
|
+
}
|
|
29
|
+
// on calls fn for one kind of event.
|
|
30
|
+
export function onPower(kind, fn, opts) {
|
|
31
|
+
return onPowerEvent((e) => {
|
|
32
|
+
if (e.kind === kind)
|
|
33
|
+
fn();
|
|
34
|
+
}, opts);
|
|
35
|
+
}
|
package/dist/remote.d.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { type SubscribeOptions } from "./events.js";
|
|
2
|
+
import { Window, View } from "./window.js";
|
|
3
|
+
export interface RemoteOptions {
|
|
4
|
+
/** The first page, http or https. */
|
|
5
|
+
url: string;
|
|
6
|
+
/**
|
|
7
|
+
* The storage partition: "" (default) is a persistent partition for remote content that is never
|
|
8
|
+
* the app's, "persist:name" a named persistent one, "name" a named one that is gone when the app quits.
|
|
9
|
+
*/
|
|
10
|
+
partition?: string;
|
|
11
|
+
/** Origins the view may navigate to besides the origin of `url`: "https://example.com", "https://*.example.com". */
|
|
12
|
+
allow?: string[];
|
|
13
|
+
/** Let the view navigate to any https origin. */
|
|
14
|
+
allowAnyHttps?: boolean;
|
|
15
|
+
/** What happens to other navigations: "external" (default) opens the system browser, "block" drops them. */
|
|
16
|
+
blocked?: "external" | "block";
|
|
17
|
+
/** Turn on the message channel with the page. */
|
|
18
|
+
messages?: boolean;
|
|
19
|
+
/** A user agent for this view only. */
|
|
20
|
+
userAgent?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface RemoteWindowOptions extends RemoteOptions {
|
|
23
|
+
id?: string;
|
|
24
|
+
title?: string;
|
|
25
|
+
width?: number;
|
|
26
|
+
height?: number;
|
|
27
|
+
fixed?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface RemoteViewOptions extends RemoteOptions {
|
|
30
|
+
id?: string;
|
|
31
|
+
beside?: string;
|
|
32
|
+
side?: "right" | "left" | "top" | "bottom";
|
|
33
|
+
size?: number;
|
|
34
|
+
minWidth?: number;
|
|
35
|
+
minHeight?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface RemoteMessage {
|
|
38
|
+
/** The id of the view. */
|
|
39
|
+
view: string;
|
|
40
|
+
/** The origin of the page, read from the engine, never from the page. */
|
|
41
|
+
origin: string;
|
|
42
|
+
data: unknown;
|
|
43
|
+
}
|
|
44
|
+
export interface RemoteEvent {
|
|
45
|
+
view: string;
|
|
46
|
+
kind: "loaded" | "navBlocked";
|
|
47
|
+
url: string;
|
|
48
|
+
/** For navBlocked: "external" (opened in the browser) or "block". */
|
|
49
|
+
verdict: "allow" | "external" | "block";
|
|
50
|
+
}
|
|
51
|
+
export interface RemoteRequest {
|
|
52
|
+
view: string;
|
|
53
|
+
url: string;
|
|
54
|
+
method: string;
|
|
55
|
+
/** What the rules did: "", "block", "redirect" or "headers". */
|
|
56
|
+
action: "" | "block" | "redirect" | "headers";
|
|
57
|
+
}
|
|
58
|
+
export interface RemoteRule {
|
|
59
|
+
/** Match patterns: "<all_urls>" or "https://*.example.com/ads/*" (scheme * means http and https). */
|
|
60
|
+
urls: string[];
|
|
61
|
+
action: "block" | "redirect" | "headers";
|
|
62
|
+
/** For "redirect": an http(s) URL. */
|
|
63
|
+
redirect?: string;
|
|
64
|
+
/** For "headers": request headers to set. */
|
|
65
|
+
headers?: Record<string, string>;
|
|
66
|
+
}
|
|
67
|
+
/** Which requests a feature covers on this platform: "" none, "navigation" the main frame, "all". */
|
|
68
|
+
export type RemoteLevel = "" | "navigation" | "all";
|
|
69
|
+
export interface RemoteCapabilities {
|
|
70
|
+
observe: RemoteLevel;
|
|
71
|
+
block: RemoteLevel;
|
|
72
|
+
redirect: RemoteLevel;
|
|
73
|
+
requestHeaders: RemoteLevel;
|
|
74
|
+
userAgent: boolean;
|
|
75
|
+
proxy: boolean;
|
|
76
|
+
certificateErrors: boolean;
|
|
77
|
+
clientCertificates: boolean;
|
|
78
|
+
auth: boolean;
|
|
79
|
+
inMemory: boolean;
|
|
80
|
+
}
|
|
81
|
+
export interface RemoteProxy {
|
|
82
|
+
mode: "system" | "direct" | "fixed";
|
|
83
|
+
/** For "fixed": http://host:port, https://host:port or socks5://host:port. */
|
|
84
|
+
url?: string;
|
|
85
|
+
/** Hosts that skip the proxy. */
|
|
86
|
+
bypass?: string[];
|
|
87
|
+
}
|
|
88
|
+
export interface RemoteClearOptions {
|
|
89
|
+
cookies?: boolean;
|
|
90
|
+
cache?: boolean;
|
|
91
|
+
storage?: boolean;
|
|
92
|
+
}
|
|
93
|
+
export interface RemoteCertificateError {
|
|
94
|
+
id: number;
|
|
95
|
+
view: string;
|
|
96
|
+
url: string;
|
|
97
|
+
host: string;
|
|
98
|
+
/** "untrusted", "expired", "notYetValid", "mismatch", "revoked", "insecure" or "unknown". */
|
|
99
|
+
errors: string[];
|
|
100
|
+
}
|
|
101
|
+
export interface RemoteAuthChallenge {
|
|
102
|
+
id: number;
|
|
103
|
+
view: string;
|
|
104
|
+
host: string;
|
|
105
|
+
realm: string;
|
|
106
|
+
scheme: string;
|
|
107
|
+
proxy: boolean;
|
|
108
|
+
retry: boolean;
|
|
109
|
+
}
|
|
110
|
+
export interface RemoteCredentials {
|
|
111
|
+
user: string;
|
|
112
|
+
password: string;
|
|
113
|
+
}
|
|
114
|
+
/** openWindow opens a window that shows a remote page. */
|
|
115
|
+
declare function remoteOpenWindow(o: RemoteWindowOptions): Promise<Window>;
|
|
116
|
+
/** addView adds a remote view to a window (default: the main window). */
|
|
117
|
+
declare function remoteAddView(o: RemoteViewOptions, window?: string): Promise<View>;
|
|
118
|
+
/** navigate loads a URL in a remote view; the view's allowlist applies. */
|
|
119
|
+
declare function remoteNavigate(view: string, url: string): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* post sends a message to the page of a remote view created with `messages: true`. The page gets a
|
|
122
|
+
* "message" event whose origin is the app's. It is delivered only while the page is on `targetOrigin`
|
|
123
|
+
* ("*" skips the check).
|
|
124
|
+
*/
|
|
125
|
+
declare function remotePost(view: string, data: unknown, targetOrigin: string): Promise<void>;
|
|
126
|
+
/** onMessage calls fn for messages remote pages post with krateRemote.postMessage. */
|
|
127
|
+
declare function remoteOnMessage(fn: (m: RemoteMessage) => void, opts?: SubscribeOptions): () => void;
|
|
128
|
+
/** onEvent calls fn when a remote page loaded or a navigation was refused. */
|
|
129
|
+
declare function remoteOnEvent(fn: (e: RemoteEvent) => void, opts?: SubscribeOptions): () => void;
|
|
130
|
+
/** capabilities says what this platform can do for remote content. */
|
|
131
|
+
declare function remoteCapabilities(): Promise<RemoteCapabilities>;
|
|
132
|
+
/** setRules replaces the request rules of a partition (see RemoteRule and capabilities()). */
|
|
133
|
+
declare function remoteSetRules(partition: string, rules: RemoteRule[]): Promise<void>;
|
|
134
|
+
/** onRequest calls fn for the requests of remote views, with what the rules did. */
|
|
135
|
+
declare function remoteOnRequest(fn: (r: RemoteRequest) => void, opts?: SubscribeOptions): () => void;
|
|
136
|
+
/** setUserAgent sets the user agent of a partition ("" restores the default). */
|
|
137
|
+
declare function remoteSetUserAgent(partition: string, userAgent: string): Promise<void>;
|
|
138
|
+
/** setProxy sets the proxy of a partition. */
|
|
139
|
+
declare function remoteSetProxy(partition: string, proxy: RemoteProxy): Promise<void>;
|
|
140
|
+
/** setClientCertificate makes a partition present a client certificate (PEM files) to a host. */
|
|
141
|
+
declare function remoteSetClientCertificate(partition: string, host: string, certFile: string, keyFile: string): Promise<void>;
|
|
142
|
+
/** clearData removes stored data of a partition; no option set means everything. */
|
|
143
|
+
declare function remoteClearData(partition: string, options?: RemoteClearOptions): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* onCertificateError decides certificates the engine refused. While a handler is subscribed fn is
|
|
146
|
+
* asked for each error and returns true to accept the certificate for that host in that partition;
|
|
147
|
+
* without a handler every error is final. Answer within a minute or the certificate is refused.
|
|
148
|
+
*/
|
|
149
|
+
declare function remoteOnCertificateError(fn: (e: RemoteCertificateError) => boolean | Promise<boolean>, opts?: SubscribeOptions): () => void;
|
|
150
|
+
/**
|
|
151
|
+
* onAuth answers HTTP authentication challenges. Return the credentials, or null to cancel. Without a
|
|
152
|
+
* handler challenges are cancelled. Answer within a minute.
|
|
153
|
+
*/
|
|
154
|
+
declare function remoteOnAuth(fn: (c: RemoteAuthChallenge) => RemoteCredentials | null | Promise<RemoteCredentials | null>, opts?: SubscribeOptions): () => void;
|
|
155
|
+
export { remoteOpenWindow as openWindow, remoteAddView as addView, remoteNavigate as navigate, remotePost as post, remoteOnMessage as onMessage, remoteOnEvent as onRemoteEvent, remoteCapabilities as capabilities, remoteSetRules as setRules, remoteOnRequest as onRequest, remoteSetUserAgent as setUserAgent, remoteSetProxy as setProxy, remoteSetClientCertificate as setClientCertificate, remoteClearData as clearData, remoteOnCertificateError as onCertificateError, remoteOnAuth as onAuth, };
|
|
156
|
+
//# sourceMappingURL=remote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote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AC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAUpI;AAED;;;GAGG;AACH,iBAAS,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,mBAAmB,KAAK,iBAAiB,GAAG,IAAI,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAUvJ;AAED,OAAO,EACL,gBAAgB,IAAI,UAAU,EAC9B,aAAa,IAAI,OAAO,EACxB,cAAc,IAAI,QAAQ,EAC1B,UAAU,IAAI,IAAI,EAClB,eAAe,IAAI,SAAS,EAC5B,aAAa,IAAI,aAAa,EAC9B,kBAAkB,IAAI,YAAY,EAClC,cAAc,IAAI,QAAQ,EAC1B,eAAe,IAAI,SAAS,EAC5B,kBAAkB,IAAI,YAAY,EAClC,cAAc,IAAI,QAAQ,EAC1B,0BAA0B,IAAI,oBAAoB,EAClD,eAAe,IAAI,SAAS,EAC5B,wBAAwB,IAAI,kBAAkB,EAC9C,YAAY,IAAI,MAAM,GACvB,CAAC"}
|
package/dist/remote.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Web pages from the internet in views and windows of the app, with no access
|
|
2
|
+
// to the app. Needs the "remote" permission; request rules and the request
|
|
3
|
+
// stream need "remote:intercept", and the user agent, proxy, certificate
|
|
4
|
+
// decisions, logins and stored data "remote:network".
|
|
5
|
+
//
|
|
6
|
+
// A remote view has its own storage partition, no bridge to the SDK and no way
|
|
7
|
+
// to fetch the app. It may navigate only to the origins you list (default: the
|
|
8
|
+
// origin it started on); the rest opens in the system browser or is dropped.
|
|
9
|
+
// You and the page talk through the message channel, which is off unless the
|
|
10
|
+
// view is created with `messages: true`: the page calls
|
|
11
|
+
// `krateRemote.postMessage(data)`, you call post(). See docs/native/remote.
|
|
12
|
+
import { call } from "./index.js";
|
|
13
|
+
import { subscribe } from "./events.js";
|
|
14
|
+
import { Window, View } from "./window.js";
|
|
15
|
+
function wireOptions(o) {
|
|
16
|
+
return {
|
|
17
|
+
url: o.url,
|
|
18
|
+
partition: o.partition ?? "",
|
|
19
|
+
allow: o.allow ?? [],
|
|
20
|
+
allowAnyHttps: o.allowAnyHttps ?? false,
|
|
21
|
+
blocked: o.blocked ?? "",
|
|
22
|
+
messages: o.messages ?? false,
|
|
23
|
+
userAgent: o.userAgent ?? "",
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** openWindow opens a window that shows a remote page. */
|
|
27
|
+
async function remoteOpenWindow(o) {
|
|
28
|
+
const id = await call("krate/remote.open", [
|
|
29
|
+
{ ...wireOptions(o), id: o.id ?? "", title: o.title ?? "", width: o.width ?? 0, height: o.height ?? 0, fixed: o.fixed ?? false },
|
|
30
|
+
]);
|
|
31
|
+
return new Window(id);
|
|
32
|
+
}
|
|
33
|
+
/** addView adds a remote view to a window (default: the main window). */
|
|
34
|
+
async function remoteAddView(o, window = "") {
|
|
35
|
+
const id = await call("krate/remote.addView", [
|
|
36
|
+
window,
|
|
37
|
+
{ ...wireOptions(o), id: o.id ?? "", beside: o.beside ?? "", side: o.side ?? "", size: o.size ?? 0, minWidth: o.minWidth ?? 0, minHeight: o.minHeight ?? 0 },
|
|
38
|
+
]);
|
|
39
|
+
return new View(id);
|
|
40
|
+
}
|
|
41
|
+
/** navigate loads a URL in a remote view; the view's allowlist applies. */
|
|
42
|
+
function remoteNavigate(view, url) {
|
|
43
|
+
return call("krate/remote.navigate", [view, url]);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* post sends a message to the page of a remote view created with `messages: true`. The page gets a
|
|
47
|
+
* "message" event whose origin is the app's. It is delivered only while the page is on `targetOrigin`
|
|
48
|
+
* ("*" skips the check).
|
|
49
|
+
*/
|
|
50
|
+
function remotePost(view, data, targetOrigin) {
|
|
51
|
+
return call("krate/remote.post", [view, targetOrigin, data]);
|
|
52
|
+
}
|
|
53
|
+
/** onMessage calls fn for messages remote pages post with krateRemote.postMessage. */
|
|
54
|
+
function remoteOnMessage(fn, opts) {
|
|
55
|
+
return subscribe("krate/remote.messages", fn, opts);
|
|
56
|
+
}
|
|
57
|
+
/** onEvent calls fn when a remote page loaded or a navigation was refused. */
|
|
58
|
+
function remoteOnEvent(fn, opts) {
|
|
59
|
+
return subscribe("krate/remote.events", fn, opts);
|
|
60
|
+
}
|
|
61
|
+
/** capabilities says what this platform can do for remote content. */
|
|
62
|
+
function remoteCapabilities() {
|
|
63
|
+
return call("krate/remote.capabilities");
|
|
64
|
+
}
|
|
65
|
+
/** setRules replaces the request rules of a partition (see RemoteRule and capabilities()). */
|
|
66
|
+
function remoteSetRules(partition, rules) {
|
|
67
|
+
return call("krate/remote.setRules", [
|
|
68
|
+
partition,
|
|
69
|
+
rules.map((r) => ({ urls: r.urls, action: r.action, redirect: r.redirect ?? "", headers: r.headers ?? {} })),
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
/** onRequest calls fn for the requests of remote views, with what the rules did. */
|
|
73
|
+
function remoteOnRequest(fn, opts) {
|
|
74
|
+
return subscribe("krate/remote.requests", fn, opts);
|
|
75
|
+
}
|
|
76
|
+
/** setUserAgent sets the user agent of a partition ("" restores the default). */
|
|
77
|
+
function remoteSetUserAgent(partition, userAgent) {
|
|
78
|
+
return call("krate/remote.setUserAgent", [partition, userAgent]);
|
|
79
|
+
}
|
|
80
|
+
/** setProxy sets the proxy of a partition. */
|
|
81
|
+
function remoteSetProxy(partition, proxy) {
|
|
82
|
+
return call("krate/remote.setProxy", [partition, { mode: proxy.mode, url: proxy.url ?? "", bypass: proxy.bypass ?? [] }]);
|
|
83
|
+
}
|
|
84
|
+
/** setClientCertificate makes a partition present a client certificate (PEM files) to a host. */
|
|
85
|
+
function remoteSetClientCertificate(partition, host, certFile, keyFile) {
|
|
86
|
+
return call("krate/remote.setClientCertificate", [partition, host, certFile, keyFile]);
|
|
87
|
+
}
|
|
88
|
+
/** clearData removes stored data of a partition; no option set means everything. */
|
|
89
|
+
function remoteClearData(partition, options = {}) {
|
|
90
|
+
return call("krate/remote.clearData", [partition, { cookies: options.cookies ?? false, cache: options.cache ?? false, storage: options.storage ?? false }]);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* onCertificateError decides certificates the engine refused. While a handler is subscribed fn is
|
|
94
|
+
* asked for each error and returns true to accept the certificate for that host in that partition;
|
|
95
|
+
* without a handler every error is final. Answer within a minute or the certificate is refused.
|
|
96
|
+
*/
|
|
97
|
+
function remoteOnCertificateError(fn, opts) {
|
|
98
|
+
return subscribe("krate/remote.certificates", (e) => {
|
|
99
|
+
void Promise.resolve(fn(e))
|
|
100
|
+
.catch(() => false)
|
|
101
|
+
.then((allow) => call("krate/remote.answerCertificate", [e.id, allow === true]).catch(() => { }));
|
|
102
|
+
}, opts);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* onAuth answers HTTP authentication challenges. Return the credentials, or null to cancel. Without a
|
|
106
|
+
* handler challenges are cancelled. Answer within a minute.
|
|
107
|
+
*/
|
|
108
|
+
function remoteOnAuth(fn, opts) {
|
|
109
|
+
return subscribe("krate/remote.auth", (c) => {
|
|
110
|
+
void Promise.resolve(fn(c))
|
|
111
|
+
.catch(() => null)
|
|
112
|
+
.then((cr) => call("krate/remote.answerAuth", [c.id, cr?.user ?? "", cr?.password ?? "", cr != null]).catch(() => { }));
|
|
113
|
+
}, opts);
|
|
114
|
+
}
|
|
115
|
+
export { remoteOpenWindow as openWindow, remoteAddView as addView, remoteNavigate as navigate, remotePost as post, remoteOnMessage as onMessage, remoteOnEvent as onRemoteEvent, remoteCapabilities as capabilities, remoteSetRules as setRules, remoteOnRequest as onRequest, remoteSetUserAgent as setUserAgent, remoteSetProxy as setProxy, remoteSetClientCertificate as setClientCertificate, remoteClearData as clearData, remoteOnCertificateError as onCertificateError, remoteOnAuth as onAuth, };
|