Disable Close and Minimize Tracker IPC Handle
This commit is contained in:
parent
3f190f333b
commit
fbf84bb7aa
|
|
@ -3,6 +3,7 @@ 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 { getActiveApp, 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);
|
||||||
|
|
@ -33,15 +34,31 @@ 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', () => {
|
ipcMain.handle('get-active-app', () => {
|
||||||
return getActiveApp();
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
@ -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 { 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");
|
||||||
|
|
||||||
const mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 550, // fixed width
|
width: 500, // fixed width
|
||||||
height: 750, // fixed height
|
height: 600, // 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(),
|
||||||
|
|
@ -33,30 +40,28 @@ 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;
|
||||||
|
|
||||||
|
|
@ -80,4 +85,6 @@ function handleCloseEvents(mainWindow: BrowserWindow) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getMainWindow() {
|
||||||
|
return mainWindow;
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,8 @@ contextBridge.exposeInMainWorld('electron', {
|
||||||
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'),
|
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>(
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,27 @@ 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 */}
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ interface Window {
|
||||||
getToken: (tokenKey: "ACCESS_TOKEN" | "REFRESH_TOKEN") => Promise<string | null>;
|
getToken: (tokenKey: "ACCESS_TOKEN" | "REFRESH_TOKEN") => Promise<string | null>;
|
||||||
uploadScreenshot: () => {};
|
uploadScreenshot: () => {};
|
||||||
getActiveAppDetails: () => {};
|
getActiveAppDetails: () => {};
|
||||||
|
toggleCloseBtn: (shouldEnable: boolean) => {},
|
||||||
|
resizeWindow: (width: number, height: number) => {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue