Skip to content

Commit 78c7d26

Browse files
committed
fix: access modifiers and catch execa errors
1 parent 21d8fcc commit 78c7d26

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/events/hubEventEmitter.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export interface InstallerEmitter extends EventEmitter {
1818
export class UnityHubInstallerEvent extends EventEmitter implements InstallerEmitter {
1919
#moduleTracker: Map<string, InstallerStatus> = new Map();
2020

21-
constructor() {
21+
public constructor() {
2222
super();
2323
}
2424

25-
completed: Promise<InstallerEvent[]> = new Promise((resolve, reject) => {
25+
public completed: Promise<InstallerEvent[]> = new Promise((resolve, reject) => {
2626
this.on(InstallerEventType.Completed, (events) => resolve(events));
2727
this.on(InstallerEventType.Error, (error) => reject(error));
2828
this.on(InstallerEventType.Cancelled, (events) => reject(new Error("Cancelled")));
@@ -33,7 +33,7 @@ export class UnityHubInstallerEvent extends EventEmitter implements InstallerEmi
3333
* @param raw - The raw event string from Unity Hub.
3434
* @returns {void}
3535
*/
36-
Progress(raw: string): void {
36+
public Progress(raw: string): void {
3737
const events = UnityHubEventParser.parseUnityHubEvent(raw);
3838
if (events.length === 0) return;
3939

@@ -47,14 +47,14 @@ export class UnityHubInstallerEvent extends EventEmitter implements InstallerEmi
4747
this.#Complete(progressEvents);
4848
}
4949

50-
#Error(events: InstallerEvent[]) {
50+
#Error(events: InstallerEvent[]): void {
5151
const errorEvents = events.filter((e) => e.status === InstallerStatus.Error);
5252

5353
if (errorEvents.length === 0) return;
5454
this.emit(InstallerEventType.Error, errorEvents);
5555
}
5656

57-
#Complete(events: InstallerEvent[]) {
57+
#Complete(events: InstallerEvent[]): void {
5858
const installed = events.filter((e) => e.status === InstallerStatus.Installed);
5959
if (installed.length > 0 && installed.length === events.length) {
6060
this.emit(InstallerEventType.Completed, installed);
@@ -65,17 +65,17 @@ export class UnityHubInstallerEvent extends EventEmitter implements InstallerEmi
6565
* Emits a cancelled event.
6666
* @returns {void}
6767
*/
68-
Cancel(): void {
68+
public Cancel(): void {
6969
//Cancel operation
7070
this.#moduleTracker.clear();
7171
this.#Cancelled([]);
7272
}
7373

74-
#Cancelled(event: InstallerEvent[]) {
74+
#Cancelled(event: InstallerEvent[]): void {
7575
this.emit(InstallerEventType.Cancelled, event);
7676
}
7777

78-
#updateModuleTracker(events: InstallerEvent[]) {
78+
#updateModuleTracker(events: InstallerEvent[]): void {
7979
for (const event of events) {
8080
this.#moduleTracker.set(event.module, event.status);
8181
}

src/events/hubEventParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class UnityHubEventParser {
1919

2020
for (const line of lines) {
2121
const match = line.match(pattern);
22-
if (match && match.groups) {
22+
if (match?.groups) {
2323
const { module, status, progress } = match.groups;
2424
events.push({
2525
module: module.trim(),

src/unityHub.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ class UnityHub {
240240
reject: false,
241241
//onStderr: (data: string) => installerEmitter.Progress(data),
242242
onStdout: (data: string) => installerEmitter.Progress(data),
243+
}).catch((error) => {
244+
console.error(`Error adding module ${modules} to Unity ${editorVersion}:`, error);
243245
});
244246
return installerEmitter;
245247
} catch (error) {
@@ -288,6 +290,8 @@ class UnityHub {
288290
reject: false,
289291
//onStderr: (data: string) => installerEmitter.Error(data),
290292
onStdout: (data: string) => installerEmitter.Progress(data),
293+
}).catch((error) => {
294+
console.error(`Error installing Unity ${version}:`, error);
291295
});
292296

293297
return installerEmitter;

0 commit comments

Comments
 (0)