Compare commits

..

3 Commits

Author SHA1 Message Date
BhagwanSingh fbf84bb7aa Disable Close and Minimize Tracker IPC Handle 2025-11-07 19:17:18 +05:30
BhagwanSingh 3f190f333b Merge branch 'merge' 2025-11-07 15:45:39 +05:30
BhagwanSingh 42dd4da26b Get Active Window 2025-11-07 13:51:55 +05:30
7 changed files with 101 additions and 30 deletions

View File

@ -1,8 +1,9 @@
// 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';
import { getMainWindow } from '../main.js';
ipcMain.handle('get-token', async (_, TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN") => {
return await getToken(TOKEN_KEY);
@ -33,11 +34,31 @@ ipcMain.handle('logout-request', async () => {
console.log("Handle Logout listened")
console.log("Token", await getToken("ACCESS_TOKEN"))
const res = await api.get("/logout");
if(res && ("success" in res) && res.success) {
return {success: true, message: "Logout Successfully"}
if (res && ("success" in res) && res.success) {
return { success: true, message: "Logout Successfully" }
}
return {success: false, message: ""}
} catch(error) {
return {success: false, message: ""}
return { success: false, message: "" }
} catch (error) {
return { success: false, message: "" }
}
});
ipcMain.handle('get-active-app', () => {
return getActiveApp();
});
ipcMain.handle('toggle-close-btn', (event, shouldEnable: boolean) => {
const mainWindow = getMainWindow()
console.log("toggle-close-btn Called", mainWindow)
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.setClosable(shouldEnable);
}
});
ipcMain.handle('resize-window', (event, width: number, height: number) => {
const mainWindow = getMainWindow()
console.log("toggle-close-btn Called", mainWindow)
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.setSize(width, height);
}
});

View File

@ -1,20 +1,27 @@
import { app, BrowserWindow, session } from 'electron';
import { app, BrowserWindow, ipcMain, session } from 'electron';
import { ipcMainHandle, ipcMainOn, isDev } from './util.js';
import { getStaticData, pollResources } from './resourceManager.js';
import { getPreloadPath, getUIPath } from './pathResolver.js';
import "./ipc/ipcHandler.js";
let mainWindow:any = null;
app.on('ready', async () => {
console.log("ready");
const mainWindow = new BrowserWindow({
width: 550, // fixed width
height: 750, // fixed height
mainWindow = new BrowserWindow({
width: 500, // fixed width
height: 600, // fixed height
resizable: false, // prevents resizing
fullscreenable: false, // disables fullscreen toggle (F11 or double-click title bar)
minimizable: false, // disables minimize button
maximizable: false, // prevents maximize
closable: true,
alwaysOnTop: true,
autoHideMenuBar: true,
frame: process.platform === 'darwin' ? false : true,
webPreferences: {
preload: getPreloadPath(),
@ -33,30 +40,28 @@ app.on('ready', async () => {
mainWindow.loadFile(getUIPath());
}
pollResources(mainWindow);
// pollResources(mainWindow);
// IPC handlers
ipcMainHandle('getStaticData', () => getStaticData());
// ipcMainHandle('getStaticData', () => getStaticData());
ipcMainOn('sendFrameAction', (payload) => {
switch (payload) {
case 'CLOSE':
mainWindow.close();
break;
case 'MAXIMIZE':
// prevent maximize
break;
case 'MINIMIZE':
mainWindow.minimize();
break;
}
});
// ipcMainOn('sendFrameAction', (payload) => {
// switch (payload) {
// case 'CLOSE':
// mainWindow.close();
// break;
// case 'MAXIMIZE':
// // prevent maximize
// break;
// case 'MINIMIZE':
// mainWindow.minimize();
// break;
// }
// });
handleCloseEvents(mainWindow);
});
function handleCloseEvents(mainWindow: BrowserWindow) {
let willClose = false;
@ -80,4 +85,6 @@ function handleCloseEvents(mainWindow: BrowserWindow) {
});
}
export function getMainWindow() {
return mainWindow;
}

View File

@ -7,6 +7,9 @@ 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'),
toggleCloseBtn: (shouldEnable: boolean) => ipcRenderer.invoke('toggle-close-btn', shouldEnable),
resizeWindow: (width: number, height: number) => ipcRenderer.invoke('resize-window', width, height),
} 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> {
@ -93,3 +94,8 @@ 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

@ -104,6 +104,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 = () => {

View File

@ -104,6 +104,27 @@ const Dashboard: React.FC = () => {
>
Screenshot Test
</button>
<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">
Disable
</button>
<button
onClick={() => {
window.electron.resizeWindow(500, 100)
}}
className="btn btn-xs btn-outline mt-2">
Resize Toggle
</button>
</div>
{/* Widgets */}

3
types.d.ts vendored
View File

@ -29,6 +29,9 @@ interface Window {
logout: () => Promise<any>;
getToken: (tokenKey: "ACCESS_TOKEN" | "REFRESH_TOKEN") => Promise<string | null>;
uploadScreenshot: () => {};
getActiveAppDetails: () => {};
toggleCloseBtn: (shouldEnable: boolean) => {},
resizeWindow: (width: number, height: number) => {},
};
}