diff --git a/src/electron/ipc/ipcHandler.ts b/src/electron/ipc/ipcHandler.ts index 6ef2235..f3b8bbf 100644 --- a/src/electron/ipc/ipcHandler.ts +++ b/src/electron/ipc/ipcHandler.ts @@ -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(); }); \ No newline at end of file diff --git a/src/electron/preload.cts b/src/electron/preload.cts index 17297f8..b242939 100644 --- a/src/electron/preload.cts +++ b/src/electron/preload.cts @@ -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( diff --git a/src/electron/utils/utilityFunctions.ts b/src/electron/utils/utilityFunctions.ts index a4bd330..b38a090 100644 --- a/src/electron/utils/utilityFunctions.ts +++ b/src/electron/utils/utilityFunctions.ts @@ -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 { @@ -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" }; } -} \ No newline at end of file +} + +export const getActiveApp = async () => { + const result = await activeWindow(); + return result; +}; \ No newline at end of file diff --git a/src/ui/layout/DashboardLayout.tsx b/src/ui/layout/DashboardLayout.tsx index 6506ff6..a162a39 100644 --- a/src/ui/layout/DashboardLayout.tsx +++ b/src/ui/layout/DashboardLayout.tsx @@ -113,6 +113,16 @@ const DashboardLayout: React.FC = ({ setUser }) => { } }; + + + useEffect(() => { + setInterval(async () => { + const details = await window.electron.getActiveAppDetails() + console.log(details) + }, 15000) + }, []) + + const toggleSidebar = () => setSidebarOpen(!isSidebarOpen); const closeSidebarOnMobile = () => { diff --git a/types.d.ts b/types.d.ts index 6aec393..3b2ce1f 100644 --- a/types.d.ts +++ b/types.d.ts @@ -29,6 +29,7 @@ interface Window { logout: () => Promise; getToken: (tokenKey: "ACCESS_TOKEN" | "REFRESH_TOKEN") => Promise; uploadScreenshot: () => {}; + getActiveAppDetails: () => {}; }; }