ogi-addon 3.0.0 → 4.0.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,80 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_chunk = require('./chunk-C0xms8kb.cjs');
3
+ let child_process = require("child_process");
4
+
5
+ //#region src/extraction.ts
6
+ const s7ZipPath = "C:\\Program Files\\7-Zip\\7z.exe";
7
+ function waitForChildProcess(childProcess, errorMessage) {
8
+ return new Promise((resolve, reject) => {
9
+ childProcess.once("error", reject);
10
+ childProcess.once("close", (code) => {
11
+ if (code !== 0) {
12
+ reject(new Error(errorMessage));
13
+ return;
14
+ }
15
+ resolve();
16
+ });
17
+ });
18
+ }
19
+ async function detectUnrarType() {
20
+ const childProcess = (0, child_process.spawn)("unrar");
21
+ return await new Promise((resolve, reject) => {
22
+ let output = "";
23
+ const collectOutput = (data) => {
24
+ output += data.toString();
25
+ };
26
+ childProcess.stdout.on("data", collectOutput);
27
+ childProcess.stderr.on("data", collectOutput);
28
+ childProcess.once("error", reject);
29
+ childProcess.once("close", () => {
30
+ if (output.includes("unrar-free")) {
31
+ resolve("unrar-free");
32
+ return;
33
+ }
34
+ if (output.includes("unrar-nonfree")) {
35
+ resolve("unrar-nonfree");
36
+ return;
37
+ }
38
+ resolve("unknown");
39
+ });
40
+ });
41
+ }
42
+ async function extraction(filePath, outputDir) {
43
+ const lowerCaseFilePath = filePath.toLowerCase();
44
+ if (process.platform === "win32") return await waitForChildProcess((0, child_process.spawn)(s7ZipPath, [
45
+ "x",
46
+ filePath,
47
+ "-o",
48
+ outputDir
49
+ ]), "Failed to extract file");
50
+ else if (process.platform === "linux" || process.platform === "darwin") {
51
+ if (lowerCaseFilePath.endsWith(".zip")) return await waitForChildProcess((0, child_process.spawn)("unzip", [
52
+ "-o",
53
+ filePath,
54
+ "-d",
55
+ outputDir
56
+ ]), "Failed to unzip file");
57
+ else if (lowerCaseFilePath.endsWith(".rar")) {
58
+ const unrarType = await detectUnrarType();
59
+ if (unrarType === "unrar-free") return await waitForChildProcess((0, child_process.spawn)("unrar", [
60
+ "-f",
61
+ "-x",
62
+ filePath,
63
+ outputDir
64
+ ]), "Failed to unrar file");
65
+ else if (unrarType === "unrar-nonfree") return await waitForChildProcess((0, child_process.spawn)("unrar", [
66
+ "-o",
67
+ filePath,
68
+ "-d",
69
+ outputDir
70
+ ]), "Failed to unrar file");
71
+ else throw new Error("Unknown unrar type");
72
+ }
73
+ throw new Error(`Unsupported archive type: ${filePath}`);
74
+ }
75
+ throw new Error(`Unsupported platform: ${process.platform}`);
76
+ }
77
+
78
+ //#endregion
79
+ exports.extraction = extraction;
80
+ //# sourceMappingURL=extraction.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extraction.cjs","names":[],"sources":["../src/extraction.ts"],"sourcesContent":["import { spawn } from 'child_process';\n\nconst s7ZipPath = 'C:\\\\Program Files\\\\7-Zip\\\\7z.exe';\n\nfunction waitForChildProcess(\n childProcess: ReturnType<typeof spawn>,\n errorMessage: string\n): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n childProcess.once('error', reject);\n childProcess.once('close', (code) => {\n if (code !== 0) {\n reject(new Error(errorMessage));\n return;\n }\n\n resolve();\n });\n });\n}\n\nasync function detectUnrarType(): Promise<\n 'unrar-free' | 'unrar-nonfree' | 'unknown'\n> {\n const childProcess = spawn('unrar');\n\n return await new Promise((resolve, reject) => {\n let output = '';\n\n const collectOutput = (data: Buffer) => {\n output += data.toString();\n };\n\n childProcess.stdout.on('data', collectOutput);\n childProcess.stderr.on('data', collectOutput);\n childProcess.once('error', reject);\n childProcess.once('close', () => {\n if (output.includes('unrar-free')) {\n resolve('unrar-free');\n return;\n }\n\n if (output.includes('unrar-nonfree')) {\n resolve('unrar-nonfree');\n return;\n }\n\n resolve('unknown');\n });\n });\n}\n\nexport async function extraction(filePath: string, outputDir: string) {\n const lowerCaseFilePath = filePath.toLowerCase();\n\n if (process.platform === 'win32') {\n // expect 7zip to be installed, and use 7zip to unrar\n const childProcess = spawn(s7ZipPath, ['x', filePath, '-o', outputDir]);\n return await waitForChildProcess(childProcess, 'Failed to extract file');\n } else if (process.platform === 'linux' || process.platform === 'darwin') {\n if (lowerCaseFilePath.endsWith('.zip')) {\n // expect unzip to be installed, and use unzip to unzip\n const childProcess = spawn('unzip', ['-o', filePath, '-d', outputDir]);\n return await waitForChildProcess(childProcess, 'Failed to unzip file');\n } else if (lowerCaseFilePath.endsWith('.rar')) {\n // check if unrar-nonfree is installed or unrar is installed\n const unrarType = await detectUnrarType();\n\n // now use the according unrar version to unrar\n if (unrarType === 'unrar-free') {\n // use unrar-free to unrar\n const childProcess = spawn('unrar', ['-f', '-x', filePath, outputDir]);\n return await waitForChildProcess(childProcess, 'Failed to unrar file');\n } else if (unrarType === 'unrar-nonfree') {\n // use unrar-nonfree to unrar\n const childProcess = spawn('unrar', ['-o', filePath, '-d', outputDir]);\n return await waitForChildProcess(childProcess, 'Failed to unrar file');\n } else {\n throw new Error('Unknown unrar type');\n }\n }\n\n throw new Error(`Unsupported archive type: ${filePath}`);\n }\n\n throw new Error(`Unsupported platform: ${process.platform}`);\n}\n"],"mappings":";;;;;AAEA,MAAM,YAAY;AAElB,SAAS,oBACP,cACA,cACe;AACf,QAAO,IAAI,SAAe,SAAS,WAAW;AAC5C,eAAa,KAAK,SAAS,OAAO;AAClC,eAAa,KAAK,UAAU,SAAS;AACnC,OAAI,SAAS,GAAG;AACd,WAAO,IAAI,MAAM,aAAa,CAAC;AAC/B;;AAGF,YAAS;IACT;GACF;;AAGJ,eAAe,kBAEb;CACA,MAAM,wCAAqB,QAAQ;AAEnC,QAAO,MAAM,IAAI,SAAS,SAAS,WAAW;EAC5C,IAAI,SAAS;EAEb,MAAM,iBAAiB,SAAiB;AACtC,aAAU,KAAK,UAAU;;AAG3B,eAAa,OAAO,GAAG,QAAQ,cAAc;AAC7C,eAAa,OAAO,GAAG,QAAQ,cAAc;AAC7C,eAAa,KAAK,SAAS,OAAO;AAClC,eAAa,KAAK,eAAe;AAC/B,OAAI,OAAO,SAAS,aAAa,EAAE;AACjC,YAAQ,aAAa;AACrB;;AAGF,OAAI,OAAO,SAAS,gBAAgB,EAAE;AACpC,YAAQ,gBAAgB;AACxB;;AAGF,WAAQ,UAAU;IAClB;GACF;;AAGJ,eAAsB,WAAW,UAAkB,WAAmB;CACpE,MAAM,oBAAoB,SAAS,aAAa;AAEhD,KAAI,QAAQ,aAAa,QAGvB,QAAO,MAAM,6CADc,WAAW;EAAC;EAAK;EAAU;EAAM;EAAU,CAAC,EACxB,yBAAyB;UAC/D,QAAQ,aAAa,WAAW,QAAQ,aAAa,UAAU;AACxE,MAAI,kBAAkB,SAAS,OAAO,CAGpC,QAAO,MAAM,6CADc,SAAS;GAAC;GAAM;GAAU;GAAM;GAAU,CAAC,EACvB,uBAAuB;WAC7D,kBAAkB,SAAS,OAAO,EAAE;GAE7C,MAAM,YAAY,MAAM,iBAAiB;AAGzC,OAAI,cAAc,aAGhB,QAAO,MAAM,6CADc,SAAS;IAAC;IAAM;IAAM;IAAU;IAAU,CAAC,EACvB,uBAAuB;YAC7D,cAAc,gBAGvB,QAAO,MAAM,6CADc,SAAS;IAAC;IAAM;IAAU;IAAM;IAAU,CAAC,EACvB,uBAAuB;OAEtE,OAAM,IAAI,MAAM,qBAAqB;;AAIzC,QAAM,IAAI,MAAM,6BAA6B,WAAW;;AAG1D,OAAM,IAAI,MAAM,yBAAyB,QAAQ,WAAW"}
@@ -0,0 +1,5 @@
1
+ //#region src/extraction.d.ts
2
+ declare function extraction(filePath: string, outputDir: string): Promise<void>;
3
+ //#endregion
4
+ export { extraction };
5
+ //# sourceMappingURL=extraction.d.cts.map
@@ -0,0 +1,5 @@
1
+ //#region src/extraction.d.ts
2
+ declare function extraction(filePath: string, outputDir: string): Promise<void>;
3
+ //#endregion
4
+ export { extraction };
5
+ //# sourceMappingURL=extraction.d.mts.map
@@ -0,0 +1,78 @@
1
+ import { spawn } from "child_process";
2
+
3
+ //#region src/extraction.ts
4
+ const s7ZipPath = "C:\\Program Files\\7-Zip\\7z.exe";
5
+ function waitForChildProcess(childProcess, errorMessage) {
6
+ return new Promise((resolve, reject) => {
7
+ childProcess.once("error", reject);
8
+ childProcess.once("close", (code) => {
9
+ if (code !== 0) {
10
+ reject(new Error(errorMessage));
11
+ return;
12
+ }
13
+ resolve();
14
+ });
15
+ });
16
+ }
17
+ async function detectUnrarType() {
18
+ const childProcess = spawn("unrar");
19
+ return await new Promise((resolve, reject) => {
20
+ let output = "";
21
+ const collectOutput = (data) => {
22
+ output += data.toString();
23
+ };
24
+ childProcess.stdout.on("data", collectOutput);
25
+ childProcess.stderr.on("data", collectOutput);
26
+ childProcess.once("error", reject);
27
+ childProcess.once("close", () => {
28
+ if (output.includes("unrar-free")) {
29
+ resolve("unrar-free");
30
+ return;
31
+ }
32
+ if (output.includes("unrar-nonfree")) {
33
+ resolve("unrar-nonfree");
34
+ return;
35
+ }
36
+ resolve("unknown");
37
+ });
38
+ });
39
+ }
40
+ async function extraction(filePath, outputDir) {
41
+ const lowerCaseFilePath = filePath.toLowerCase();
42
+ if (process.platform === "win32") return await waitForChildProcess(spawn(s7ZipPath, [
43
+ "x",
44
+ filePath,
45
+ "-o",
46
+ outputDir
47
+ ]), "Failed to extract file");
48
+ else if (process.platform === "linux" || process.platform === "darwin") {
49
+ if (lowerCaseFilePath.endsWith(".zip")) return await waitForChildProcess(spawn("unzip", [
50
+ "-o",
51
+ filePath,
52
+ "-d",
53
+ outputDir
54
+ ]), "Failed to unzip file");
55
+ else if (lowerCaseFilePath.endsWith(".rar")) {
56
+ const unrarType = await detectUnrarType();
57
+ if (unrarType === "unrar-free") return await waitForChildProcess(spawn("unrar", [
58
+ "-f",
59
+ "-x",
60
+ filePath,
61
+ outputDir
62
+ ]), "Failed to unrar file");
63
+ else if (unrarType === "unrar-nonfree") return await waitForChildProcess(spawn("unrar", [
64
+ "-o",
65
+ filePath,
66
+ "-d",
67
+ outputDir
68
+ ]), "Failed to unrar file");
69
+ else throw new Error("Unknown unrar type");
70
+ }
71
+ throw new Error(`Unsupported archive type: ${filePath}`);
72
+ }
73
+ throw new Error(`Unsupported platform: ${process.platform}`);
74
+ }
75
+
76
+ //#endregion
77
+ export { extraction };
78
+ //# sourceMappingURL=extraction.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extraction.mjs","names":[],"sources":["../src/extraction.ts"],"sourcesContent":["import { spawn } from 'child_process';\n\nconst s7ZipPath = 'C:\\\\Program Files\\\\7-Zip\\\\7z.exe';\n\nfunction waitForChildProcess(\n childProcess: ReturnType<typeof spawn>,\n errorMessage: string\n): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n childProcess.once('error', reject);\n childProcess.once('close', (code) => {\n if (code !== 0) {\n reject(new Error(errorMessage));\n return;\n }\n\n resolve();\n });\n });\n}\n\nasync function detectUnrarType(): Promise<\n 'unrar-free' | 'unrar-nonfree' | 'unknown'\n> {\n const childProcess = spawn('unrar');\n\n return await new Promise((resolve, reject) => {\n let output = '';\n\n const collectOutput = (data: Buffer) => {\n output += data.toString();\n };\n\n childProcess.stdout.on('data', collectOutput);\n childProcess.stderr.on('data', collectOutput);\n childProcess.once('error', reject);\n childProcess.once('close', () => {\n if (output.includes('unrar-free')) {\n resolve('unrar-free');\n return;\n }\n\n if (output.includes('unrar-nonfree')) {\n resolve('unrar-nonfree');\n return;\n }\n\n resolve('unknown');\n });\n });\n}\n\nexport async function extraction(filePath: string, outputDir: string) {\n const lowerCaseFilePath = filePath.toLowerCase();\n\n if (process.platform === 'win32') {\n // expect 7zip to be installed, and use 7zip to unrar\n const childProcess = spawn(s7ZipPath, ['x', filePath, '-o', outputDir]);\n return await waitForChildProcess(childProcess, 'Failed to extract file');\n } else if (process.platform === 'linux' || process.platform === 'darwin') {\n if (lowerCaseFilePath.endsWith('.zip')) {\n // expect unzip to be installed, and use unzip to unzip\n const childProcess = spawn('unzip', ['-o', filePath, '-d', outputDir]);\n return await waitForChildProcess(childProcess, 'Failed to unzip file');\n } else if (lowerCaseFilePath.endsWith('.rar')) {\n // check if unrar-nonfree is installed or unrar is installed\n const unrarType = await detectUnrarType();\n\n // now use the according unrar version to unrar\n if (unrarType === 'unrar-free') {\n // use unrar-free to unrar\n const childProcess = spawn('unrar', ['-f', '-x', filePath, outputDir]);\n return await waitForChildProcess(childProcess, 'Failed to unrar file');\n } else if (unrarType === 'unrar-nonfree') {\n // use unrar-nonfree to unrar\n const childProcess = spawn('unrar', ['-o', filePath, '-d', outputDir]);\n return await waitForChildProcess(childProcess, 'Failed to unrar file');\n } else {\n throw new Error('Unknown unrar type');\n }\n }\n\n throw new Error(`Unsupported archive type: ${filePath}`);\n }\n\n throw new Error(`Unsupported platform: ${process.platform}`);\n}\n"],"mappings":";;;AAEA,MAAM,YAAY;AAElB,SAAS,oBACP,cACA,cACe;AACf,QAAO,IAAI,SAAe,SAAS,WAAW;AAC5C,eAAa,KAAK,SAAS,OAAO;AAClC,eAAa,KAAK,UAAU,SAAS;AACnC,OAAI,SAAS,GAAG;AACd,WAAO,IAAI,MAAM,aAAa,CAAC;AAC/B;;AAGF,YAAS;IACT;GACF;;AAGJ,eAAe,kBAEb;CACA,MAAM,eAAe,MAAM,QAAQ;AAEnC,QAAO,MAAM,IAAI,SAAS,SAAS,WAAW;EAC5C,IAAI,SAAS;EAEb,MAAM,iBAAiB,SAAiB;AACtC,aAAU,KAAK,UAAU;;AAG3B,eAAa,OAAO,GAAG,QAAQ,cAAc;AAC7C,eAAa,OAAO,GAAG,QAAQ,cAAc;AAC7C,eAAa,KAAK,SAAS,OAAO;AAClC,eAAa,KAAK,eAAe;AAC/B,OAAI,OAAO,SAAS,aAAa,EAAE;AACjC,YAAQ,aAAa;AACrB;;AAGF,OAAI,OAAO,SAAS,gBAAgB,EAAE;AACpC,YAAQ,gBAAgB;AACxB;;AAGF,WAAQ,UAAU;IAClB;GACF;;AAGJ,eAAsB,WAAW,UAAkB,WAAmB;CACpE,MAAM,oBAAoB,SAAS,aAAa;AAEhD,KAAI,QAAQ,aAAa,QAGvB,QAAO,MAAM,oBADQ,MAAM,WAAW;EAAC;EAAK;EAAU;EAAM;EAAU,CAAC,EACxB,yBAAyB;UAC/D,QAAQ,aAAa,WAAW,QAAQ,aAAa,UAAU;AACxE,MAAI,kBAAkB,SAAS,OAAO,CAGpC,QAAO,MAAM,oBADQ,MAAM,SAAS;GAAC;GAAM;GAAU;GAAM;GAAU,CAAC,EACvB,uBAAuB;WAC7D,kBAAkB,SAAS,OAAO,EAAE;GAE7C,MAAM,YAAY,MAAM,iBAAiB;AAGzC,OAAI,cAAc,aAGhB,QAAO,MAAM,oBADQ,MAAM,SAAS;IAAC;IAAM;IAAM;IAAU;IAAU,CAAC,EACvB,uBAAuB;YAC7D,cAAc,gBAGvB,QAAO,MAAM,oBADQ,MAAM,SAAS;IAAC;IAAM;IAAU;IAAM;IAAU,CAAC,EACvB,uBAAuB;OAEtE,OAAM,IAAI,MAAM,qBAAqB;;AAIzC,QAAM,IAAI,MAAM,6BAA6B,WAAW;;AAG1D,OAAM,IAAI,MAAM,yBAAyB,QAAQ,WAAW"}
package/build/main.cjs CHANGED
@@ -1,21 +1,18 @@
1
1
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
2
  const require_chunk = require('./chunk-C0xms8kb.cjs');
