Multiple Click Handle, Task Manager Instance Handle, Loader, Remove Unnecessary Polling

This commit is contained in:
BhagwanSingh 2025-11-17 09:52:09 +05:30
parent c0f0986a5f
commit f0e6b704cd
7 changed files with 201 additions and 69 deletions

39
package-lock.json generated
View File

@ -2814,11 +2814,12 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"node_modules/@types/minimatch": { "node_modules/@types/luxon": {
"version": "5.1.2", "version": "3.7.1",
"resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", "resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-3.7.1.tgz",
"integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==", "integrity": "sha512-H3iskjFIAn5SlJU7OuxUmTEpebK6TKB8rxZShDslBMZJ5u9S//KM1sbdAisiSrqwLQncVjnpi2OK2J51h+4lsg==",
"dev": true "dev": true,
"license": "MIT"
}, },
"node_modules/@types/ms": { "node_modules/@types/ms": {
"version": "2.1.0", "version": "2.1.0",
@ -8311,6 +8312,34 @@
"react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0" "react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0"
} }
}, },
"node_modules/luxon": {
"version": "3.7.2",
"resolved": "https://registry.npmjs.org/luxon/-/luxon-3.7.2.tgz",
"integrity": "sha512-vtEhXh/gNjI9Yg1u4jX/0YVPMvxzHuGgCm6tC5kZyb08yjGWGnqAjGJvcXbqQR2P3MyMEFnRbpcdFS6PBcLqew==",
"license": "MIT",
"engines": {
"node": ">=12"
}
},
"node_modules/lzma-native": {
"version": "8.0.6",
"resolved": "https://registry.npmjs.org/lzma-native/-/lzma-native-8.0.6.tgz",
"integrity": "sha512-09xfg67mkL2Lz20PrrDeNYZxzeW7ADtpYFbwSQh9U8+76RIzx5QsJBMy8qikv3hbUPfpy6hqwxt6FcGK81g9AA==",
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
"node-addon-api": "^3.1.0",
"node-gyp-build": "^4.2.1",
"readable-stream": "^3.6.0"
},
"bin": {
"lzmajs": "bin/lzmajs"
},
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/magic-string": { "node_modules/magic-string": {
"version": "0.30.21", "version": "0.30.21",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",

View File

