diff --git a/src/lib/crash.ts b/src/lib/crash.ts index 67272f2..8283a83 100644 --- a/src/lib/crash.ts +++ b/src/lib/crash.ts @@ -1,7 +1,6 @@ import { wm, wdata } from './windowManager'; -import { easeInOutQuad } from './animations'; import { wait, toP } from './utils' -import { app, screen } from 'electron'; +import { BrowserWindow, screen } from 'electron'; export default async function displayCrashScreen() { const bwdata = { ...wdata }; @@ -9,9 +8,12 @@ export default async function displayCrashScreen() { w: 40, h: 40, whp: true, - onCreate: (win: any) => { + onCreate: (win: BrowserWindow) => { win.loadURL(`http://localhost:${process.nfenv.serverPort}/screens/crash/index.html`); }, + onClose: function () { + process.exit(1) + } }); const button = wm.create({ w: 10, @@ -19,16 +21,22 @@ export default async function displayCrashScreen() { whp: true, noBorder: true, noBackground: true, - onCreate: (win: any) => { + onCreate: (win: BrowserWindow) => { win.loadURL(`http://localhost:${process.nfenv.serverPort}/screens/crash/exit.html`); }, }); await wait(300); - console.log('[nfcrash] Deleted all windows'); Object.keys(bwdata).forEach(async (id) => { bwdata[id].win.destroy(); // Note: We dont use wm.destroy(...) so ...onDestroy wont get called and cause trouble }); + console.log('[nfcrash] Deleted all windows'); const { width: sw, height: sh } = screen.getPrimaryDisplay().bounds; - wm.move({ id: button, y: 75, x: 50, p: true, fromCenter: true }); + const { height: csh, y: csy } = wdata[win].win.getBounds(); + await wait(100); + // Gives more control on the padding + // vvvvvvvvvv padding between the screen and exit button + const yTo = csy + csh + toP(sh, 6); + const xTo = toP(sw, 50); + wm.move({ id: button, y: yTo, x: xTo, fromCenter: true }); wm.follow.start(button, win); }; \ No newline at end of file diff --git a/src/lib/windowManager.ts b/src/lib/windowManager.ts index 450dfbc..79fc38f 100644 --- a/src/lib/windowManager.ts +++ b/src/lib/windowManager.ts @@ -64,8 +64,8 @@ const wm = { const tick = c.tick || 16; const totalSteps = Math.floor(duration / tick); - let targetX = toP(c.p ? sw : 1, c.x); - let targetY = toP(c.p ? sh : 1, c.y); + let targetX = c.p ? toP(sw, c.x) : c.x; + let targetY = c.p ? toP(sh, c.y) : c.y; if (c.fromCenter) { wb = win.win.getBounds(); @@ -113,38 +113,29 @@ const wm = { } const wb = win.win.getBounds(); const sW = wb.width, sH = wb.height; - // Use the given dimensions if provided; otherwise fall back to the current window size c.w = c.w === undefined ? sW : c.w; c.h = c.h === undefined ? sH : c.h; const duration = c.duration || 500; const tick = c.tick || 16; const totalSteps = Math.floor(duration / tick); - // Get primary display bounds – make sure that screen is imported from Electron const { width: sw, height: sh } = screen.getPrimaryDisplay().bounds; - // Calculate target width and height using percentage conversion if needed. - // Assuming toP converts a percentage value to pixels const targetW = toP(c.p ? sw : 1, c.w); const targetH = toP(c.p ? sh : 1, c.h); - // Compute window center for centering if needed const centerX = wb.x + wb.width / 2; const centerY = wb.y + wb.height / 2; - // Adjust position based on the chosen anchor. const getAnchoredPosition = (curWidth: number, curHeight: number) => { let newX = wb.x; let newY = wb.y; switch (c.anchor) { case 'top': - // Align to top – x remains same newY = wb.y; break; case 'bottom': - // Align to bottom newY = wb.y + wb.height - curHeight; break; case 'left': - // Align to left – y remains same newX = wb.x; break; case 'right': @@ -152,14 +143,12 @@ const wm = { newX = wb.x + wb.width - curWidth; break; default: - // Default: center the resized window relative to the original bounds newX = centerX - curWidth / 2; newY = centerY - curHeight / 2; } return { newX, newY }; }; - // Animation function to smooth the resize const animate = () => { let currentStep = 0; const startW = wb.width; @@ -170,7 +159,6 @@ const wm = { const eT = c.ease ? c.ease(t) : t; const newW = startW + (targetW - startW) * eT; const newH = startH + (targetH - startH) * eT; - // Get new positions based on the current width and height const pos = getAnchoredPosition(Math.round(newW), Math.round(newH)); win.win.setBounds({ x: pos.newX, @@ -181,7 +169,6 @@ const wm = { if (currentStep < totalSteps) { setTimeout(step, tick); } else { - // Make sure to set final bounds exactly const finalPos = getAnchoredPosition(Math.round(targetW), Math.round(targetH)); win.win.setBounds({ x: finalPos.newX, @@ -193,8 +180,6 @@ const wm = { }; step(); }; - - // Use animate if smooth animation is requested, otherwise set bounds immediately. if (c.smooth) { animate(); } else {