timer
This commit is contained in:
commit
94a6ebdac7
File diff suppressed because it is too large
Load Diff
|
|
@ -22,6 +22,7 @@
|
|||
"axios": "^1.13.2",
|
||||
"chalk": "^5.6.2",
|
||||
"electron-store": "^11.0.2",
|
||||
"get-windows": "^9.2.3",
|
||||
"lucide-react": "^0.552.0",
|
||||
"os-utils": "^0.0.14",
|
||||
"react": "^18.3.1",
|
||||
|
|
|
|||
|
|
@ -3,26 +3,11 @@ import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|||
import { getToken } from '../utils/tokenHelper.js';
|
||||
import chalk from "chalk";
|
||||
|
||||
const TOKEN_KEY = 'auth_token';
|
||||
const Reset = "\x1b[0m";
|
||||
const Bright = "\x1b[1m";
|
||||
const Dim = "\x1b[2m";
|
||||
const Underscore = "\x1b[4m";
|
||||
const Blink = "\x1b[5m";
|
||||
const Reverse = "\x1b[7m";
|
||||
const Hidden = "\x1b[8m";
|
||||
|
||||
const FgRed = "\x1b[31m";
|
||||
const FgGreen = "\x1b[32m";
|
||||
const FgYellow = "\x1b[33m";
|
||||
const FgBlue = "\x1b[34m";
|
||||
const FgMagenta = "\x1b[35m";
|
||||
const FgCyan = "\x1b[36m";
|
||||
const FgWhite = "\x1b[37m";
|
||||
const TOKEN_KEY = 'ACCESS_TOKEN';
|
||||
|
||||
const api: AxiosInstance = axios.create({
|
||||
baseURL: 'https://wired-terminally-muskrat.ngrok-free.app/api/v1', // 🔁 your backend
|
||||
timeout: 10000,
|
||||
baseURL: 'https://wired-terminally-muskrat.ngrok-free.app/api/v1/va', // 🔁 your backend
|
||||
// timeout: 10000,
|
||||
});
|
||||
|
||||
console.log("Creating Axios Instance", axios.VERSION);
|
||||
|
|
@ -33,8 +18,10 @@ console.log("Axios .request reference:", api.request);
|
|||
api.interceptors.request.use(
|
||||
async (config: AxiosRequestConfig): Promise<any> => {
|
||||
const token = await getToken(TOKEN_KEY);
|
||||
if (token && config.headers) {
|
||||
config.headers.token = token;
|
||||
config.headers = config.headers || {}
|
||||
|
||||
if (token) {
|
||||
config.headers['token'] = token;
|
||||
config.headers['ngrok-skip-browser-warning'] = 98098;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ import { getToken, saveToken, clearToken } from '../utils/tokenHelper.js';
|
|||
import { handleLogin, takeScreenshot } from '../utils/utilityFunctions.js';
|
||||
import api from '../api/axiosClient.js';
|
||||
|
||||
ipcMain.handle('get-token', async (_, TOKEN_KEY: string) => {
|
||||
ipcMain.handle('get-token', async (_, TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN") => {
|
||||
return await getToken(TOKEN_KEY);
|
||||
});
|
||||
|
||||
ipcMain.handle('save-token', async (_, TOKEN_KEY: string, token: string) => {
|
||||
ipcMain.handle('save-token', async (_, TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN", token: string) => {
|
||||
await saveToken(TOKEN_KEY, token);
|
||||
return true;
|
||||
});
|
||||
|
|
@ -28,14 +28,16 @@ ipcMain.handle('login-request', async (event, credentials: { email: string, pass
|
|||
return handleLogin(credentials);
|
||||
});
|
||||
|
||||
ipcMain.handle("logout-request", async () => {
|
||||
console.log("Logout handler triggered");
|
||||
ipcMain.handle('logout-request', async () => {
|
||||
try {
|
||||
console.log("Handle Logout listened")
|
||||
console.log("Token", await getToken("ACCESS_TOKEN"))
|
||||
const res = await api.get("/logout");
|
||||
console.log("logout response",res)
|
||||
return { success: true, data: res.data };
|
||||
} catch (err: any) {
|
||||
console.error("Logout failed:", err);
|
||||
return { success: false, error: err.message };
|
||||
if(res && ("success" in res) && res.success) {
|
||||
return {success: true, message: "Logout Successfully"}
|
||||
}
|
||||
return {success: false, message: ""}
|
||||
} catch(error) {
|
||||
return {success: false, message: ""}
|
||||
}
|
||||
});
|
||||
|
|
@ -1,49 +1,32 @@
|
|||
import { contextBridge, ipcRenderer } from "electron";
|
||||
|
||||
const electron = require('electron');
|
||||
|
||||
console.log("setting PreLoad")
|
||||
|
||||
|
||||
contextBridge.exposeInMainWorld('electron', {
|
||||
subscribeStatistics: (callback) =>
|
||||
ipcOn('statistics', (stats) => {
|
||||
callback(stats);
|
||||
}),
|
||||
subscribeChangeView: (callback) =>
|
||||
ipcOn('changeView', (view) => {
|
||||
callback(view);
|
||||
}),
|
||||
getStaticData: () => ipcInvoke('getStaticData'),
|
||||
sendFrameAction: (payload) => ipcSend('sendFrameAction', payload),
|
||||
|
||||
login: (credentials: { email: string, password: string }) => ipcRenderer.invoke('login-request', credentials),
|
||||
|
||||
logout: () => ipcRenderer.invoke('logout-request'),
|
||||
|
||||
getToken: (TOKEN_KEY: string) => ipcRenderer.invoke('get-token', TOKEN_KEY),
|
||||
getToken: (TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN") => ipcRenderer.invoke('get-token', TOKEN_KEY),
|
||||
uploadScreenshot: () => ipcRenderer.invoke('upload-screenshot'),
|
||||
|
||||
} satisfies Window['electron']);
|
||||
|
||||
function ipcInvoke<Key extends keyof EventPayloadMapping>(
|
||||
key: Key
|
||||
): Promise<EventPayloadMapping[Key]> {
|
||||
return electron.ipcRenderer.invoke(key);
|
||||
}
|
||||
// function ipcInvoke<Key extends keyof EventPayloadMapping>(
|
||||
// key: Key
|
||||
// ): Promise<EventPayloadMapping[Key]> {
|
||||
// return ipcRenderer.invoke(key);
|
||||
// }
|
||||
|
||||
function ipcOn<Key extends keyof EventPayloadMapping>(
|
||||
key: Key,
|
||||
callback: (payload: EventPayloadMapping[Key]) => void
|
||||
) {
|
||||
const cb = (_: Electron.IpcRendererEvent, payload: any) => callback(payload);
|
||||
electron.ipcRenderer.on(key, cb);
|
||||
return () => electron.ipcRenderer.off(key, cb);
|
||||
}
|
||||
// function ipcOn<Key extends keyof EventPayloadMapping>(
|
||||
// key: Key,
|
||||
// callback: (payload: EventPayloadMapping[Key]) => void
|
||||
// ) {
|
||||
// const cb = (_: Electron.IpcRendererEvent, payload: any) => callback(payload);
|
||||
// ipcRenderer.on(key, cb);
|
||||
// return () => ipcRenderer.off(key, cb);
|
||||
// }
|
||||
|
||||
function ipcSend<Key extends keyof EventPayloadMapping>(
|
||||
key: Key,
|
||||
payload: EventPayloadMapping[Key]
|
||||
) {
|
||||
electron.ipcRenderer.send(key, payload);
|
||||
}
|
||||
// function ipcSend<Key extends keyof EventPayloadMapping>(
|
||||
// key: Key,
|
||||
// payload: EventPayloadMapping[Key]
|
||||
// ) {
|
||||
// ipcRenderer.send(key, payload);
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ import Store from 'electron-store';
|
|||
|
||||
const store = new Store();
|
||||
|
||||
export async function getToken(TOKEN_KEY: string): Promise<string | null> {
|
||||
export async function getToken(TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN"): Promise<string | null> {
|
||||
const encryptedBase64 = store.get(TOKEN_KEY) as string | undefined;
|
||||
if (!encryptedBase64) return null;
|
||||
const encryptedBuffer = Buffer.from(encryptedBase64, 'base64');
|
||||
return safeStorage.decryptString(encryptedBuffer);
|
||||
}
|
||||
|
||||
export async function saveToken(TOKEN_KEY: string, token: string): Promise<void> {
|
||||
export async function saveToken(TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN", token: string): Promise<void> {
|
||||
const encryptedBuffer = safeStorage.encryptString(token);
|
||||
store.set(TOKEN_KEY, encryptedBuffer.toString('base64'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,10 @@ export const handleLogin = async (credentials: { email: string, password: string
|
|||
|
||||
console.log("API CAlled", response)
|
||||
const { accessToken, refreshToken } = response.data;
|
||||
await saveToken(accessToken, refreshToken);
|
||||
|
||||
await saveToken("ACCESS_TOKEN", accessToken);
|
||||
await saveToken("REFRESH_TOKEN", refreshToken);
|
||||
|
||||
return { success: true, user: response.data.user };
|
||||
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -92,13 +92,13 @@ const DashboardLayout: React.FC<DashboardLayoutProps> = ({ setUser }) => {
|
|||
>(new Map());
|
||||
|
||||
const handleLogout = async () => {
|
||||
try {
|
||||
const res = await window.electron.logout()
|
||||
if (res && res.success) {
|
||||
localStorage.removeItem("user");
|
||||
setUser(null);
|
||||
console.log("calling Logout UI");
|
||||
|
||||
try {
|
||||
const res = await window.electron.logout();
|
||||
console.log(res, "Logout done");
|
||||
navigate("/login");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Logout error:", error);
|
||||
}
|
||||
|
|
@ -447,7 +447,7 @@ const DashboardLayout: React.FC<DashboardLayoutProps> = ({ setUser }) => {
|
|||
))}
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
className="flex items-center justify-center w-10 h-10 rounded-lg transition-all duration-150 hover:bg-error/10 text-error hover:text-error mt-auto"
|
||||
className="flex items-center justify-center w-10 h-10 rounded-lg transition-all duration-150 hover:bg-error/10 text-error hover:text-error mt-auto cursor-pointer"
|
||||
title="Logout"
|
||||
>
|
||||
<LogOut size={18} />
|
||||
|
|
|
|||
|
|
@ -25,17 +25,9 @@ type UnsubscribeFunction = () => void;
|
|||
|
||||
interface Window {
|
||||
electron: {
|
||||
subscribeStatistics: (
|
||||
callback: (statistics: Statistics) => void
|
||||
) => UnsubscribeFunction;
|
||||
getStaticData: () => Promise<StaticData>;
|
||||
subscribeChangeView: (
|
||||
callback: (view: View) => void
|
||||
) => UnsubscribeFunction;
|
||||
sendFrameAction: (payload: FrameWindowAction) => void;
|
||||
login: (credentials: { email: string; password: string }) => Promise<any>;
|
||||
logout: () => Promise<{ success: boolean; error?: string }>;
|
||||
getToken: (tokenKey: string) => Promise<string | null>;
|
||||
logout: () => Promise<any>;
|
||||
getToken: (tokenKey: "ACCESS_TOKEN" | "REFRESH_TOKEN") => Promise<string | null>;
|
||||
uploadScreenshot: () => {};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue