Skip to content

Commit

Permalink
fix: promt user to restart as admin if they get a permission error
Browse files Browse the repository at this point in the history
  • Loading branch information
MattLish committed Aug 2, 2022
1 parent 3e50482 commit 1189059
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/main/services/error.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,15 @@ export class ErrorService {
logger.error(new Error().stack);
await dialog.showErrorBox(title, message);
}

async handleUnknownError(error?: unknown) {
logger.error(
`Unknown error. The stack trace might hold more details. ${error}`
);
logger.error(new Error().stack);
await dialog.showErrorBox(
"An unknown error has occurred",
"If you require more support, please post a message in the official modpack Discord and send your launcher log files."
);
}
}
42 changes: 30 additions & 12 deletions src/main/services/launcher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ModpackService } from "@/main/services/modpack.service";
import { BindingScope, injectable } from "@loopback/context";
import { app } from "electron";
import { logger } from "@/main/logger";
import { ErrorService } from "@/main/services/error.service";
import { WindowService } from "@/main/services/window.service";

@injectable({
scope: BindingScope.SINGLETON,
Expand All @@ -21,7 +23,9 @@ export class LauncherService {
@service(ModpackService) private modpackService: ModpackService,
@service(ProfileService) private profileService: ProfileService,
@service(ModOrganizerService)
private modOrganizerService: ModOrganizerService
private modOrganizerService: ModOrganizerService,
@service(ErrorService) private errorService: ErrorService,
@service(WindowService) private windowService: WindowService
) {}

async refreshModpack() {
Expand All @@ -30,17 +34,31 @@ export class LauncherService {
}

async setModpack(filepath: string) {
await this.configService.setPreference(
USER_PREFERENCE_KEYS.MOD_DIRECTORY,
filepath
);
await this.validateConfig();
await this.backupAssets();
await this.enbService.resetCurrentEnb(false);
await this.resolutionService.setResolution(
this.resolutionService.getResolutionPreference()
);
await this.resolutionService.setShouldDisableUltraWidescreen();
try {
await this.configService.setPreference(
USER_PREFERENCE_KEYS.MOD_DIRECTORY,
filepath
);
await this.validateConfig();
await this.backupAssets();
await this.enbService.resetCurrentEnb(false);
await this.resolutionService.setResolution(
this.resolutionService.getResolutionPreference()
);
await this.resolutionService.setShouldDisableUltraWidescreen();
} catch (error) {
if (error instanceof Error && error.message.includes("EPERM")) {
await this.errorService.handleError(
"Permission error",
`
The launcher has been unable to create/modify some files due to a permissions error.
It is strongly recommended you restart the application as an administrator.`
);
this.windowService.quit();
} else {
await this.errorService.handleUnknownError(error);
}
}
}

async validateConfig() {
Expand Down

0 comments on commit 1189059

Please sign in to comment.