wm 1.0.2, minor crash screen adjustments

This commit is contained in:
Annie 2025-03-08 14:30:05 +03:00
parent ac2b338f13
commit 1c084b16f5
2 changed files with 16 additions and 23 deletions

View file

@ -1,7 +1,6 @@
import { wm, wdata } from './windowManager'; import { wm, wdata } from './windowManager';
import { easeInOutQuad } from './animations';
import { wait, toP } from './utils' import { wait, toP } from './utils'
import { app, screen } from 'electron'; import { BrowserWindow, screen } from 'electron';
export default async function displayCrashScreen() { export default async function displayCrashScreen() {
const bwdata = { ...wdata }; const bwdata = { ...wdata };
@ -9,9 +8,12 @@ export default async function displayCrashScreen() {
w: 40, w: 40,
h: 40, h: 40,
whp: true, whp: true,
onCreate: (win: any) => { onCreate: (win: BrowserWindow) => {
win.loadURL(`http://localhost:${process.nfenv.serverPort}/screens/crash/index.html`); win.loadURL(`http://localhost:${process.nfenv.serverPort}/screens/crash/index.html`);
}, },
onClose: function () {
process.exit(1)
}
}); });
const button = wm.create({ const button = wm.create({
w: 10, w: 10,
@ -19,16 +21,22 @@ export default async function displayCrashScreen() {
whp: true, whp: true,
noBorder: true, noBorder: true,
noBackground: true, noBackground: true,
onCreate: (win: any) => { onCreate: (win: BrowserWindow) => {
win.loadURL(`http://localhost:${process.nfenv.serverPort}/screens/crash/exit.html`); win.loadURL(`http://localhost:${process.nfenv.serverPort}/screens/crash/exit.html`);
}, },
}); });
await wait(300); await wait(300);
console.log('[nfcrash] Deleted all windows');
Object.keys(bwdata).forEach(async (id) => { Object.keys(bwdata).forEach(async (id) => {
bwdata[id].win.destroy(); // Note: We dont use wm.destroy(...) so ...onDestroy wont get called and cause trouble 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; 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); wm.follow.start(button, win);
}; };

View file

@ -64,8 +64,8 @@ const wm = {
const tick = c.tick || 16; const tick = c.tick || 16;
const totalSteps = Math.floor(duration / tick); const totalSteps = Math.floor(duration / tick);
let targetX = toP(c.p ? sw : 1, c.x); let targetX = c.p ? toP(sw, c.x) : c.x;
let targetY = toP(c.p ? sh : 1, c.y); let targetY = c.p ? toP(sh, c.y) : c.y;
if (c.fromCenter) { if (c.fromCenter) {
wb = win.win.getBounds(); wb = win.win.getBounds();
@ -113,38 +113,29 @@ const wm = {
} }
const wb = win.win.getBounds(); const wb = win.win.getBounds();
const sW = wb.width, sH = wb.height; 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.w = c.w === undefined ? sW : c.w;
c.h = c.h === undefined ? sH : c.h; c.h = c.h === undefined ? sH : c.h;
const duration = c.duration || 500; const duration = c.duration || 500;
const tick = c.tick || 16; const tick = c.tick || 16;
const totalSteps = Math.floor(duration / tick); 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; 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 targetW = toP(c.p ? sw : 1, c.w);
const targetH = toP(c.p ? sh : 1, c.h); const targetH = toP(c.p ? sh : 1, c.h);
// Compute window center for centering if needed
const centerX = wb.x + wb.width / 2; const centerX = wb.x + wb.width / 2;
const centerY = wb.y + wb.height / 2; const centerY = wb.y + wb.height / 2;
// Adjust position based on the chosen anchor.
const getAnchoredPosition = (curWidth: number, curHeight: number) => { const getAnchoredPosition = (curWidth: number, curHeight: number) => {
let newX = wb.x; let newX = wb.x;
let newY = wb.y; let newY = wb.y;
switch (c.anchor) { switch (c.anchor) {
case 'top': case 'top':
// Align to top x remains same
newY = wb.y; newY = wb.y;
break; break;
case 'bottom': case 'bottom':
// Align to bottom
newY = wb.y + wb.height - curHeight; newY = wb.y + wb.height - curHeight;
break; break;
case 'left': case 'left':
// Align to left y remains same
newX = wb.x; newX = wb.x;
break; break;
case 'right': case 'right':
@ -152,14 +143,12 @@ const wm = {
newX = wb.x + wb.width - curWidth; newX = wb.x + wb.width - curWidth;
break; break;
default: default:
// Default: center the resized window relative to the original bounds
newX = centerX - curWidth / 2; newX = centerX - curWidth / 2;
newY = centerY - curHeight / 2; newY = centerY - curHeight / 2;
} }
return { newX, newY }; return { newX, newY };
}; };
// Animation function to smooth the resize
const animate = () => { const animate = () => {
let currentStep = 0; let currentStep = 0;
const startW = wb.width; const startW = wb.width;
@ -170,7 +159,6 @@ const wm = {
const eT = c.ease ? c.ease(t) : t; const eT = c.ease ? c.ease(t) : t;
const newW = startW + (targetW - startW) * eT; const newW = startW + (targetW - startW) * eT;
const newH = startH + (targetH - startH) * 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)); const pos = getAnchoredPosition(Math.round(newW), Math.round(newH));
win.win.setBounds({ win.win.setBounds({
x: pos.newX, x: pos.newX,
@ -181,7 +169,6 @@ const wm = {
if (currentStep < totalSteps) { if (currentStep < totalSteps) {
setTimeout(step, tick); setTimeout(step, tick);
} else { } else {
// Make sure to set final bounds exactly
const finalPos = getAnchoredPosition(Math.round(targetW), Math.round(targetH)); const finalPos = getAnchoredPosition(Math.round(targetW), Math.round(targetH));
win.win.setBounds({ win.win.setBounds({
x: finalPos.newX, x: finalPos.newX,
@ -193,8 +180,6 @@ const wm = {
}; };
step(); step();
}; };
// Use animate if smooth animation is requested, otherwise set bounds immediately.
if (c.smooth) { if (c.smooth) {
animate(); animate();
} else { } else {