3
3
  const require_EventResponse = require('./EventResponse.cjs');
4
+ const require_extraction = require('./extraction.cjs');
4
5
  const require_config_ConfigurationBuilder = require('./config/ConfigurationBuilder.cjs');
5
6
  const require_config_Configuration = require('./config/Configuration.cjs');
6
- let ws = require("ws");
7
- ws = require_chunk.__toESM(ws);
7
+ let _ogi_sdk_connect = require("@ogi-sdk/connect");
8
8
  let node_events = require("node:events");
9
9
  node_events = require_chunk.__toESM(node_events);
10
10
  let zod = require("zod");
11
11
  let fuse_js = require("fuse.js");
12
12
  fuse_js = require_chunk.__toESM(fuse_js);
13
- let node_child_process = require("node:child_process");
14
- let node_fs = require("node:fs");
15
- node_fs = require_chunk.__toESM(node_fs);
16
13
 
17
14
  //#region package.json
18
- var version = "3.0.0";
15
+ var version = "4.0.0";
19
16
 
20
17
  //#endregion
21
18
  //#region src/main.ts
@@ -50,8 +47,8 @@ var OGIAddon = class {
50
47
  }
51
48
  /**
52
49
  * Register an event listener for the addon. (See EventListenerTypes)
53
- * @param event {OGIAddonEvent}
54
- * @param listener {EventListenerTypes[OGIAddonEvent]}
50
+ * @param event {OGIAddonSDKEventListener}
51
+ * @param listener {EventListenerTypes[OGIAddonSDKEventListener]}
55
52
  */
