Get Running Apps
This commit is contained in:
parent
fbf84bb7aa
commit
70cd30af95
|
|
@ -4,6 +4,7 @@ import { getToken, saveToken, clearToken } from '../utils/tokenHelper.js';
|
|||
import { getActiveApp, handleLogin, takeScreenshot } from '../utils/utilityFunctions.js';
|
||||
import api from '../api/axiosClient.js';
|
||||
import { getMainWindow } from '../main.js';
|
||||
import { exec } from 'child_process';
|
||||
|
||||
ipcMain.handle('get-token', async (_, TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN") => {
|
||||
return await getToken(TOKEN_KEY);
|
||||
|
|
@ -61,4 +62,23 @@ ipcMain.handle('resize-window', (event, width: number, height: number) => {
|
|||
if (mainWindow && !mainWindow.isDestroyed()) {
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -10,6 +10,7 @@ contextBridge.exposeInMainWorld('electron', {
|
|||
getActiveAppDetails: () => ipcRenderer.invoke('get-active-app'),
|
||||
toggleCloseBtn: (shouldEnable: boolean) => ipcRenderer.invoke('toggle-close-btn', shouldEnable),
|
||||
resizeWindow: (width: number, height: number) => ipcRenderer.invoke('resize-window', width, height),
|
||||
getRunningApps: () => ipcRenderer.invoke('get-running-apps'),
|
||||
} satisfies Window['electron']);
|
||||
|
||||
// function ipcInvoke<Key extends keyof EventPayloadMapping>(
|
||||
|
|
|
|||
|
|
@ -104,27 +104,35 @@ const Dashboard: React.FC = () => {
|
|||
>
|
||||
Screenshot Test
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
window.electron.toggleCloseBtn(true)
|
||||
}}
|
||||
className="btn btn-xs btn-outline mt-2">
|
||||
<button
|
||||
onClick={() => {
|
||||
window.electron.toggleCloseBtn(true)
|
||||
}}
|
||||
className="btn btn-xs btn-outline mt-2">
|
||||
Enable
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
window.electron.toggleCloseBtn(false)
|
||||
}}
|
||||
className="btn btn-xs btn-outline mt-2">
|
||||
<button
|
||||
onClick={() => {
|
||||
window.electron.toggleCloseBtn(false)
|
||||
}}
|
||||
className="btn btn-xs btn-outline mt-2">
|
||||
Disable
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
window.electron.resizeWindow(500, 100)
|
||||
}}
|
||||
className="btn btn-xs btn-outline mt-2">
|
||||
<button
|
||||
onClick={() => {
|
||||
window.electron.resizeWindow(500, 100)
|
||||
}}
|
||||
className="btn btn-xs btn-outline mt-2">
|
||||
Resize Toggle
|
||||
</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>
|
||||
|
||||
{/* Widgets */}
|
||||
|
|
@ -204,10 +212,10 @@ const Dashboard: React.FC = () => {
|
|||
<span className="text-base-content/70">Status:</span>{" "}
|
||||
<span
|
||||
className={`badge ${selectedData?.isPaused
|
||||
? "badge-warning"
|
||||
: selectedData?.isTracking
|
||||
? "badge-success"
|
||||
: "badge-neutral"
|
||||
? "badge-warning"
|
||||
: selectedData?.isTracking
|
||||
? "badge-success"
|
||||
: "badge-neutral"
|
||||
}`}
|
||||
>
|
||||
{selectedData?.isPaused
|
||||
|
|
@ -264,8 +272,8 @@ const Dashboard: React.FC = () => {
|
|||
<td>
|
||||
<button
|
||||
className={`btn btn-xs ${isCurrentlySelected
|
||||
? "btn-success"
|
||||
: "btn-primary"
|
||||
? "btn-success"
|
||||
: "btn-primary"
|
||||
}`}
|
||||
onClick={() => handleProjectSelect(project.id)}
|
||||
disabled={isDisabled}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ interface Window {
|
|||
getActiveAppDetails: () => {};
|
||||
toggleCloseBtn: (shouldEnable: boolean) => {},
|
||||
resizeWindow: (width: number, height: number) => {},
|
||||
getRunningApps: () => Promise<{name: string, pid:string}[]>,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue