diff --git a/README.md b/README.md index 2fa4664..a145b18 100644 --- a/README.md +++ b/README.md @@ -400,8 +400,8 @@ can't be rebuilt after a change, it's marked and the reason is shown. - **A "Working…" spinner**: the geometry engine is busy; complex steps can take a moment. **Stop** next to it drops the work and takes back the change that started it (like an undo). -- **A change you expected isn't there yet**: when a newer version is out, a - notice offers to update. **More → Update** loads the newest +- **A change you expected isn't there yet**: when a newer version is out, + **More** pulses and its **Update** item says NEW. **More → Update** loads the newest version right away (your project is kept). --- diff --git a/src/app.ts b/src/app.ts index 8cd212e..9e7f5f1 100644 --- a/src/app.ts +++ b/src/app.ts @@ -26,7 +26,7 @@ import { SketchTool } from "./tools/sketch"; import { bodiesOf, edgeRefOf, faceRefOf, sameSel, sourcesOf, type AppContext, type Sel, type Tool } from "./tools/tool"; import { setupRightColumn } from "./ui/panels"; import type { ToolItem } from "./ui/ui"; -import { el, UI } from "./ui/ui"; +import { UI } from "./ui/ui"; import { setUnits, setVariables } from "./units"; import { InputRouter } from "./view/input"; import { ViewCube } from "./view/viewcube"; @@ -818,27 +818,14 @@ export class App implements AppContext { if (isFull()) return void (document.exitFullscreen?.() ?? doc.webkitExitFullscreen?.()); goFull(); }); - // On opening, on every device: offer full screen (a browser only allows it - // from a tap, so it has to be asked). Not where it can't be done, or already is. + // The welcome window (and File → Open) has a Full screen button too (a + // browser only allows it from a tap). Not where it can't be done, or where + // the app already has the whole screen (installed). const canFull = !!(root.requestFullscreen || root.webkitRequestFullscreen) && (document.fullscreenEnabled ?? true); - const already = () => isFull() || matchMedia("(display-mode: fullscreen)").matches || matchMedia("(display-mode: standalone)").matches; - if (canFull && !already()) { - const banner = el("div", "update-banner compact-banner"); - banner.addEventListener("pointerdown", (e) => e.stopPropagation()); - const yes = el("button", "text-btn primary", "Full screen"); - const away = () => banner.remove(); - yes.addEventListener("click", () => (away(), goFull())); - // No "Not now": a click on the workspace (or waiting) puts it away. - banner.append(el("span", "", "Use the whole screen?"), yes); - setTimeout(() => !already() && document.body.append(banner), 800); - // Unanswered: it goes away by itself (More → Fullscreen is always there). - setTimeout(away, 15_000); - document.addEventListener("fullscreenchange", () => isFull() && away()); - // A click or tap on the workspace answers it ("not now"). - document.getElementById("view")?.addEventListener("pointerdown", away, { once: true, capture: true }); - } + const installed = matchMedia("(display-mode: fullscreen)").matches || matchMedia("(display-mode: standalone)").matches; + this.fullscreen = canFull && !installed ? { isFull, toggle: () => (isFull() ? void (document.exitFullscreen?.() ?? doc.webkitExitFullscreen?.()) : goFull()) } : null; // Help and Tutorial: placeholders for now. - // A newer build out? A notice offers to update; More → Update does it now. + // A newer build out? More pulses and its Update item says NEW. this.updates = new Updates(() => this.store.flush()); moreItem("m-update", () => void this.confirmReset()); // Phones and tablets: an offer to add the app to the home screen (More → Install app too). @@ -1092,6 +1079,9 @@ export class App implements AppContext { } /** File → Open: the projects kept on this device, and Open file… for any other. */ + /** Full screen from the projects window (null: not offered here). */ + private fullscreen: { isFull(): boolean; toggle(): void } | null = null; + private async showProjects(welcome = false): Promise { // The open one with its picture as it looks now. if (this.projectId) await this.keepInLibrary(JSON.stringify(this.store.doc), true); @@ -1110,7 +1100,7 @@ export class App implements AppContext { else await renameProject(id, name); return name; }, - }, { welcome }); + }, { welcome, fullscreen: this.fullscreen }); } private async openKept(id: string): Promise { diff --git a/src/ui/help.ts b/src/ui/help.ts index 7598072..c1d493c 100644 --- a/src/ui/help.ts +++ b/src/ui/help.ts @@ -26,7 +26,7 @@ const SECTIONS: { title: string; intro?: string; items: Entry[] }[] = [ items: [ { icon: "file", name: "File", text: "New, open and save projects (.super). Every project you work on is kept on this device: Open shows them as pictures - tap one to carry on, or Open file… for any .super file (each copy can be saved as a file or deleted there). New keeps the open one. Clearing the site's data in the browser deletes them, so save the ones that matter as files too. Export STL or 3MF for 3D printing, STEP for other CAD programs, DXF of a sketch (tap it in Items first) for laser cutters and CNC. The share mark next to each sends the file straight to another app (phones and tablets)." }, { icon: "body", name: "Items", text: "Every body, sketch, plane and image, with an eye to hide or show it. Each kind (Bodies, Sketches, Planes & axes, Images) folds away under its heading; a plane's icon shows how it was made. Group things into folders (Select, tick them, New folder); tick items all in one folder for New subfolder inside it. Remove takes ticked items out of their folder (one level up); Move, then tick a folder or subfolder, puts them in it. A tool waiting for a body takes one tapped here. What is selected in the view (a body double-clicked, a plane) lights up in the list." }, - { icon: "more", name: "More", text: "Fullscreen, Update (loads the newest version - when one is out and its notice was put away, More pulses and this item shows a pulsing NEW), this Help, About, and support links." }, + { icon: "more", name: "More", text: "Fullscreen (also in the window the app opens with), Update (loads the newest version - when one is out, More pulses and this item shows a pulsing NEW), this Help, About, and support links." }, ], }, { diff --git a/src/ui/library.ts b/src/ui/library.ts index e4de014..1e18724 100644 --- a/src/ui/library.ts +++ b/src/ui/library.ts @@ -76,7 +76,19 @@ function supportBox(): HTMLElement { return box; } -export function showLibrary(entries: LibraryEntry[], currentId: string | null, act: LibraryActions, opts: { welcome?: boolean } = {}): void { +const FULL = + ''; +const UNFULL = + ''; + +export interface LibraryOptions { + /** The app's opening: a welcome and a few words on it. */ + welcome?: boolean; + /** A Full screen button (null: not offered). */ + fullscreen?: { isFull(): boolean; toggle(): void } | null; +} + +export function showLibrary(entries: LibraryEntry[], currentId: string | null, act: LibraryActions, opts: LibraryOptions = {}): void { const back = el("div", "dialog-back"); const box = el("div", "dialog library"); if (opts.welcome) box.classList.add("welcome"); @@ -92,6 +104,23 @@ export function showLibrary(entries: LibraryEntry[], currentId: string | null, a closeBtn.type = "button"; closeBtn.title = "Close"; closeBtn.innerHTML = icons.close; + // Full screen: the window stays (pick a project next); the button follows the state. + let fsBtn: HTMLButtonElement | null = null; + const fs = opts.fullscreen; + const paintFull = () => { + if (!fsBtn || !fs) return; + const on = fs.isFull(); + fsBtn.innerHTML = on ? UNFULL : FULL; + fsBtn.append(on ? "Exit full screen" : "Full screen"); + }; + if (fs) { + fsBtn = el("button", "text-btn library-full"); + fsBtn.type = "button"; + fsBtn.title = "Use the whole screen"; + fsBtn.addEventListener("click", () => fs.toggle()); + paintFull(); + head.append(fsBtn); + } head.append(newBtn, fileBtn, closeBtn); box.append(head); if (opts.welcome) { @@ -109,7 +138,11 @@ export function showLibrary(entries: LibraryEntry[], currentId: string | null, a const close = () => { back.remove(); window.removeEventListener("keydown", onKey, true); + document.removeEventListener("fullscreenchange", paintFull); + document.removeEventListener("webkitfullscreenchange", paintFull); }; + document.addEventListener("fullscreenchange", paintFull); + document.addEventListener("webkitfullscreenchange", paintFull); const onKey = (e: KeyboardEvent) => { // A question asked over it (Delete?) has the keys. if (back.nextElementSibling?.classList.contains("dialog-back")) return; diff --git a/src/ui/update.ts b/src/ui/update.ts index adc37d5..a65d28d 100644 --- a/src/ui/update.ts +++ b/src/ui/update.ts @@ -1,5 +1,6 @@ // Newer version available? The page checks the site now and then (and when -// you come back to it); if a new build is out, a notice offers to update. +// you come back to it); if a new build is out, More pulses and its Update +// item carries a NEW badge - no notice over the work. // Updating - or More → Update - clears the browser's stored copies of // the app's files and reloads. Your project is saved first and stays. @@ -22,31 +23,8 @@ async function liveBuild(): Promise { } export class Updates { - private banner = el("div", "update-banner compact-banner"); - private shownFor: string | null = null; - /** `beforeReload` saves the project before the page is reloaded. */ constructor(private beforeReload: () => Promise) { - this.banner.hidden = true; - const text = el("span", "", "Update available"); - const now = el("button", "text-btn primary", "Update"); - now.addEventListener("click", () => void this.reset()); - this.banner.append(text, now); - this.banner.addEventListener("pointerdown", (e) => e.stopPropagation()); - document.body.append(this.banner); - // No "Later": a click or tap on the workspace puts it away (More → Update - // is always there). - // Put away with an update still waiting: More pulses, and its Update item - // carries a pulsing NEW, until it's done. - document.getElementById("view")?.addEventListener( - "pointerdown", - () => { - if (this.banner.hidden) return; - this.banner.hidden = true; - this.markPending(); - }, - { capture: true }, - ); // Only a built site has a build to compare (not the dev server). if (!loadedBuild()) return; setTimeout(() => void this.check(), 20_000); @@ -61,15 +39,12 @@ export class Updates { if (item && !item.querySelector(".new-badge")) item.append(el("span", "new-badge", "NEW")); } - /** Is a newer build out? Shows the notice (once per build). Returns whether it is. */ + /** Is a newer build out? Marks More if so. Returns whether it is. */ async check(): Promise { const mine = loadedBuild(); const live = await liveBuild(); if (!mine || !live || live === mine) return false; - if (this.shownFor !== live) { - this.shownFor = live; - this.banner.hidden = false; - } + this.markPending(); return true; } @@ -78,7 +53,6 @@ export class Updates { * workers) and reload from the site. The project is saved first. */ async reset(): Promise { - this.banner.hidden = true; await this.beforeReload(); try { if ("caches" in window) for (const k of await caches.keys()) await caches.delete(k);