photon-engine-electron 0.1.0

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.
@@ -0,0 +1,17 @@
1
+ import { IFileSystem } from "photon-engine";
2
+ export declare class ElectronFileSystem implements IFileSystem {
3
+ private nodeFs;
4
+ private nodePath;
5
+ private getFs;
6
+ readText(path: string): Promise<string>;
7
+ writeText(path: string, content: string): Promise<void>;
8
+ readBinary(path: string): Promise<Uint8Array>;
9
+ writeBinary(path: string, data: Uint8Array): Promise<void>;
10
+ exists(path: string): Promise<boolean>;
11
+ mkdir(path: string): Promise<void>;
12
+ remove(path: string): Promise<void>;
13
+ listDir(path: string): Promise<string[]>;
14
+ isFile(path: string): Promise<boolean>;
15
+ isDir(path: string): Promise<boolean>;
16
+ }
17
+ //# sourceMappingURL=ElectronFileSystem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ElectronFileSystem.d.ts","sourceRoot":"","sources":["../src/ElectronFileSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,kBAAmB,YAAW,WAAW;IACpD,OAAO,CAAC,MAAM,CAAoC;IAClD,OAAO,CAAC,QAAQ,CAAsC;YAExC,KAAK;IAOb,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKvC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKvD,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAM7C,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAK1D,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKtC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKnC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAMxC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAMtC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAK5C"}
@@ -0,0 +1,62 @@
1
+ export class ElectronFileSystem {
2
+ nodeFs = null;
3
+ nodePath = null;
4
+ async getFs() {
5
+ if (this.nodeFs && this.nodePath)
6
+ return { fs: this.nodeFs, path: this.nodePath };
7
+ this.nodeFs = await import("fs");
8
+ this.nodePath = await import("path");
9
+ return { fs: this.nodeFs, path: this.nodePath };
10
+ }
11
+ async readText(path) {
12
+ const { fs } = await this.getFs();
13
+ return fs.promises.readFile(path, "utf-8");
14
+ }
15
+ async writeText(path, content) {
16
+ const { fs } = await this.getFs();
17
+ await fs.promises.writeFile(path, content, "utf-8");
18
+ }
19
+ async readBinary(path) {
20
+ const { fs } = await this.getFs();
21
+ const buf = await fs.promises.readFile(path);
22
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
23
+ }
24
+ async writeBinary(path, data) {
25
+ const { fs } = await this.getFs();
26
+ await fs.promises.writeFile(path, data);
27
+ }
28
+ async exists(path) {
29
+ const { fs } = await this.getFs();
30
+ try {
31
+ await fs.promises.access(path);
32
+ return true;
33
+ }
34
+ catch {
35
+ return false;
36
+ }
37
+ }
38
+ async mkdir(path) {
39
+ const { fs } = await this.getFs();
40
+ await fs.promises.mkdir(path, { recursive: true });
41
+ }
42
+ async remove(path) {
43
+ const { fs } = await this.getFs();
44
+ await fs.promises.rm(path, { recursive: true, force: true });
45
+ }
46
+ async listDir(path) {
47
+ const { fs } = await this.getFs();
48
+ const entries = await fs.promises.readdir(path, { withFileTypes: true });
49
+ return entries.map((e) => e.name);
50
+ }
51
+ async isFile(path) {
52
+ const { fs } = await this.getFs();
53
+ const stat = await fs.promises.stat(path);
54
+ return stat.isFile();
55
+ }
56
+ async isDir(path) {
57
+ const { fs } = await this.getFs();
58
+ const stat = await fs.promises.stat(path);
59
+ return stat.isDirectory();
60
+ }
61
+ }
62
+ //# sourceMappingURL=ElectronFileSystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ElectronFileSystem.js","sourceRoot":"","sources":["../src/ElectronFileSystem.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,kBAAkB;IACrB,MAAM,GAA+B,IAAI,CAAC;IAC1C,QAAQ,GAAiC,IAAI,CAAC;IAE9C,KAAK,CAAC,KAAK;QACjB,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClF,IAAI,CAAC,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;QACrC,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,MAAO,EAAE,IAAI,EAAE,IAAI,CAAC,QAAS,EAAE,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAY;QACzB,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QAClC,OAAO,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAAY,EAAE,OAAe;QAC3C,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QAClC,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE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AAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAY;QACxB,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QACzE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAY;QACvB,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QAClC,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAY;QACtB,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QAClC,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ import { INativeBridge } from "photon-engine";
2
+ import { ElectronFileSystem } from "./ElectronFileSystem";
3
+ export declare class ElectronNativeBridge implements INativeBridge {
4
+ readonly fs: ElectronFileSystem;
5
+ constructor();
6
+ invoke(channel: string, args?: Record<string, unknown>): Promise<unknown>;
7
+ }
8
+ //# sourceMappingURL=ElectronNativeBridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ElectronNativeBridge.d.ts","sourceRoot":"","sources":["../src/ElectronNativeBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,qBAAa,oBAAqB,YAAW,aAAa;IACxD,QAAQ,CAAC,EAAE,EAAE,kBAAkB,CAAC;;IAM1B,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;CAIhF"}
@@ -0,0 +1,12 @@
1
+ import { ElectronFileSystem } from "./ElectronFileSystem";
2
+ export class ElectronNativeBridge {
3
+ fs;
4
+ constructor() {
5
+ this.fs = new ElectronFileSystem();
6
+ }
7
+ async invoke(channel, args) {
8
+ const { ipcRenderer } = await import("electron");
9
+ return ipcRenderer.invoke(channel, args);
10
+ }
11
+ }
12
+ //# sourceMappingURL=ElectronNativeBridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ElectronNativeBridge.js","sourceRoot":"","sources":["../src/ElectronNativeBridge.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,OAAO,oBAAoB;IACtB,EAAE,CAAqB;IAEhC;QACE,IAAI,CAAC,EAAE,GAAG,IAAI,kBAAkB,EAAE,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,IAA8B;QAC1D,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;QACjD,OAAO,WAAW,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export { ElectronFileSystem } from "./ElectronFileSystem";
2
+ export { ElectronNativeBridge } from "./ElectronNativeBridge";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { ElectronFileSystem } from "./ElectronFileSystem";
2
+ export { ElectronNativeBridge } from "./ElectronNativeBridge";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "photon-engine-electron",
3
+ "version": "0.1.0",
4
+ "description": "Electron adapter for Photon Engine",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "dev": "tsc --watch",
20
+ "typecheck": "tsc --noEmit",
21
+ "prepublishOnly": "npm run build"
22
+ },
23
+ "peerDependencies": {
24
+ "electron": "^28.0.0",
25
+ "photon-engine": "^0.1.0"
26
+ },
27
+ "devDependencies": {
28
+ "photon-engine": "file:../core",
29
+ "typescript": "^5.6.0"
30
+ },
31
+ "license": "MIT"
32
+ }