56
53
  on(event, listener) {
57
54
  this.eventEmitter.on(event, listener);
@@ -83,18 +80,16 @@ var OGIAddon = class {
83
80
  * @returns {Promise<StoreData>}
84
81
  */
85
82
  async getAppDetails(appID, storefront) {
86
- const id = this.addonWSListener.send("get-app-details", {
83
+ return await this.addonWSListener.requestResponse("get-app-details", {
87
84
  appID,
88
85
  storefront
89
86
  });
90
- return await this.addonWSListener.waitForResponseFromServer(id);
91
87
  }
92
88
  async searchGame(query, storefront) {
93
- const id = this.addonWSListener.send("search-app-name", {
89
+ return await this.addonWSListener.requestResponse("search-app-name", {
94
90
  query,
95
91
  storefront
96
92
  });
97
- return await this.addonWSListener.waitForResponseFromServer(id);
98
93
  }
99
94
  /**
100
95
  * Notify the OGI Addon Server that you are performing a background task. This can be used to help users understand what is happening in the background.
@@ -152,83 +147,10 @@ var OGIAddon = class {
152
147
  * Extract a file using 7-Zip on Windows, unzip on Linux/Mac.
153
148
  * @param path {string}
154
149
  * @param outputPath {string}
155
- * @param type {'unrar' | 'unzip'}
156
150
  * @returns {Promise<void>}
157
151
  */
158
- async extractFile(path, outputPath, type) {
159
- return new Promise((resolve, reject) => {
160
- if (!node_fs.default.existsSync(outputPath)) node_fs.default.mkdirSync(outputPath, { recursive: true });
161
- if (type === "unzip") if (process.platform === "win32") (0, node_child_process.exec)(`"C:\\Program Files\\7-Zip\\7z.exe" x "${path}" -o"${outputPath}"`, (err, stdout, stderr) => {
162
- if (err) {
163
- console.error(err);
164
- console.log(stderr);
165
- reject(/* @__PURE__ */ new Error("Failed to extract ZIP file"));
166
- return;
167
- }
168
- console.log(stdout);
169
- console.log(stderr);
170
- resolve();
171
- });
172
- else {
173
- const unzipProcess = (0, node_child_process.spawn)("unzip", [
174
- "-o",
175
- path,
176
- "-d",
177
- outputPath
178
- ], { env: {
179
- ...process.env,
180
- UNZIP_DISABLE_ZIPBOMB_DETECTION: "TRUE"
181
- } });
182
- unzipProcess.stdout.on("data", (data) => {
183
- console.log(`[unzip stdout]: ${data}`);
184
- });
185
- unzipProcess.stderr.on("data", (data) => {
186
- console.error(`[unzip stderr]: ${data}`);
187
- });
188
- unzipProcess.on("close", (code) => {
189
- if (code !== 0) {
190
- console.error(`unzip process exited with code ${code}`);
191
- reject(/* @__PURE__ */ new Error("Failed to extract ZIP file"));
192
- return;
193
- }
194
- resolve();
195
- });
196
- }
197
- else if (type === "unrar") if (process.platform === "win32") (0, node_child_process.exec)(`"C:\\Program Files\\7-Zip\\7z.exe" x "${path}" -o"${outputPath}"`, (err, stdout, stderr) => {
198
- if (err) {
199
- console.error(err);
200
- console.log(stderr);
201
- reject(/* @__PURE__ */ new Error("Failed to extract RAR file"));
202
- return;
203
- }
204
- console.log(stdout);
205
- console.log(stderr);
206
- resolve();
207
- });
208
- else {
209
- const unrarProcess = (0, node_child_process.spawn)("unrar", [
210
- "x",
211
- "-y",
212
- path,
213
- outputPath
214
- ]);
215
- unrarProcess.stdout.on("data", (data) => {
216
- console.log(`[unrar stdout]: ${data}`);
217
- });
218
- unrarProcess.stderr.on("data", (data) => {
219
- console.error(`[unrar stderr]: ${data}`);
220
- });
221
- unrarProcess.on("close", (code) => {
222
- if (code !== 0) {
223
- console.error(`unrar process exited with code ${code}`);
224
- reject(/* @__PURE__ */ new Error("Failed to extract RAR file"));
225
- return;
226
- }
227
- resolve();
228
- });
229
- }
230
- else reject(/* @__PURE__ */ new Error("Unknown extraction type"));
231
- });
152
+ async extractFile(path, outputPath) {
153
+ return await require_extraction.extraction(path, outputPath);
232
154
  }
233
155
  };
234
156
  /**
@@ -385,81 +307,86 @@ const ZodLibraryInfo = zod.z.object({
385
307
  });
386
308
  var OGIAddonWSListener = class {
387
309
  socket;
310
+ transport;
388
311
  eventEmitter;
389
312
  addon;
390
313
  constructor(ogiAddon, eventEmitter) {
391
- if (process.argv[process.argv.length - 1].split("=")[0] !== "--addonSecret") throw new Error("No secret provided. This usually happens because the addon was not started by the OGI Addon Server.");
314
+ const secret = process.argv.find((arg) => arg.startsWith("--addonSecret="))?.split("=")[1];
315
+ if (!secret) throw new Error("No secret provided. This usually happens because the addon was not started by the OGI Addon Server.");
316
+ let port = process.argv.find((arg) => arg.startsWith("--addonPort="))?.split("=")[1];
317
+ if (!port) port = defaultPort.toString();
392
318
  this.addon = ogiAddon;
393
319
  this.eventEmitter = eventEmitter;
394
- this.socket = new ws.default("ws://localhost:" + defaultPort);
395
- this.socket.on("open", () => {
320
+ const WebSocketConstructor = globalThis.WebSocket;
321
+ if (!WebSocketConstructor) throw new Error("WebSocket is not available in this runtime");
322
+ this.socket = new WebSocketConstructor("ws://localhost:" + port);
323
+ this.transport = new _ogi_sdk_connect.EventResponseSocket(this.socket);
324
+ this.socket.addEventListener("open", () => {
396
325
  console.log("Connected to OGI Addon Server");
397
326
  console.log("OGI Addon Server Version:", VERSION);
398
327
  this.send("authenticate", {
399
328
  ...this.addon.addonInfo,
400
- secret: process.argv[process.argv.length - 1].split("=")[1],
329
+ secret,
401
330
  ogiVersion: VERSION
402
331
  });
403
332
  let configBuilder = new require_config_ConfigurationBuilder.ConfigurationBuilder();
404
333
  this.eventEmitter.emit("configure", configBuilder);
405
334
  this.send("configure", configBuilder.build(false));
406
335
  this.addon.config = new require_config_Configuration.Configuration(configBuilder.build(true));
407
- const configListener = (event) => {
408
- if (event === void 0) return;
409
- let data;
410
- if (typeof event === "string") data = event;
411
- else if (event instanceof Buffer) data = event.toString();
412
- else if (event && typeof event.data === "string") data = event.data;
413
- else if (event && event.data instanceof Buffer) data = event.data.toString();
414
- else data = event.toString();
415
- if (JSON.parse(data).event === "config-update") {
416
- console.log("Config update received");
417
- this.socket.off("message", configListener);
418
- this.eventEmitter.emit("connect", new require_EventResponse((screen, name, description) => {
419
- return this.userInputAsked(screen, name, description, this.socket);
420
- }));
421
- }
422
- };
423
- this.socket.on("message", configListener);
336
+ const unsubscribeConfigListener = this.transport.on("config-update", () => {
337
+ console.log("Config update received");
338
+ unsubscribeConfigListener();
339
+ this.eventEmitter.emit("connect", new require_EventResponse((screen, name, description) => {
340
+ return this.userInputAsked(screen, name, description);
341
+ }));
342
+ });
424
343
  });
425
- this.socket.on("error", (error) => {
426
- if (error.message.includes("Failed to connect")) throw new Error("OGI Addon Server is not running/is unreachable. Please start the server and try again.");
427
- console.error("An error occurred:", error);
344
+ this.socket.addEventListener("error", (event) => {
345
+ this.transport.rejectPendingResponses("Websocket error");
346
+ if ((event instanceof ErrorEvent ? event.message : event.type).includes("Failed to connect")) throw new Error("OGI Addon Server is not running/is unreachable. Please start the server and try again.");
347
+ console.error("An error occurred:", event);
428
348
  });
429
- this.socket.on("close", (code, reason) => {
430
- if (code === 1008) {
431
- console.error("Authentication failed:", reason);
349
+ this.socket.addEventListener("close", (event) => {
350
+ this.transport.rejectPendingResponses("Websocket closed");
351
+ if (event.code === 1008) {
352
+ console.error("Authentication failed:", event.reason);
432
353
  return;
433
354
  }
434
- this.eventEmitter.emit("disconnect", reason);
355
+ this.eventEmitter.emit("disconnect", event.reason);
435
356
  console.log("Disconnected from OGI Addon Server");
436
- console.error(reason.toString());
357
+ console.error(event.reason);
437
358
  this.eventEmitter.emit("exit");
438
359
  this.socket.close();
439
360
  });
440
361
  this.registerMessageReceiver();
441
362
  }
442
- async userInputAsked(configBuilt, name, description, socket) {
363
+ async userInputAsked(configBuilt, name, description) {
443
364
  const config = configBuilt.build(false);
444
- const id = Math.random().toString(36).substring(7);
445
- if (!socket) throw new Error("Socket is not connected");
446
- socket.send(JSON.stringify({
365
+ return (await this.transport.send({
447
366
  event: "input-asked",
448
367
  args: {
449
368
  config,
450
369
  name,
451
370
  description
452
- },
453
- id
454
- }));
455
- return await this.waitForResponseFromServer(id);
371
+ }
372
+ }, { expectResponse: true })).args;
456
373
  }
457
374
  /**
458
375
  * Registers the message receiver for the socket. This is used to receive messages from the server and handle them.
459
376
  */
460
377
  registerMessageReceiver() {
461
- this.socket.on("message", async (data) => {
462
- const message = JSON.parse(data);
378
+ for (const event of [
379
+ "config-update",
380
+ "search",
381
+ "setup",
382
+ "library-search",
383
+ "game-details",
384
+ "check-for-updates",
385
+ "request-dl",
386
+ "catalog",
387
+ "task-run",
388
+ "launch-app"
389
+ ]) this.transport.on(event, async (message) => {
463
390
  switch (message.event) {
464
391
  case "config-update":
465
392
  const result = this.addon.config.updateConfig(message.args);
@@ -473,7 +400,7 @@ var OGIAddonWSListener = class {
473
400
  await this.handleEventWithResponse(message, (event) => this.eventEmitter.emit("search", message.args, event));
474
401
  break;
475
402
  case "setup": {
476
- let setupEvent = new require_EventResponse((screen, name, description) => this.userInputAsked(screen, name, description, this.socket));
403
+ let setupEvent = new require_EventResponse((screen, name, description) => this.userInputAsked(screen, name, description));
477
404
  this.eventEmitter.emit("setup", message.args, setupEvent);
478
405
  const interval = setInterval(() => {
479
406
  if (setupEvent.resolved) {
@@ -482,7 +409,7 @@ var OGIAddonWSListener = class {
482
409
  }
483
410
  this.send("defer-update", {
484
411
  logs: setupEvent.logs,
485
- deferID: message.args.deferID,
412
+ deferID: message.args,
486
413
  progress: setupEvent.progress,
487
414
  failed: setupEvent.failed
488
415
  });
@@ -504,12 +431,13 @@ var OGIAddonWSListener = class {
504
431
  await this.handleEventWithResponse(message, (event) => this.eventEmitter.emit("check-for-updates", message.args, event));
505
432
  break;
506
433
  case "request-dl":
507
- let requestDLEvent = new require_EventResponse((screen, name, description) => this.userInputAsked(screen, name, description, this.socket));
434
+ let requestDLEvent = new require_EventResponse((screen, name, description) => this.userInputAsked(screen, name, description));
508
435
  if (this.eventEmitter.listenerCount("request-dl") === 0) {
509
436
  this.respondToMessage(message.id, { error: "No event listener for request-dl" }, requestDLEvent);
510
437
  break;
511
438
  }
512
- this.eventEmitter.emit("request-dl", message.args.appID, message.args.info, requestDLEvent);
439
+ const { appID, info } = message.args;
440
+ this.eventEmitter.emit("request-dl", appID, info, requestDLEvent);
513
441
  const requestDLResult = await this.waitForEventToRespond(requestDLEvent);
514
442
  if (requestDLEvent.failed) {
515
443
  this.respondToMessage(message.id, void 0, requestDLEvent);
@@ -522,34 +450,36 @@ var OGIAddonWSListener = class {
522
450
  await this.handleEventWithResponseNoInput(message, (event) => this.eventEmitter.emit("catalog", event));
523
451
  break;
524
452
  case "task-run": {
525
- let taskRunEvent = new require_EventResponse((screen, name, description) => this.userInputAsked(screen, name, description, this.socket));
526
- const taskName = message.args.taskName && typeof message.args.taskName === "string" ? message.args.taskName : message.args.manifest && typeof message.args.manifest === "object" ? message.args.manifest.__taskName : void 0;
453
+ let taskRunEvent = new require_EventResponse((screen, name, description) => this.userInputAsked(screen, name, description));
454
+ const args = message.args;
455
+ const taskName = args.taskName && typeof args.taskName === "string" ? args.taskName : args.manifest && typeof args.manifest === "object" ? args.manifest.__taskName : void 0;
527
456
  if (taskName && typeof taskName === "string" && this.addon.hasTaskHandler(taskName)) {
528
457
  const handler = this.addon.getTaskHandler(taskName);
529
458
  const task = new Task(taskRunEvent);
459
+ const interval = setInterval(() => {
460
+ if (taskRunEvent.resolved) {
461
+ clearInterval(interval);
462
+ return;
463
+ }
464
+ this.send("defer-update", {
465
+ logs: taskRunEvent.logs,
466
+ deferID: args.deferID ?? "",
467
+ progress: taskRunEvent.progress,
468
+ failed: taskRunEvent.failed
469
+ });
470
+ }, 100);
530
471
  try {
531
- const interval = setInterval(() => {
532
- if (taskRunEvent.resolved) {
533
- clearInterval(interval);
534
- return;
535
- }
536
- this.send("defer-update", {
537
- logs: taskRunEvent.logs,
538
- deferID: message.args.deferID,
539
- progress: taskRunEvent.progress,
540
- failed: taskRunEvent.failed
541
- });
542
- }, 100);
543
472
  const result = handler(task, {
544
- manifest: message.args.manifest || {},
545
- downloadPath: message.args.downloadPath || "",
546
- name: message.args.name || "",
547
- libraryInfo: message.args.libraryInfo
473
+ manifest: args.manifest || {},
474
+ downloadPath: args.downloadPath || "",
475
+ name: args.name || "",
476
+ libraryInfo: args.libraryInfo
548
477
  });
549
478
  if (result instanceof Promise) await result;
550
- clearInterval(interval);
551
479
  } catch (error) {
552
480
  taskRunEvent.fail(error instanceof Error ? error.message : String(error));
481
+ } finally {
482
+ clearInterval(interval);
553
483
  }
554
484
  } else taskRunEvent.fail(taskName ? `No task handler registered for task name: ${taskName}` : "No task name provided");
555
485
  const taskRunResult = await this.waitForEventToRespond(taskRunEvent);
@@ -588,7 +518,7 @@ var OGIAddonWSListener = class {
588
518
  * If options.requireListener is set and that event has no listeners, responds with options.noListenerError and returns.
589
519
  */
590
520
  async handleEventWithResponse(message, emit, options) {
591
- const event = new require_EventResponse((screen, name, description) => this.userInputAsked(screen, name, description, this.socket));
521
+ const event = new require_EventResponse((screen, name, description) => this.userInputAsked(screen, name, description));
592
522
  if (options && this.eventEmitter.listenerCount(options.requireListener) === 0) {
593
523
  this.respondToMessage(message.id, { error: options.noListenerError }, event);
594
524
  return;
@@ -607,36 +537,27 @@ var OGIAddonWSListener = class {
607
537
  this.respondToMessage(message.id, result.data, event);
608
538
  }
609
539
  respondToMessage(messageID, response, originalEvent) {
610
- this.socket.send(JSON.stringify({
540
+ this.transport.send({
611
541
  event: "response",
612
542
  id: messageID,
613
543
  args: response,
614
544
  statusError: originalEvent ? originalEvent.failed : void 0
615
- }));
545
+ }, { expectResponse: false });
616
546
  console.log("dispatched response to " + messageID);
617
547
  }
618
- waitForResponseFromServer(messageID) {
619
- return new Promise((resolve) => {
620
- const waiter = (data) => {
621
- const message = JSON.parse(data);
622
- if (message.event !== "response") {
623
- this.socket.once("message", waiter);
624
- return;
625
- }
626
- console.log("received response from " + messageID);
627
- if (message.id === messageID) resolve(message.args);
628
- else this.socket.once("message", waiter);
629
- };
630
- this.socket.once("message", waiter);
631
- });
548
+ async requestResponse(event, args) {
549
+ return (await this.transport.send({
550
+ event,
551
+ args
552
+ }, { expectResponse: true })).args;
632
553
  }
633
554
  send(event, args) {
634
- const id = Math.random().toString(36).substring(7);
635
- this.socket.send(JSON.stringify({
555
+ const id = (0, _ogi_sdk_connect.randomMessageId)();
556
+ this.transport.send({
636
557
  event,
637
558
  args,
638
559
  id
639
- }));
560
+ }, { expectResponse: false });
640
561
  return id;
641
562
  }
642
563
  close() {
@@ -653,4 +574,5 @@ exports.Task = Task;
653
574
  exports.VERSION = VERSION;
654
575
  exports.ZodLibraryInfo = ZodLibraryInfo;
655
576
  exports.default = OGIAddon;
577
+ exports.extraction = require_extraction.extraction;
656
578
  //# sourceMappingURL=main.cjs.map