From c0335a3f0b35d12df9372e50af304b3773297253 Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Sat, 30 Nov 2024 12:43:31 -0500 Subject: [PATCH] Fix windows demo page and launch dev behavior for PWA --- package.json | 2 +- packages/core/launch.ts | 1 - packages/core/utils/server.js | 8 +++++++- tests/demo/pages/windows/index.ts | 4 ++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index de47825..e0f3080 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "@commoners/solidarity": "0.0.53", "@commoners/splash-screen": "0.0.52", "@commoners/testing": "0.0.53", - "@commoners/windows": "0.0.52", + "@commoners/windows": "0.0.53", "@vitest/coverage-v8": "^2.0.3", "search-insights": "^2.15.0", "commoners": "0.0.53", diff --git a/packages/core/launch.ts b/packages/core/launch.ts index 33a0305..bd64236 100644 --- a/packages/core/launch.ts +++ b/packages/core/launch.ts @@ -11,7 +11,6 @@ import { spawnProcess } from './utils/processes.js' import { createServer } from './utils/server.js' import * as mobile from './mobile/index.js' -import { run } from 'node:test'; const open = import('open').then(m => m.default) diff --git a/packages/core/utils/server.js b/packages/core/utils/server.js index a1192a6..ea1b090 100644 --- a/packages/core/utils/server.js +++ b/packages/core/utils/server.js @@ -2,7 +2,7 @@ import http from 'node:http' import path from 'node:path'; import url from 'node:url'; -import { readFileSync, statSync } from 'node:fs'; +import { existsSync, readFileSync, statSync } from 'node:fs'; export const createServer = ({ root = process.cwd(), handler }) => { @@ -36,6 +36,12 @@ export const createServer = ({ root = process.cwd(), handler }) => { '.pdf': 'application/pdf', '.doc': 'application/msword' }; + + if (!existsSync(pathname)) { + res.statusCode = 404; + res.end(`File ${pathname} not found!`); + return; + } if (statSync(pathname).isDirectory()) pathname = path.join(pathname, 'index' + ext); diff --git a/tests/demo/pages/windows/index.ts b/tests/demo/pages/windows/index.ts index fabddc6..b225bbc 100644 --- a/tests/demo/pages/windows/index.ts +++ b/tests/demo/pages/windows/index.ts @@ -3,7 +3,6 @@ import { READY } from 'commoners:env' import '../../style.css' const app = document.getElementById('app')! -const popupButton = document.getElementById('popup')! // ---------------------- Window Buttons ---------------------- @@ -29,7 +28,8 @@ const openWindow = async (type, windows) => { const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1) READY.then(({ windows }) => { - if (!windows || (Object.keys(windows).length === 1 && windows.main)) popupButton.disabled = true + if (!windows) return app.innerHTML = '

Windows plugin is not available.

' + if (Object.keys(windows).length === 1 && windows.main) return `

Cannot open windows from a secondary window.

` Object.entries(windows).forEach(([ name, manager ]) => {