Skip to content

Commit adcde52

Browse files
committed
feat(web): add Project.checkCompatibility API
1 parent 569bc53 commit adcde52

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/utoo-web/src/project/Project.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
ServiceWorkerOptions,
1717
Stats,
1818
} from "../types";
19+
import { checkCompatibility } from "./checkCompatibility";
1920
import { ForkedProject } from "./ForkedProject";
2021

2122
let ProjectWorker: Worker;
@@ -251,4 +252,8 @@ export class Project implements ProjectEndpoint {
251252

252253
return new ForkedProject(channel.port1);
253254
}
255+
256+
public static checkCompatibility() {
257+
return checkCompatibility();
258+
}
254259
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
export function checkCompatibility(): {
2+
compatible: boolean;
3+
minimalVersion: { chrome: number };
4+
details: {
5+
sharedArrayBuffer: boolean;
6+
atomics: boolean;
7+
worker: boolean;
8+
serviceWorker: boolean;
9+
opfs: boolean;
10+
fileSystemObserver: boolean;
11+
};
12+
missing: string[];
13+
} {
14+
const details = {
15+
sharedArrayBuffer:
16+
typeof SharedArrayBuffer !== "undefined" && crossOriginIsolated,
17+
atomics: typeof Atomics !== "undefined",
18+
worker: typeof Worker !== "undefined",
19+
serviceWorker: "serviceWorker" in navigator,
20+
opfs: "storage" in navigator && "getDirectory" in navigator.storage,
21+
fileSystemObserver: "FileSystemObserver" in window,
22+
};
23+
24+
const missing: string[] = [];
25+
26+
if (!details.sharedArrayBuffer) missing.push("SharedArrayBuffer (COOP/COEP)");
27+
if (!details.atomics) missing.push("Atomics");
28+
if (!details.worker) missing.push("Worker");
29+
if (!details.serviceWorker) missing.push("ServiceWorker");
30+
if (!details.opfs) missing.push("OPFS");
31+
if (!details.fileSystemObserver) missing.push("FileSystemObserver");
32+
33+
const compatible = missing.length === 0;
34+
const minimalVersion = { chrome: 137 };
35+
36+
return {
37+
compatible,
38+
minimalVersion,
39+
details,
40+
missing,
41+
};
42+
}

0 commit comments

Comments
 (0)