@basthon/kernel-base 0.78.4 → 0.78.6
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/lib/kernel.d.ts +5 -0
- package/lib/kernel.js +7 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/worker/kernel-main.js +30 -26
- package/lib/worker/kernel-worker.d.ts +1 -0
- package/lib/worker/kernel-worker.js +2 -1
- package/package.json +1 -1
package/lib/kernel.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class KernelBase {
|
|
|
14
14
|
protected _pendingInput?: PromiseDelegate<string>;
|
|
15
15
|
private _listeners;
|
|
16
16
|
protected _options: any;
|
|
17
|
+
protected _runningData: any;
|
|
17
18
|
protected _files: Map<string, ArrayBuffer>;
|
|
18
19
|
protected _modules: Map<string, ArrayBuffer>;
|
|
19
20
|
constructor(options: any);
|
|
@@ -109,6 +110,10 @@ export declare class KernelBase {
|
|
|
109
110
|
* inside the version number directory inside the assets directory.
|
|
110
111
|
*/
|
|
111
112
|
basthonRoot(absolute?: boolean): string;
|
|
113
|
+
/**
|
|
114
|
+
* Set running data (introduced to manage user_seed in capytale).
|
|
115
|
+
*/
|
|
116
|
+
setRunningData(data: any): Promise<void>;
|
|
112
117
|
/**
|
|
113
118
|
* Downloading data (bytes array or data URL) as filename
|
|
114
119
|
* (opening browser dialog).
|
package/lib/kernel.js
CHANGED
|
@@ -24,6 +24,7 @@ export class KernelBase {
|
|
|
24
24
|
this._pendingInput = undefined;
|
|
25
25
|
// a map to register wrapped listeners to allow later remove
|
|
26
26
|
this._listeners = new Map();
|
|
27
|
+
this._runningData = {};
|
|
27
28
|
this._files = new Map();
|
|
28
29
|
this._modules = new Map();
|
|
29
30
|
this._options = this.clone(options);
|
|
@@ -206,6 +207,12 @@ export class KernelBase {
|
|
|
206
207
|
basthonRoot(absolute = false) {
|
|
207
208
|
return (this.assetsURL(absolute) + "/" + this.version() + "/" + this.language());
|
|
208
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Set running data (introduced to manage user_seed in capytale).
|
|
212
|
+
*/
|
|
213
|
+
async setRunningData(data) {
|
|
214
|
+
this._runningData = { ...this._runningData, ...data };
|
|
215
|
+
}
|
|
209
216
|
/**
|
|
210
217
|
* Downloading data (bytes array or data URL) as filename
|
|
211
218
|
* (opening browser dialog).
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.78.
|
|
1
|
+
export declare const VERSION = "0.78.6";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.78.
|
|
1
|
+
export const VERSION = "0.78.6";
|
|
@@ -98,35 +98,38 @@ export class KernelMainBase extends KernelBase {
|
|
|
98
98
|
*/
|
|
99
99
|
async _start() {
|
|
100
100
|
await super._start();
|
|
101
|
-
// kernel restart in legacy mode is lazy, not a full restart
|
|
102
101
|
if (this.isLegacy() && this.remote != null) {
|
|
102
|
+
// kernel restart in legacy mode is lazy, not a full restart
|
|
103
103
|
await this.remote?.legacyStart();
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
// setup the proxy worker
|
|
107
|
-
const proxyWorker = new Worker(new URL("./comlink-proxy.js", import.meta.url));
|
|
108
|
-
const proxy = wrap(proxyWorker);
|
|
109
|
-
// setup the kernel worker
|
|
110
|
-
await this.setupWorker();
|
|
111
|
-
// always set... but not always useful
|
|
112
|
-
await this.remote?.setEphemeralAPI(this._ephemeralAPI);
|
|
113
|
-
if (this.syncCommSupport()) {
|
|
114
|
-
console.log("Using SharedArrayBuffer for synchronous worker communication.");
|
|
115
|
-
await this._remote?.setSAB(this._sab);
|
|
116
104
|
}
|
|
117
|
-
else
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
105
|
+
else {
|
|
106
|
+
// setup the proxy worker
|
|
107
|
+
const proxyWorker = new Worker(new URL("./comlink-proxy.js", import.meta.url));
|
|
108
|
+
const proxy = wrap(proxyWorker);
|
|
109
|
+
// setup the kernel worker
|
|
110
|
+
await this.setupWorker();
|
|
111
|
+
// always set... but not always useful
|
|
112
|
+
await this.remote?.setEphemeralAPI(this._ephemeralAPI);
|
|
113
|
+
if (this.syncCommSupport()) {
|
|
114
|
+
console.log("Using SharedArrayBuffer for synchronous worker communication.");
|
|
115
|
+
await this._remote?.setSAB(this._sab);
|
|
116
|
+
}
|
|
117
|
+
else if (this._fallbackKey != null) {
|
|
118
|
+
console.warn("SharedArrayBuffer not available, falling back to " +
|
|
119
|
+
"using third-party server for synchronous worker communication.");
|
|
120
|
+
const pass = globalThis.crypto.randomUUID();
|
|
121
|
+
await this.remote?.setFallbackKeyAndPass(this._fallbackKey, pass);
|
|
122
|
+
const AES = await import("crypto-js/aes");
|
|
123
|
+
this._encrypt = (message) => AES.encrypt(message, pass).toString();
|
|
124
|
+
}
|
|
125
|
+
// bind ports
|
|
126
|
+
const port = await proxy[createEndpoint]();
|
|
127
|
+
await this.remote?.setProxyPort(transfer(port, [port]));
|
|
128
|
+
// init remote
|
|
129
|
+
await this.remote?.init();
|
|
124
130
|
}
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
await this.remote?.setProxyPort(transfer(port, [port]));
|
|
128
|
-
// init remote
|
|
129
|
-
await this.remote?.init();
|
|
131
|
+
// restore running data (if any) in the kernel worker
|
|
132
|
+
await this.setRunningData(this._runningData);
|
|
130
133
|
}
|
|
131
134
|
/**
|
|
132
135
|
* Comlink remote getter.
|
|
@@ -152,7 +155,8 @@ export class KernelMainBase extends KernelBase {
|
|
|
152
155
|
* Set running data in the kernel worker (introduced to manage user_seed in capytale).
|
|
153
156
|
*/
|
|
154
157
|
async setRunningData(data) {
|
|
155
|
-
|
|
158
|
+
await super.setRunningData(data);
|
|
159
|
+
await this.remote?.setRunningData(this._runningData);
|
|
156
160
|
}
|
|
157
161
|
/**
|
|
158
162
|
* Convert a canvas array buffer to a PNG data URL (base64 encoded).
|
|
@@ -74,6 +74,7 @@ declare class KernelWorkerBase {
|
|
|
74
74
|
setEphemeralAPI(url: string): Promise<void>;
|
|
75
75
|
/**
|
|
76
76
|
* Set running data (introduced to manage user_seed in capytale).
|
|
77
|
+
* It is not updated but replaced with the new data.
|
|
77
78
|
*/
|
|
78
79
|
setRunningData(data: any): Promise<void>;
|
|
79
80
|
/**
|
|
@@ -118,9 +118,10 @@ class KernelWorkerBase {
|
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
120
|
* Set running data (introduced to manage user_seed in capytale).
|
|
121
|
+
* It is not updated but replaced with the new data.
|
|
121
122
|
*/
|
|
122
123
|
async setRunningData(data) {
|
|
123
|
-
this._runningData =
|
|
124
|
+
this._runningData = data;
|
|
124
125
|
}
|
|
125
126
|
/**
|
|
126
127
|
* Get running data.
|