Skip to content

Commit

Permalink
fix(skymp5-client): fix auth by deferring hot reload (skyrim-multipla…
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove authored Jun 4, 2024
1 parent 52fa452 commit b50c453
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions skymp5-client/src/services/services/authService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ export class AuthService extends ClientListener {
logTrace(this, `Received createActorMessage for self, resetting widgets`);
this.sp.browser.executeJavaScript('window.skyrimPlatform.widgets.set([]);');
this.authDialogOpen = false;

// The idea is to write authData to disk after auth dialog is closed
// This is because write to plugins dir triggers hotreload, which in turn breaks the auth dialog
// So we need to write to disk after dialog is closed
if (this.authDataWriteTask) {
const task = this.authDataWriteTask.authDataToWrite;
this.controller.once("update", () => this.writeAuthDataToDisk(task));
this.authDataWriteTask = null;
}
}
else {
logTrace(this, `Received createActorMessage for self, but auth dialog was not open so not resetting widgets`);
Expand Down Expand Up @@ -183,15 +192,16 @@ export class AuthService extends ClientListener {
this.refreshWidgets();
break;
}
this.writeAuthDataToDisk(authData);
this.authDataWriteTask = { authDataToWrite: authData };
this.controller.emitter.emit("authAttempt", { authGameData: { remote: authData } });

this.authAttemptProgressIndicator = true;


break;
case events.clearAuthData:
this.writeAuthDataToDisk(null);
// Doesn't seem to be used
this.authDataWriteTask = { authDataToWrite: null };
break;
case events.openGithub:
this.sp.win32.loadUrl(this.githubUrl);
Expand Down Expand Up @@ -571,8 +581,11 @@ export class AuthService extends ClientListener {
this.authAttemptProgressIndicator = false;
this.controller.lookupListener(NetworkingService).close();
logTrace(this, 'max logging delay reached received');
browserState.comment = "";
browserState.loginFailedReason = 'технические шоколадки\nпопробуйте еще раз\nпожалуйста\nили напишите нам в discord';
this.sp.browser.executeJavaScript(new FunctionInfo(this.loginFailedWidgetSetter).getText({ events, browserState, authData: authData }));

authData = null;
}

if (this.authAttemptProgressIndicator) {
Expand Down Expand Up @@ -617,6 +630,8 @@ export class AuthService extends ClientListener {
private authAttemptProgressIndicator = false;
private authAttemptProgressIndicatorCounter = 0;

private authDataWriteTask: { authDataToWrite: RemoteAuthGameData | null } | null = null;

private readonly githubUrl = "https://github.com/skyrim-multiplayer/skymp";
private readonly patreonUrl = "https://www.patreon.com/skymp";
private readonly pluginAuthDataName = `auth-data-no-load`;
Expand Down

0 comments on commit b50c453

Please sign in to comment.