Get Active Window

This commit is contained in:
BhagwanSingh 2025-11-07 13:51:55 +05:30
parent e2b0561251
commit 42dd4da26b
5 changed files with 25 additions and 3 deletions

View File

@ -1,7 +1,7 @@
// electron/ipc/tokenHandler.ts
import { ipcMain } from 'electron';
import { getToken, saveToken, clearToken } from '../utils/tokenHelper.js';
import { handleLogin, takeScreenshot } from '../utils/utilityFunctions.js';
import { getActiveApp, handleLogin, takeScreenshot } from '../utils/utilityFunctions.js';
import api from '../api/axiosClient.js';
ipcMain.handle('get-token', async (_, TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN") => {
@ -40,4 +40,8 @@ ipcMain.handle('logout-request', async () => {
} catch(error) {
return {success: false, message: ""}
}
});
ipcMain.handle('get-active-app', () => {
return getActiveApp();
});

View File

@ -7,6 +7,7 @@ contextBridge.exposeInMainWorld('electron', {
logout: () => ipcRenderer.invoke('logout-request'),
getToken: (TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN") => ipcRenderer.invoke('get-token', TOKEN_KEY),
uploadScreenshot: () => ipcRenderer.invoke('upload-screenshot'),
getActiveAppDetails: () => ipcRenderer.invoke('get-active-app'),
} satisfies Window['electron']);
// function ipcInvoke<Key extends keyof EventPayloadMapping>(

View File

@ -4,6 +4,7 @@ import path from "path";
import axios from 'axios';
import sharp from 'sharp';
import { saveToken } from "./tokenHelper.js";
import { activeWindow } from "get-windows";
// Blur using an offscreen canvas
async function blurAndCompressBase64Image(base64: string): Promise<Buffer> {
@ -65,7 +66,7 @@ export const handleLogin = async (credentials: { email: string, password: string
await saveToken("ACCESS_TOKEN", accessToken);
await saveToken("REFRESH_TOKEN", refreshToken);
return { success: true, user: response.data.user };
} catch (error) {
@ -92,4 +93,9 @@ export const handleLogin = async (credentials: { email: string, password: string
return { success: false, error: "Unexpected error occurred" };
}
}
}
export const getActiveApp = async () => {
const result = await activeWindow();
return result;
};

View File

@ -113,6 +113,16 @@ const DashboardLayout: React.FC<DashboardLayoutProps> = ({ setUser }) => {
}
};
useEffect(() => {
setInterval(async () => {
const details = await window.electron.getActiveAppDetails()
console.log(details)
}, 15000)
}, [])
const toggleSidebar = () => setSidebarOpen(!isSidebarOpen);
const closeSidebarOnMobile = () => {

1
types.d.ts vendored
View File

@ -29,6 +29,7 @@ interface Window {
logout: () => Promise<any>;
getToken: (tokenKey: "ACCESS_TOKEN" | "REFRESH_TOKEN") => Promise<string | null>;
uploadScreenshot: () => {};
getActiveAppDetails: () => {};
};
}