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

@ -105,26 +105,34 @@ const Dashboard: React.FC = () => {
Screenshot Test Screenshot Test
</button> </button>
<button <button
onClick={() => { onClick={() => {
window.electron.toggleCloseBtn(true) window.electron.toggleCloseBtn(true)
}} }}
className="btn btn-xs btn-outline mt-2"> className="btn btn-xs btn-outline mt-2">
Enable Enable
</button> </button>
<button <button
onClick={() => { onClick={() => {
window.electron.toggleCloseBtn(false) window.electron.toggleCloseBtn(false)
}} }}
className="btn btn-xs btn-outline mt-2"> className="btn btn-xs btn-outline mt-2">
Disable Disable
</button> </button>
<button <button
onClick={() => { onClick={() => {
window.electron.resizeWindow(500, 100) window.electron.resizeWindow(500, 100)
}} }}
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 */}
@ -204,10 +212,10 @@ const Dashboard: React.FC = () => {
<span className="text-base-content/70">Status:</span>{" "} <span className="text-base-content/70">Status:</span>{" "}
<span <span
className={`badge ${selectedData?.isPaused className={`badge ${selectedData?.isPaused
? "badge-warning" ? "badge-warning"
: selectedData?.isTracking : selectedData?.isTracking
? "badge-success" ? "badge-success"
: "badge-neutral" : "badge-neutral"
}`} }`}
> >
{selectedData?.isPaused {selectedData?.isPaused
@ -264,8 +272,8 @@ const Dashboard: React.FC = () => {
<td> <td>
<button <button
className={`btn btn-xs ${isCurrentlySelected className={`btn btn-xs ${isCurrentlySelected
? "btn-success" ? "btn-success"
: "btn-primary" : "btn-primary"
}`} }`}
onClick={() => handleProjectSelect(project.id)} onClick={() => handleProjectSelect(project.id)}
disabled={isDisabled} disabled={isDisabled}

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}[]>,
}; };
} }