@ -7,7 +7,7 @@
"scripts": { "scripts": {
"dev": "npm-run-all --parallel dev:react dev:electron", "dev": "npm-run-all --parallel dev:react dev:electron",
"dev:react": "vite", "dev:react": "vite",
"dev:electron": "npm run build && cross-env NODE_ENV=development electron --inspect=5858 .", "dev:electron": "npm run build && cross-env NODE_ENV=development electron .",
"prod:electron": "npm run build && cross-env NODE_ENV=production electron .", "prod:electron": "npm run build && cross-env NODE_ENV=production electron .",
"build": "tsc && vite build", "build": "tsc && vite build",
"preview": "vite preview", "preview": "vite preview",

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 27 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 27 KiB

29
src/assets/splash.html Normal file
View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
background: #ffffff;
font-family: Arial, sans-serif;
}
.loader {
width: 50px;
height: 50px;
border: 5px solid #e0e0e0;
border-top-color: #6a5acd;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
</style>
</head>
<body>
<div class="loader"></div>
</body>
</html>

View File

@ -1,105 +1,179 @@
import { app, BrowserWindow, ipcMain, session } from 'electron'; import { app, BrowserWindow, globalShortcut, session } from "electron";
import { ipcMainHandle, ipcMainOn, isDev } from './util.js'; import { isDev } from "./util.js";
import { getStaticData, pollResources } from './resourceManager.js'; // import { pollResources } from "./resourceManager.js";
import { getPreloadPath, getUIPath } from './pathResolver.js'; import { getPreloadPath, getUIPath } from "./pathResolver.js";
import { registerIPCHandlers } from "./ipc/ipcHandler.js";
import "./ipc/ipcHandler.js"; import "./ipc/ipcHandler.js";
import { registerIPCHandlers } from './ipc/ipcHandler.js'; import path from "path";
import { fileURLToPath } from "url";
let mainWindow:any = null; app.setAppUserModelId("com.tracker.app");
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => { const __filename = fileURLToPath(import.meta.url);
// Prevent the default behavior of showing a certificate error dialog const __dirname = path.dirname(__filename);
event.preventDefault();
// Allow the certificate, effectively ignoring the error // ---------------------------
callback(true); // SINGLE INSTANCE LOCK
// ---------------------------
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
process.exit(0);
}
let mainWindow: BrowserWindow | null = null;
let splashWindow: BrowserWindow | null = null;
// ---------------------------
// HANDLE DOUBLE OPEN ATTEMPT
// ---------------------------
app.on("second-instance", () => {
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.show();
mainWindow.focus();
}
}); });
app.on('ready', async () => { // ---------------------------
console.log("ready"); // MAIN APP READY
// ---------------------------
app.on("ready", async () => {
mainWindow = new BrowserWindow({
width: 500, // fixed width splashWindow = new BrowserWindow({
height: 600, // fixed height width: 300,
height: 300,
resizable: false, // prevents resizing frame: false,
fullscreenable: false, // disables fullscreen toggle (F11 or double-click title bar) transparent: false,
minimizable: false, // disables minimize button alwaysOnTop: false, // splash does NOT need to be on top || Yooo Don't make it onTop
maximizable: false, // prevents maximize resizable: false,
show: true,
skipTaskbar: true,
webPreferences: {
devTools: false,
}
});
splashWindow.loadFile(
path.join(__dirname, "../assets/splash.html")
);
// Create the main window
const win = new BrowserWindow({
width: 500,
height: 600,
resizable: false,
fullscreenable: false,
minimizable: false,
maximizable: false,
closable: true, closable: true,
alwaysOnTop: true, alwaysOnTop: true,
skipTaskbar: true,
autoHideMenuBar: true, autoHideMenuBar: true,
frame: process.platform === "darwin" ? false : true,
frame: process.platform === 'darwin' ? false : true, show: false, // speed improvement
webPreferences: { webPreferences: {
devTools: false,
preload: getPreloadPath(), preload: getPreloadPath(),
contextIsolation: true,
nodeIntegration: false,
}, },
}); });
session.defaultSession.webRequest.onBeforeRequest((details, callback) => { mainWindow = win;
console.log('🌐 Request:', details.method, details.url);
callback({ cancel: false });
});
if (isDev()) { // ------------------------------------
mainWindow.loadURL('http://localhost:5123'); // ONLY LOG NETWORK REQUESTS IN DEV
mainWindow.webContents.openDevTools(); // ------------------------------------
} else { if (isDev() && process.env.LOG_REQUESTS === "true") {
mainWindow.loadFile(getUIPath()); session.defaultSession.webRequest.onBeforeRequest((details, callback) => {
console.log("🌐 Request:", details.method, details.url);
callback({ cancel: false });
});
} }
// pollResources(mainWindow); // ------------------------------------
// 🔹 Register all IPC handlers (includes polling) // LOAD FRONTEND
registerIPCHandlers(mainWindow); // ------------------------------------
if (isDev()) {
win.loadURL("http://localhost:5123");
// win.webContents.openDevTools(); // Optional (slows startup)
} else {
win.loadFile(getUIPath());
}
pollResources(mainWindow); // ------------------------------------
// SHOW WINDOW WHEN READY (no white flash)
// ------------------------------------
win.once("ready-to-show", () => {
// Delay heavy work to improve startup speed
setTimeout(() => {
splashWindow?.close();
splashWindow = null;
// IPC handlers win.show();
// ipcMainHandle('getStaticData', () => getStaticData()); // pollResources(win);
registerIPCHandlers(win);
}, 500);
});
// ipcMainOn('sendFrameAction', (payload) => { // ------------------------------------
// switch (payload) { // HANDLE CLOSE EVENTS
// case 'CLOSE': // ------------------------------------
// mainWindow.close(); handleCloseEvents(win);
// break;
// case 'MAXIMIZE':
// // prevent maximize
// break;
// case 'MINIMIZE':
// mainWindow.minimize();
// break;
// }
// });
handleCloseEvents(mainWindow);
}); });
function handleCloseEvents(mainWindow: BrowserWindow) {
app.on('browser-window-focus', () => {
globalShortcut.register('CommandOrControl+R', () => {
// Do nothing; disables reload
});
globalShortcut.register('F5', () => {
// Do nothing; disables reload
});
globalShortcut.register('CommandOrControl+Shift+I', () => {
// Do nothing; disables DevTools
});
});
app.on('browser-window-blur', () => {
globalShortcut.unregisterAll();
});
// ---------------------------
// CUSTOM CLOSE BEHAVIOR
// ---------------------------
function handleCloseEvents(window: BrowserWindow) {
let willClose = false; let willClose = false;
mainWindow.on('close', (e) => { window.on("close", (e) => {
if (willClose) return; if (willClose) return;
e.preventDefault(); e.preventDefault();
mainWindow.hide(); window.hide();
if (app.dock) { if (app.dock) {
app.dock.hide(); app.dock.hide();
} }
}); });
app.on('before-quit', () => { app.on("before-quit", () => {
willClose = true; willClose = true;
}); });
mainWindow.on('show', () => { window.on("show", () => {
willClose = false; willClose = false;
}); });
} }
// ---------------------------
// GET MAIN WINDOW EXPORT
// ---------------------------
export function getMainWindow() { export function getMainWindow() {
return mainWindow; return mainWindow;
} }

View File

@ -99,8 +99,6 @@ const App: React.FC = () => {
const theme = ThemeToggle(); const theme = ThemeToggle();
const dispatch = useDispatch<AppDispatch>(); const dispatch = useDispatch<AppDispatch>();
// ✅ Get user directly from Redux // ✅ Get user directly from Redux
const user = useSelector((state: RootState) => state.user.user); const user = useSelector((state: RootState) => state.user.user);