Skip to content

Commit 6b14b40

Browse files
authored
Merge pull request #268 from Open-STEM/FranksDev
STOP button and Google login robustness
2 parents 68b5c9d + 1410d9b commit 6b14b40

5 files changed

Lines changed: 252 additions & 110 deletions

File tree

src/connections/connection.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ abstract class Connection {
648648
this.startReaduntil("KeyboardInterrupt:");
649649
await this.writeToDevice("\r" + this.CTRL_CMD_KINTERRUPT); // ctrl-C to interrupt any running program
650650
let result = await this.haltUntilRead(1, 20);
651+
651652
if (result == undefined) {
652653
this.startReaduntil(">>>");
653654
await this.writeToDevice("\r" + this.CTRL_CMD_NORMALMODE); // ctrl-C to interrupt any running program
@@ -656,17 +657,22 @@ abstract class Connection {
656657
return true;
657658
}
658659
}
660+
659661
//try multiple times to get to the prompt
660662
let gotToPrompt = false;
661663
for (let i = 0; i < 20; i++) {
662664
this.startReaduntil(">>>");
663-
await this.writeToDevice("\r" + this.CTRL_CMD_KINTERRUPT);
664-
result = await this.haltUntilRead(2, 5); //this should be fast
665+
await this.writeToDevice("\r" + this.CTRL_CMD_KINTERRUPT + this.CTRL_CMD_KINTERRUPT);
666+
result = await this.haltUntilRead(0, 5); //this should be fast
665667
if (result != undefined && result.length > 0) {
666668
gotToPrompt = true;
667669
break;
668670
}
669671
}
672+
673+
this.startReaduntil(">>>");
674+
await this.writeToDevice("\r" + this.CTRL_CMD_NORMALMODE); // ctrl-C to interrupt any running program
675+
result = await this.haltUntilRead(1, 20);
670676
return gotToPrompt;
671677
}
672678
async prepareForStop() {

src/services/google-auth.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,25 @@ class GoogleAuthService {
126126
}
127127
}
128128

129+
/**
130+
* Wait until the backend handshake token is available before exchanging OAuth codes.
131+
*/
132+
async ensureHandshakeReady(): Promise<void> {
133+
if (this._handshakeToken) {
134+
return;
135+
}
136+
const maxAttempts = 15;
137+
const delayMs = 200;
138+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
139+
await this.initHandshake();
140+
if (this._handshakeToken) {
141+
return;
142+
}
143+
await new Promise((resolve) => setTimeout(resolve, delayMs));
144+
}
145+
throw new Error('Google Auth handshake not ready');
146+
}
147+
129148
/**
130149
* Refreshes the access token using the stored refresh token.
131150
* @returns A Promise that resolves to the new access token.
@@ -226,8 +245,12 @@ class GoogleAuthService {
226245
* @returns A Promise that resolves to an object containing access_token, refresh_token, and expires_in.
227246
*/
228247
async getRefreshToken() {
229-
if (!this._handshakeToken || !this._code) {
230-
throw new Error('Handshake token or authorization code not available.');
248+
if (!this._code) {
249+
throw new Error('Authorization code not available.');
250+
}
251+
await this.ensureHandshakeReady();
252+
if (!this._handshakeToken) {
253+
throw new Error('Handshake token not available.');
231254
}
232255

233256
try {

src/utils/i18n/locales/en/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"user-folder": "User Folder Name",
108108
"google-drive-folder": "Google Drive Folder Name",
109109
"googleLoginTooltip": "Sign in with your Google account to access files stored in Google Drive.",
110+
"googleSigningIn": "Signing in...",
110111
"googlogoutTooltip": "Sign out of your Google account.",
111112
"not-google-drive-file": "This file can not be saved to Google Drive because it was not associated with Google Drive! Please try saving it to XRP!",
112113
"editGoogleLoginRequired": "This file is stored in Google Drive. Please sign back in to Google Drive to edit and save it.",

src/utils/i18n/locales/es/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
"username": "Nombre de Usuario",
192192
"googlesignin": "Iniciar sesión con Google",
193193
"googleLoginTooltip": "Inicie sesión con su cuenta de Google para acceder a los archivos almacenados en Google Drive.",
194+
"googleSigningIn": "Iniciando sesión...",
194195
"googlogoutTooltip": "Cerrar sesión de su cuenta de Google.",
195196
"login": "Inicio de Sesión de Google",
196197
"login-desc": "El modo de usuario está configurado actualmente en Usuario de Google. Por favor inicie sesión en su cuenta de Google para editar sus archivos. Haga clic en el botón Iniciar Sesión en Google a continuación.",

0 commit comments

Comments
 (0)