Get Running Apps

This commit is contained in:
BhagwanSingh 2025-11-10 11:56:36 +05:30
parent fbf84bb7aa
commit 70cd30af95
4 changed files with 51 additions and 21 deletions

View File

@ -4,6 +4,7 @@ import { getToken, saveToken, clearToken } from '../utils/tokenHelper.js';
import { getActiveApp, handleLogin, takeScreenshot } from '../utils/utilityFunctions.js'; import { getActiveApp, handleLogin, takeScreenshot } from '../utils/utilityFunctions.js';
import api from '../api/axiosClient.js'; import api from '../api/axiosClient.js';
import { getMainWindow } from '../main.js'; import { getMainWindow } from '../main.js';
import { exec } from 'child_process';
ipcMain.handle('get-token', async (_, TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN") => { ipcMain.handle('get-token', async (_, TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN") => {
return await getToken(TOKEN_KEY); return await getToken(TOKEN_KEY);
@ -62,3 +63,22 @@ ipcMain.handle('resize-window', (event, width: number, height: number) => {
mainWindow.setSize(width, height); mainWindow.setSize(width, height);
} }
}); });
ipcMain.handle('get-running-apps', async () => {
return new Promise((resolve, reject) => {
exec('tasklist', (err, stdout) => {
if (err) return reject(err);
const lines = stdout.split('\n').slice(3); // skip headers
const apps = lines
.map(line => line.trim().split(/\s+/))
.filter(parts => parts.length > 1)
.map(parts => ({
name: parts[0],
pid: parts[1],
}));
resolve(apps);
});
});
});

View File

@ -10,6 +10,7 @@ contextBridge.exposeInMainWorld('electron', {
getActiveAppDetails: () => ipcRenderer.invoke('get-active-app'), getActiveAppDetails: () => ipcRenderer.invoke('get-active-app'),
toggleCloseBtn: (shouldEnable: boolean) => ipcRenderer.invoke('toggle-close-btn', shouldEnable), toggleCloseBtn: (shouldEnable: boolean) => ipcRenderer.invoke('toggle-close-btn', shouldEnable),
resizeWindow: (width: number, height: number) => ipcRenderer.invoke('resize-window', width, height), resizeWindow: (width: number, height: number) => ipcRenderer.invoke('resize-window', width, height),
getRunningApps: () => ipcRenderer.invoke('get-running-apps'),
} satisfies Window['electron']); } satisfies Window['electron']);
// function ipcInvoke<Key extends keyof EventPayloadMapping>( // function ipcInvoke<Key extends keyof EventPayloadMapping>(

View File

@ -125,6 +125,14 @@ const Dashboard: React.FC = () => {
className="btn btn-xs btn-outline mt-2"> className="btn btn-xs btn-outline mt-2">
Resize Toggle Resize Toggle
</button> </button>
<button
onClick={async () => {
const res = await window.electron.getRunningApps()
console.log(res, "Line 131")
}}
className="btn btn-xs btn-outline mt-2">
Get Running Apps
</button>
</div> </div>
{/* Widgets */} {/* Widgets */}

1
types.d.ts vendored
View File

@ -32,6 +32,7 @@ interface Window {
getActiveAppDetails: () => {}; getActiveAppDetails: () => {};
toggleCloseBtn: (shouldEnable: boolean) => {}, toggleCloseBtn: (shouldEnable: boolean) => {},
resizeWindow: (width: number, height: number) => {}, resizeWindow: (width: number, height: number) => {},
getRunningApps: () => Promise<{name: string, pid:string}[]>,
}; };
} }