Route IPC through desktop notify and remove CLI OTP prompting.
OTP authentication is now handled by the desktop UI instead of stdin prompts. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
97974ada12
commit
7d8031e009
@ -4,7 +4,7 @@ import log4js from "log4js";
|
|||||||
import { startWaiting, stopWaiting } from "../spinner.js";
|
import { startWaiting, stopWaiting } from "../spinner.js";
|
||||||
import CupsPrinterInterface from "./interfaces/cupsinterface.js";
|
import CupsPrinterInterface from "./interfaces/cupsinterface.js";
|
||||||
import ReceiptInterface from "./interfaces/receiptinterface.js";
|
import ReceiptInterface from "./interfaces/receiptinterface.js";
|
||||||
import { sendIPC } from "../electron/ipc.js";
|
import { sendIPC } from "../desktop/notify.js";
|
||||||
// Load configuration
|
// Load configuration
|
||||||
const config = loadConfig();
|
const config = loadConfig();
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { loadConfig } from "../config.js";
|
import { loadConfig } from "../config.js";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import { sendIPC } from "../electron/ipc.js";
|
import { sendIPC } from "../desktop/notify.js";
|
||||||
import { DocumentPrinterClient } from "./documentprinterclient.js";
|
import { DocumentPrinterClient } from "./documentprinterclient.js";
|
||||||
import { startWaiting, stopWaiting } from "../spinner.js";
|
import { startWaiting, stopWaiting } from "../spinner.js";
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import axios from "axios";
|
|||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { loadConfig, ensureDataDir } from "../config.js";
|
import { loadConfig, ensureDataDir } from "../config.js";
|
||||||
import { sendIPC } from "../electron/ipc.js";
|
import { sendIPC } from "../desktop/notify.js";
|
||||||
|
|
||||||
const config = loadConfig();
|
const config = loadConfig();
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import { notPrompting } from "../utils.js";
|
|
||||||
import { getConfigPath, loadConfig } from "../config.js";
|
import { getConfigPath, loadConfig } from "../config.js";
|
||||||
import { applyLogLevel } from "../logging.js";
|
import { applyLogLevel } from "../logging.js";
|
||||||
import { getServerVersionInfo } from "../serverVersion.js";
|
import { getServerVersionInfo } from "../serverVersion.js";
|
||||||
@ -49,7 +48,6 @@ export class LocalServer {
|
|||||||
startWaiting("Authenticating with OTP via local server...", logger);
|
startWaiting("Authenticating with OTP via local server...", logger);
|
||||||
let result;
|
let result;
|
||||||
try {
|
try {
|
||||||
notPrompting();
|
|
||||||
result = await this.socketClient.authenticateWithOtp(otp, {
|
result = await this.socketClient.authenticateWithOtp(otp, {
|
||||||
retryOnFailure: false,
|
retryOnFailure: false,
|
||||||
logs: false,
|
logs: false,
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { randomUUID } from "crypto";
|
|||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import NodeCache from "node-cache";
|
import NodeCache from "node-cache";
|
||||||
import { loadConfig } from "../config.js";
|
import { loadConfig } from "../config.js";
|
||||||
import { sendIPC } from "../electron/ipc.js";
|
import { sendIPC } from "../desktop/notify.js";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
import { formatState } from "../commandlineutils.js";
|
import { formatState } from "../commandlineutils.js";
|
||||||
const config = loadConfig();
|
const config = loadConfig();
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
import { PrinterClient } from "./printerclient.js";
|
import { PrinterClient } from "./printerclient.js";
|
||||||
import { loadConfig } from "../config.js";
|
import { loadConfig } from "../config.js";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import { sendIPC } from "../electron/ipc.js";
|
import { sendIPC } from "../desktop/notify.js";
|
||||||
import { startWaiting, stopWaiting } from "../spinner.js";
|
import { startWaiting, stopWaiting } from "../spinner.js";
|
||||||
// Load configuration
|
// Load configuration
|
||||||
const config = loadConfig();
|
const config = loadConfig();
|
||||||
|
|||||||
@ -3,8 +3,8 @@ import { WebSocketScanner } from "../network/websocketScanner.js";
|
|||||||
import { io } from "socket.io-client";
|
import { io } from "socket.io-client";
|
||||||
// Load configuration
|
// Load configuration
|
||||||
import { loadConfig, saveConfig } from "../config.js";
|
import { loadConfig, saveConfig } from "../config.js";
|
||||||
import { askOtp, getDeviceInfo, notPrompting } from "../utils.js";
|
import { getDeviceInfo } from "../utils.js";
|
||||||
import { sendIPC } from "../electron/ipc.js";
|
import { sendIPC } from "../desktop/notify.js";
|
||||||
import { PrinterManager } from "../printer/printermanager.js";
|
import { PrinterManager } from "../printer/printermanager.js";
|
||||||
import { HostManager } from "../host/hostmanager.js";
|
import { HostManager } from "../host/hostmanager.js";
|
||||||
import { FileManager } from "../files/filemanager.js";
|
import { FileManager } from "../files/filemanager.js";
|
||||||
@ -152,11 +152,11 @@ export class SocketClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async authenticateWithOtp(otp = undefined, options = {}) {
|
async authenticateWithOtp(otp, options = {}) {
|
||||||
const { retryOnFailure = otp == undefined, logs = true } = options;
|
const { retryOnFailure = false, logs = true } = options;
|
||||||
|
|
||||||
if (otp == undefined) {
|
if (!otp) {
|
||||||
otp = await askOtp();
|
return { valid: false, error: "OTP is required" };
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.waitForConnection();
|
await this.waitForConnection();
|
||||||
@ -188,12 +188,6 @@ export class SocketClient {
|
|||||||
logger.error("Host not authenticated:", verifyResult.error);
|
logger.error("Host not authenticated:", verifyResult.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retryOnFailure) {
|
|
||||||
const retryResult = await this.authenticateWithOtp();
|
|
||||||
resolve(retryResult);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve({ valid: false, error: verifyResult.error });
|
resolve({ valid: false, error: verifyResult.error });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -331,7 +325,6 @@ export class SocketClient {
|
|||||||
logger.info("An OTP code is required to setup this host.");
|
logger.info("An OTP code is required to setup this host.");
|
||||||
this.authenticated = false;
|
this.authenticated = false;
|
||||||
sendIPC("setAuthenticated", false);
|
sendIPC("setAuthenticated", false);
|
||||||
this.authenticateWithOtp();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.authenticate({ id: config.host.id, authCode: config.host.authCode });
|
this.authenticate({ id: config.host.id, authCode: config.host.authCode });
|
||||||
@ -760,7 +753,6 @@ export class SocketClient {
|
|||||||
sendIPC("setConnected", false);
|
sendIPC("setConnected", false);
|
||||||
this.authenticated = false;
|
this.authenticated = false;
|
||||||
sendIPC("setAuthenticated", false);
|
sendIPC("setAuthenticated", false);
|
||||||
notPrompting();
|
|
||||||
this.scheduleReconnect();
|
this.scheduleReconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/utils.js
33
src/utils.js
@ -1,38 +1,5 @@
|
|||||||
import readline from "node:readline";
|
|
||||||
import os from "os";
|
import os from "os";
|
||||||
|
|
||||||
let isPrompting = false; // prevent multiple prompts at the same time
|
|
||||||
|
|
||||||
export async function askOtp() {
|
|
||||||
console.log("ASKING OTP");
|
|
||||||
if (isPrompting) return null; // prevent multiple prompts
|
|
||||||
isPrompting = true;
|
|
||||||
console.log("is not prompting");
|
|
||||||
|
|
||||||
const rl = readline.createInterface({
|
|
||||||
input: process.stdin,
|
|
||||||
output: process.stdout,
|
|
||||||
});
|
|
||||||
|
|
||||||
const question = (query) =>
|
|
||||||
new Promise((resolve) => rl.question(query, resolve));
|
|
||||||
|
|
||||||
try {
|
|
||||||
console.log("-----------");
|
|
||||||
const enteredOtp = await question("Enter OTP: ");
|
|
||||||
console.log("-----------");
|
|
||||||
isPrompting = false;
|
|
||||||
rl.close();
|
|
||||||
return enteredOtp.trim();
|
|
||||||
} catch (error) {
|
|
||||||
console.log("Error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function notPrompting() {
|
|
||||||
isPrompting = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getDeviceInfo() {
|
export function getDeviceInfo() {
|
||||||
return {
|
return {
|
||||||
os: {
|
os: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user