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",
|
"axios": "^1.13.2",
|
||||||
"chalk": "^5.6.2",
|
"chalk": "^5.6.2",
|
||||||
"electron-store": "^11.0.2",
|
"electron-store": "^11.0.2",
|
||||||
|
"get-windows": "^9.2.3",
|
||||||
"lucide-react": "^0.552.0",
|
"lucide-react": "^0.552.0",
|
||||||
"os-utils": "^0.0.14",
|
"os-utils": "^0.0.14",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
|
|
|
||||||
|
|
@ -3,26 +3,11 @@ import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||||
import { getToken } from '../utils/tokenHelper.js';
|
import { getToken } from '../utils/tokenHelper.js';
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
|
||||||
const TOKEN_KEY = 'auth_token';
|
const TOKEN_KEY = 'ACCESS_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 api: AxiosInstance = axios.create({
|
const api: AxiosInstance = axios.create({
|
||||||
baseURL: 'https://wired-terminally-muskrat.ngrok-free.app/api/v1', // 🔁 your backend
|
baseURL: 'https://wired-terminally-muskrat.ngrok-free.app/api/v1/va', // 🔁 your backend
|
||||||
timeout: 10000,
|
// timeout: 10000,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Creating Axios Instance", axios.VERSION);
|
console.log("Creating Axios Instance", axios.VERSION);
|
||||||
|
|
@ -33,8 +18,10 @@ console.log("Axios .request reference:", api.request);
|
||||||
api.interceptors.request.use(
|
api.interceptors.request.use(
|
||||||
async (config: AxiosRequestConfig): Promise<any> => {
|
async (config: AxiosRequestConfig): Promise<any> => {
|
||||||
const token = await getToken(TOKEN_KEY);
|
const token = await getToken(TOKEN_KEY);
|
||||||
if (token && config.headers) {
|
config.headers = config.headers || {}
|
||||||
config.headers.token = token;
|
|
||||||
|
if (token) {
|
||||||
|
config.headers['token'] = token;
|
||||||
config.headers['ngrok-skip-browser-warning'] = 98098;
|
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 { handleLogin, takeScreenshot } from '../utils/utilityFunctions.js';
|
||||||
import api from '../api/axiosClient.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);
|
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);
|
await saveToken(TOKEN_KEY, token);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
@ -28,14 +28,16 @@ ipcMain.handle('login-request', async (event, credentials: { email: string, pass
|
||||||
return handleLogin(credentials);
|
return handleLogin(credentials);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle("logout-request", async () => {
|
ipcMain.handle('logout-request', async () => {
|
||||||
console.log("Logout handler triggered");
|
|
||||||
try {
|
try {
|
||||||
|
console.log("Handle Logout listened")
|
||||||
|
console.log("Token", await getToken("ACCESS_TOKEN"))
|
||||||
const res = await api.get("/logout");
|
const res = await api.get("/logout");
|
||||||
console.log("logout response",res)
|
if(res && ("success" in res) && res.success) {
|
||||||
return { success: true, data: res.data };
|
return {success: true, message: "Logout Successfully"}
|
||||||
} catch (err: any) {
|
}
|
||||||
console.error("Logout failed:", err);
|
return {success: false, message: ""}
|
||||||
return { success: false, error: err.message };
|
} catch(error) {
|
||||||
|
return {success: false, message: ""}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -1,49 +1,32 @@
|
||||||
import { contextBridge, ipcRenderer } from "electron";
|
import { contextBridge, ipcRenderer } from "electron";
|
||||||
|
|
||||||
const electron = require('electron');
|
|
||||||
|
|
||||||
console.log("setting PreLoad")
|
console.log("setting PreLoad")
|
||||||
|
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld('electron', {
|
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),
|
login: (credentials: { email: string, password: string }) => ipcRenderer.invoke('login-request', credentials),
|
||||||
|
|
||||||
logout: () => ipcRenderer.invoke('logout-request'),
|
logout: () => ipcRenderer.invoke('logout-request'),
|
||||||
|
getToken: (TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN") => ipcRenderer.invoke('get-token', TOKEN_KEY),
|
||||||
getToken: (TOKEN_KEY: string) => ipcRenderer.invoke('get-token', TOKEN_KEY),
|
|
||||||
uploadScreenshot: () => ipcRenderer.invoke('upload-screenshot'),
|
uploadScreenshot: () => ipcRenderer.invoke('upload-screenshot'),
|
||||||
|
|
||||||
} satisfies Window['electron']);
|
} satisfies Window['electron']);
|
||||||
|
|
||||||
function ipcInvoke<Key extends keyof EventPayloadMapping>(
|
// function ipcInvoke<Key extends keyof EventPayloadMapping>(
|
||||||
key: Key
|
// key: Key
|
||||||
): Promise<EventPayloadMapping[Key]> {
|
// ): Promise<EventPayloadMapping[Key]> {
|
||||||
return electron.ipcRenderer.invoke(key);
|
// return ipcRenderer.invoke(key);
|
||||||
}
|
// }
|
||||||
|
|
||||||
function ipcOn<Key extends keyof EventPayloadMapping>(
|
// function ipcOn<Key extends keyof EventPayloadMapping>(
|
||||||
key: Key,
|
// key: Key,
|
||||||
callback: (payload: EventPayloadMapping[Key]) => void
|
// callback: (payload: EventPayloadMapping[Key]) => void
|
||||||
) {
|
// ) {
|
||||||
const cb = (_: Electron.IpcRendererEvent, payload: any) => callback(payload);
|
// const cb = (_: Electron.IpcRendererEvent, payload: any) => callback(payload);
|
||||||
electron.ipcRenderer.on(key, cb);
|
// ipcRenderer.on(key, cb);
|
||||||
return () => electron.ipcRenderer.off(key, cb);
|
// return () => ipcRenderer.off(key, cb);
|
||||||
}
|
// }
|
||||||
|
|
||||||
function ipcSend<Key extends keyof EventPayloadMapping>(
|
// function ipcSend<Key extends keyof EventPayloadMapping>(
|
||||||
key: Key,
|
// key: Key,
|
||||||
payload: EventPayloadMapping[Key]
|
// payload: EventPayloadMapping[Key]
|
||||||
) {
|
// ) {
|
||||||
electron.ipcRenderer.send(key, payload);
|
// ipcRenderer.send(key, payload);
|
||||||
}
|
// }
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,14 @@ import Store from 'electron-store';
|
||||||
|
|
||||||
const store = new 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;
|
const encryptedBase64 = store.get(TOKEN_KEY) as string | undefined;
|
||||||
if (!encryptedBase64) return null;
|
if (!encryptedBase64) return null;
|
||||||
const encryptedBuffer = Buffer.from(encryptedBase64, 'base64');
|
const encryptedBuffer = Buffer.from(encryptedBase64, 'base64');
|
||||||
return safeStorage.decryptString(encryptedBuffer);
|
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);
|
const encryptedBuffer = safeStorage.encryptString(token);
|
||||||
store.set(TOKEN_KEY, encryptedBuffer.toString('base64'));
|
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)
|
console.log("API CAlled", response)
|
||||||
const { accessToken, refreshToken } = response.data;
|
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 };
|
return { success: true, user: response.data.user };
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -92,13 +92,13 @@ const DashboardLayout: React.FC<DashboardLayoutProps> = ({ setUser }) => {
|
||||||
>(new Map());
|
>(new Map());
|
||||||
|
|
||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
|
try {
|
||||||
|
const res = await window.electron.logout()
|
||||||
|
if (res && res.success) {
|
||||||
localStorage.removeItem("user");
|
localStorage.removeItem("user");
|
||||||
setUser(null);
|
setUser(null);
|
||||||
console.log("calling Logout UI");
|
navigate("/login");
|
||||||
|
}
|
||||||
try {
|
|
||||||
const res = await window.electron.logout();
|
|
||||||
console.log(res, "Logout done");
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Logout error:", error);
|
console.error("Logout error:", error);
|
||||||
}
|
}
|
||||||
|
|
@ -447,7 +447,7 @@ const DashboardLayout: React.FC<DashboardLayoutProps> = ({ setUser }) => {
|
||||||
))}
|
))}
|
||||||
<button
|
<button
|
||||||
onClick={handleLogout}
|
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"
|
title="Logout"
|
||||||
>
|
>
|
||||||
<LogOut size={18} />
|
<LogOut size={18} />
|
||||||
|
|
|
||||||
|
|
@ -25,17 +25,9 @@ type UnsubscribeFunction = () => void;
|
||||||
|
|
||||||
interface Window {
|
interface Window {
|
||||||
electron: {
|
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>;
|
login: (credentials: { email: string; password: string }) => Promise<any>;
|
||||||
logout: () => Promise<{ success: boolean; error?: string }>;
|
logout: () => Promise<any>;
|
||||||
getToken: (tokenKey: string) => Promise<string | null>;
|
getToken: (tokenKey: "ACCESS_TOKEN" | "REFRESH_TOKEN") => Promise<string | null>;
|
||||||
uploadScreenshot: () => {};
|
uploadScreenshot: () => {};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue