All files / src/views notifications.ts

49.45% Statements 45/91
100% Branches 0/0
0% Functions 0/4
49.45% Lines 45/91

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 931x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x             1x 1x 1x 1x 1x 1x 1x 1x                         1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                   1x 1x 1x 1x 1x 1x 1x 1x 1x                                          
import * as vscode from "vscode";
import { getAuthContext } from "../services/auth-service";
import {
  signInMenu,
  handleSignUp,
  handleSignOut,
} from "../services/auth-service";
 
const showErrors = true;
 
/**
 * Displays an error notification to the user in VS Code.
 *
 * Logs the error to the console and, if enabled, shows a non-modal error message in the editor.
 *
 * @param message - The error message to display.
 */
export async function errorNotification(message: string) {
  console.error(message);
  if (!showErrors) {
    return;
  }
  vscode.window.showErrorMessage(message, { modal: false });
}
 
/**
 * Prompts unauthenticated users to either sign in or sign up.
 *
 * Displays an informational notification with "Sign In" and "Sign Up" options,
 * and triggers the appropriate authentication workflow based on the user's choice.
 */
export async function authNotification() {
  const choice = await vscode.window.showInformationMessage(
    "You are not authenticated. Please sign in to track your progress!",
    "Sign In",
    "Sign Up"
  );

  if (choice === "Sign In") {
    await signInMenu();
  } else if (choice === "Sign Up") {
    await handleSignUp();
  }
}
 
 
/**
 * Notifies the user with a sign-out prompt.
 *
 * If the user confirms, triggers the sign-out process.
 *
 * @param messsage - The message to display with the sign-out option.
 */
export async function authSignOutNotification(messsage: string) {
  const signOutChoice = await vscode.window.showInformationMessage(
    `${messsage}`,
    "Sign Out"
  );

  if (signOutChoice === "Sign Out") {
    await handleSignOut();
  }
}
 
/**
 * Shows a temporary warning notification in the VS Code status bar.
 *
 * Displays the message for 2 seconds before automatically dismissing it.
 *
 * @param message - The message to display in the status bar.
 */
export async function showAuthNotification(message: string) {
  //   vscode.window.showInformationMessage(message, { modal: false });
  const notification = vscode.window.createStatusBarItem(
    vscode.StatusBarAlignment.Right,
    90
  );

  notification.text = `$(info) ${message}`;
  notification.color = new vscode.ThemeColor("statusBarItem.warningForeground");
  notification.backgroundColor = new vscode.ThemeColor(
    "statusBarItem.warningBackground"
  );
  notification.show();

  // Auto-dismiss after 2 seconds
  setTimeout(() => {
    notification.hide();
    notification.dispose();
  }, 2000);
}