Repository navigation
Windows: paths, fetch of the app's files, storage, navigator #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,12 +8,17 @@ | |
| * The file is $BLOOM_STORAGE, else config's storageFile, else | ||
| * `<storageName>` in the app's folder: ~/.config/<app>/ (or | ||
| * $XDG_CONFIG_HOME/<app>/) on a desktop and Apple TV, Library/Application | ||
| * Support/<app>/ in an iOS app's container. | ||
| * Support/<app>/ in an iOS app's container, %APPDATA%\<app>\ on Windows. | ||
| */ | ||
| import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; | ||
| import { config } from "./config.ts"; | ||
| import { MOBILE, frameCount, onAfterFrame, onQuit } from "./frame.ts"; | ||
|
|
||
| /** The folder a file is in, for "/" and Windows' "\" alike. */ | ||
| export function parentDir(path: string): string { | ||
| return path.slice(0, Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"))); | ||
| } | ||
|
|
||
| /** `~/...` -> $HOME/... (on iOS HOME is the app's container). */ | ||
| export function expandHome(path: string): string { | ||
| return path.startsWith("~/") ? (process.env["HOME"] ?? ".") + path.slice(1) : path; | ||
|
|
@@ -26,6 +31,11 @@ export function storagePath(): string { | |
| const c = config(); | ||
| if (c.storageFile !== "") return expandHome(c.storageFile); | ||
| if (MOBILE) return (env["HOME"] ?? ".") + "/Library/Application Support/" + c.app + "/" + c.storageName; | ||
| // Windows: %APPDATA%\<app> (HOME is only set under a Unix-style shell there) | ||
| if (process.platform === "win32") { | ||
| const appData = env["APPDATA"] ?? env["USERPROFILE"]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fall back to If Select the first nonempty value. Keep nonempty
|
||
| if (appData !== undefined && appData !== "") return appData.replace(/\\/g, "/") + "/" + c.app + "/" + c.storageName; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep existing Windows saves loadable after the storage default changes. On Windows, The affected case is limited to Windows processes that have Windows users with a save at the previous default must keep access to it, or the change must state the move. The implementation chooses how: for example, load the legacy file when the new file is absent. Scope of the change
|
||
| } | ||
| const xdg = env["XDG_CONFIG_HOME"]; | ||
| return (xdg !== undefined && xdg !== "" ? xdg : (env["HOME"] ?? ".") + "/.config") + "/" + c.app + "/" + c.storageName; | ||
| } | ||
|
|
@@ -59,7 +69,7 @@ export function flushStorage(): void { | |
| const now = snapshot(); | ||
| if (now === saved) return; | ||
| try { | ||
| mkdirSync(STORAGE.slice(0, STORAGE.lastIndexOf("/")), { recursive: true }); | ||
| mkdirSync(parentDir(STORAGE), { recursive: true }); | ||
| writeFileSync(STORAGE, now); | ||
| saved = now; | ||
| } catch (err) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decode the configured root URL pathname before it is used as a disk path.
The documented
root: new URL("../", import.meta.url).pathnamerecipe produces a percent-encoded path. For a checkout underC:\Users\Alice Smith\game\,webRoot()cachesC:/Users/Alice%20Smith/game/, andbrowser.tsreads a path that does not exist. The page then fails to load.The configured root must become the decoded native directory before it is cached in
root. Apply this conversion only to a configured URL pathname. Do not add decoding tourlPathToFile, becausesrc/fetch.ts:27already decodes its input. Keep native paths from the environment, the working directory, and the bundle unchanged.The
node:urlfileURLToPathhelper is one way to perform this conversion, but only if the Perry runtime supports it. Confirm that support before using it.