Compare commits

..

No commits in common. "fbf84bb7aa12f2034939bc6bfd8a5eb748136155" and "94a6ebdac7b3dd13220aa4365304e94a7df4e9b3" have entirely different histories.

7 changed files with 30 additions and 101 deletions

View File

@ -1,9 +1,8 @@
// electron/ipc/tokenHandler.ts // electron/ipc/tokenHandler.ts
import { ipcMain } from 'electron'; import { ipcMain } from 'electron';
import { getToken, saveToken, clearToken } from '../utils/tokenHelper.js'; import { getToken, saveToken, clearToken } from '../utils/tokenHelper.js';
import { getActiveApp, handleLogin, takeScreenshot } from '../utils/utilityFunctions.js'; import { handleLogin, takeScreenshot } from '../utils/utilityFunctions.js';
import api from '../api/axiosClient.js'; import api from '../api/axiosClient.js';
import { getMainWindow } from '../main.js';
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);
@ -34,31 +33,11 @@ ipcMain.handle('logout-request', async () => {
console.log("Handle Logout listened") console.log("Handle Logout listened")
console.log("Token", await getToken("ACCESS_TOKEN")) console.log("Token", await getToken("ACCESS_TOKEN"))
const res = await api.get("/logout"); const res = await api.get("/logout");
if (res && ("success" in res) && res.success) { if(res && ("success" in res) && res.success) {
return { success: true, message: "Logout Successfully" } return {success: true, message: "Logout Successfully"}
} }
return { success: false, message: "" } return {success: false, message: ""}
} catch (error) { } catch(error) {
return { success: false, message: "" } 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,27 +1,20 @@
import { app, BrowserWindow, ipcMain, session } from 'electron'; import { app, BrowserWindow, session } from 'electron';
import { ipcMainHandle, ipcMainOn, isDev } from './util.js'; import { ipcMainHandle, ipcMainOn, isDev } from './util.js';
import { getStaticData, pollResources } from './resourceManager.js'; import { getStaticData, pollResources } from './resourceManager.js';
import { getPreloadPath, getUIPath } from './pathResolver.js'; import { getPreloadPath, getUIPath } from './pathResolver.js';
import "./ipc/ipcHandler.js"; import "./ipc/ipcHandler.js";
let mainWindow:any = null;
app.on('ready', async () => { app.on('ready', async () => {
console.log("ready"); console.log("ready");
mainWindow = new BrowserWindow({ const mainWindow = new BrowserWindow({
width: 500, // fixed width width: 550, // fixed width
height: 600, // fixed height height: 750, // fixed height
resizable: false, // prevents resizing resizable: false, // prevents resizing
fullscreenable: false, // disables fullscreen toggle (F11 or double-click title bar) fullscreenable: false, // disables fullscreen toggle (F11 or double-click title bar)
minimizable: false, // disables minimize button
maximizable: false, // prevents maximize maximizable: false, // prevents maximize
closable: true,
alwaysOnTop: true,
autoHideMenuBar: true, autoHideMenuBar: true,
frame: process.platform === 'darwin' ? false : true, frame: process.platform === 'darwin' ? false : true,
webPreferences: { webPreferences: {
preload: getPreloadPath(), preload: getPreloadPath(),
@ -40,28 +33,30 @@ app.on('ready', async () => {
mainWindow.loadFile(getUIPath()); mainWindow.loadFile(getUIPath());
} }
// pollResources(mainWindow); pollResources(mainWindow);
// IPC handlers // IPC handlers
// ipcMainHandle('getStaticData', () => getStaticData()); ipcMainHandle('getStaticData', () => getStaticData());
// ipcMainOn('sendFrameAction', (payload) => { ipcMainOn('sendFrameAction', (payload) => {
// switch (payload) { switch (payload) {
// case 'CLOSE': case 'CLOSE':
// mainWindow.close(); mainWindow.close();
// break; break;
// case 'MAXIMIZE': case 'MAXIMIZE':
// // prevent maximize // prevent maximize
// break; break;
// case 'MINIMIZE': case 'MINIMIZE':
// mainWindow.minimize(); mainWindow.minimize();
// break; break;
// } }
// }); });
handleCloseEvents(mainWindow); handleCloseEvents(mainWindow);
}); });
function handleCloseEvents(mainWindow: BrowserWindow) { function handleCloseEvents(mainWindow: BrowserWindow) {
let willClose = false; let willClose = false;
@ -85,6 +80,4 @@ function handleCloseEvents(mainWindow: BrowserWindow) {
}); });
} }
export function getMainWindow() {
return mainWindow;
}

View File

@ -7,9 +7,6 @@ contextBridge.exposeInMainWorld('electron', {
logout: () => ipcRenderer.invoke('logout-request'), logout: () => ipcRenderer.invoke('logout-request'),
getToken: (TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN") => ipcRenderer.invoke('get-token', TOKEN_KEY), getToken: (TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN") => ipcRenderer.invoke('get-token', TOKEN_KEY),
uploadScreenshot: () => ipcRenderer.invoke('upload-screenshot'), 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']); } satisfies Window['electron']);
// function ipcInvoke<Key extends keyof EventPayloadMapping>( // function ipcInvoke<Key extends keyof EventPayloadMapping>(

View File

@ -4,7 +4,6 @@ import path from "path";
import axios from 'axios'; import axios from 'axios';
import sharp from 'sharp'; import sharp from 'sharp';
import { saveToken } from "./tokenHelper.js"; import { saveToken } from "./tokenHelper.js";
import { activeWindow } from "get-windows";
// Blur using an offscreen canvas // Blur using an offscreen canvas
async function blurAndCompressBase64Image(base64: string): Promise<Buffer> { async function blurAndCompressBase64Image(base64: string): Promise<Buffer> {
@ -66,7 +65,7 @@ export const handleLogin = async (credentials: { email: string, password: string
await saveToken("ACCESS_TOKEN", accessToken); await saveToken("ACCESS_TOKEN", accessToken);
await saveToken("REFRESH_TOKEN", refreshToken); await saveToken("REFRESH_TOKEN", refreshToken);
return { success: true, user: response.data.user }; return { success: true, user: response.data.user };
} catch (error) { } catch (error) {
@ -93,9 +92,4 @@ export const handleLogin = async (credentials: { email: string, password: string
return { success: false, error: "Unexpected error occurred" }; return { success: false, error: "Unexpected error occurred" };
} }
} }
export const getActiveApp = async () => {
const result = await activeWindow();
return result;
};

View File

@ -104,16 +104,6 @@ const DashboardLayout: React.FC<DashboardLayoutProps> = ({ setUser }) => {
} }
}; };
useEffect(() => {
setInterval(async () => {
const details = await window.electron.getActiveAppDetails()
console.log(details)
}, 15000)
}, [])
const toggleSidebar = () => setSidebarOpen(!isSidebarOpen); const toggleSidebar = () => setSidebarOpen(!isSidebarOpen);
const closeSidebarOnMobile = () => { const closeSidebarOnMobile = () => {

View File

@ -104,27 +104,6 @@ const Dashboard: React.FC = () => {
> >
Screenshot Test Screenshot Test
</button> </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> </div>
{/* Widgets */} {/* Widgets */}

3
types.d.ts vendored
View File

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