Three of plan 016's four blockers. Each is a different reason the app could not work at all on a phone. **It had no permission to read anything.** The generated manifest asked for INTERNET, VIBRATE, biometrics, location and a camera, and nothing whatever about storage -- so at targetSdk 35 the app could see its own private directory and no music. It now declares READ_MEDIA_AUDIO, the two capped legacy storage permissions, and MANAGE_EXTERNAL_STORAGE. That last one is deliberate and is the load-bearing choice. This app is a library manager: audio_files.file_path is the primary key of ownership, the scanner walks a directory the user chose, and tagwriter rewrites files in place. MediaStore offers no stable directory to walk and no in-place write, so scoped storage is not "more work" here, it is a different application. MANAGE_EXTERNAL_STORAGE is Play-restricted, which is acceptable only because this ships as an APK through the package registry -- if it ever targets Play, that line is what has to go, and plan 016 says what replaces it. It is granted on a Settings screen rather than in a dialog, so it cannot be requested with requestPermissions(). MainActivity opens that screen on every cold start until access exists -- there is no degraded mode worth offering -- and re-checks in onResume, because the way back from another task is a resume, emitting android:storageAccess so the frontend can react. **The first-run flow could not complete.** All three call sites asked for a folder through the Wails dialog, which returns an error on Android: SAF yields tree URIs and this app is keyed on paths. So the app browses the filesystem itself, which it can now do. ListDirectories lists directories only (the thing being chosen is a library root), skips what it cannot stat rather than failing the listing (Android's storage root holds directories no app may enter), follows symlinks (os.DirEntry reports the link, so a symlinked music folder would silently vanish), and hides dotted entries. utils/pick-directory.ts is the one place that chooses between the two, so the three call sites changed by one line each. **Which platform is asked of the backend**, not of System.IsAndroid(): the dialog is backend code, so the backend is what knows whether it can open one; it answers for iOS at the same time; and it keeps the fallback testable through the ordinary transport fake rather than a module mock of the Wails runtime, whose platform helpers read build constants. **And MPRIS was compiled into the Android build**, because android implies the linux build tag, so it went looking for a session bus that does not exist. mpris_linux.go is `linux && !android` now and the stub covers Android, which means no lock-screen transport there yet -- a missing feature rather than a broken one, and the remaining blocker. The foreground service is typed mediaPlayback rather than the scaffold's dataSync, with the matching permission, so playback can survive the screen locking once there is a MediaSession to drive it. The type in the manifest and the one passed to startForeground must agree or startForeground throws.
88 lines
2.8 KiB
TypeScript
88 lines
2.8 KiB
TypeScript
/**
|
|
* "Ask the user for a folder", once.
|
|
*
|
|
* Three call sites want a directory — the first-run wizard, the library
|
|
* settings and the download clients' save path — and on desktop all
|
|
* three can use the platform's own dialog. On Android that dialog
|
|
* *returns an error*: the Storage Access Framework yields tree URIs
|
|
* rather than filesystem paths, and a path is what this app's library
|
|
* model is keyed on.
|
|
*
|
|
* So the platform test lives here rather than at each call site, which
|
|
* is the same rule `utils/binding.ts` and `utils/library-status.ts`
|
|
* follow: a fact about the platform is stated once, at the boundary.
|
|
*
|
|
* *Which* platform is asked of the backend, not of the Wails runtime's
|
|
* `System.IsAndroid()`. The dialog is backend code, so the backend is
|
|
* what knows whether it can open one; it answers for iOS at the same
|
|
* time; and it keeps this testable through the ordinary transport fake
|
|
* rather than a module mock.
|
|
*
|
|
* Returns the chosen path, or `null` if the user cancelled. Callers
|
|
* treat those the same way they always did — a falsy result means "no
|
|
* change" — so adopting this is a one-line edit at each site.
|
|
*/
|
|
import {
|
|
DirectoryPicker,
|
|
HasNativeDirectoryPicker,
|
|
} from "@go/frontendutil/frontendutil.js";
|
|
|
|
import type { FolderPicker } from "../components/folder-picker/folder-picker";
|
|
|
|
let picker: FolderPicker | null = null;
|
|
let native: Promise<boolean> | null = null;
|
|
|
|
/**
|
|
* Asked once per session and remembered: it cannot change while the app
|
|
* is running, and a folder picker should not pay a round trip to find
|
|
* out which kind it is.
|
|
*/
|
|
function hasNative(): Promise<boolean> {
|
|
native ??= HasNativeDirectoryPicker().catch(() => true);
|
|
|
|
return native;
|
|
}
|
|
|
|
/** Testing seam: forget the cached platform answer. */
|
|
export function resetDirectoryPickerCache(): void {
|
|
native = null;
|
|
picker = null;
|
|
}
|
|
|
|
/**
|
|
* The in-app browser is mounted on first use and then kept.
|
|
*
|
|
* Mounting it on demand and awaiting its module in the same update as
|
|
* `showModal()` is the trap `index.ts` documents for views — so the
|
|
* element is created, appended and *then* asked to open, on separate
|
|
* turns.
|
|
*/
|
|
async function inAppPicker(): Promise<FolderPicker> {
|
|
if (picker) return picker;
|
|
|
|
await import("../components/folder-picker/folder-picker");
|
|
|
|
const el = document.createElement("folder-picker");
|
|
|
|
document.body.appendChild(el);
|
|
picker = el;
|
|
|
|
return el;
|
|
}
|
|
|
|
/** Ask for a directory. Resolves to an absolute path, or null. */
|
|
export async function pickDirectory(startAt?: string): Promise<string | null> {
|
|
if (!(await hasNative())) {
|
|
const el = await inAppPicker();
|
|
|
|
return el.choose(startAt);
|
|
}
|
|
|
|
// The desktop dialog returns '' when dismissed; normalise that to
|
|
// null so every caller has one falsy case to handle rather than
|
|
// two.
|
|
const chosen = await DirectoryPicker();
|
|
|
|
return chosen === "" ? null : chosen;
|
|
}
|