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.
289 lines
8.3 KiB
TypeScript
289 lines
8.3 KiB
TypeScript
import { LitElement, html, css, nothing } from 'lit';
|
|
import { customElement, state, query } from 'lit/decorators.js';
|
|
import '@awesome.me/webawesome/dist/components/dialog/dialog.js';
|
|
import '@awesome.me/webawesome/dist/components/icon/icon.js';
|
|
import {
|
|
AddLibrary,
|
|
GetAllLibrariesWithTrackCounts,
|
|
} from '@go/library/library.js';
|
|
import { describeError, explainError } from '@utils/describe-error';
|
|
import { nameDialogsIn } from '@utils/name-dialog';
|
|
import { pickDirectory } from '../../utils/pick-directory';
|
|
|
|
/**
|
|
* First-run setup wizard.
|
|
*
|
|
* On startup it checks whether any library has already been registered.
|
|
* If one exists the wizard stays hidden and the app proceeds as normal.
|
|
* If there are none (fresh install), it presents a non-dismissable modal
|
|
* prompting the user to pick their music folder, registers it through the
|
|
* library CRUD API, and dismisses itself. AddLibrary emits LibraryAdded
|
|
* and kicks off the initial scan automatically.
|
|
*/
|
|
@customElement('first-run-wizard')
|
|
export class FirstRunWizard extends LitElement {
|
|
@query('wa-dialog')
|
|
private dialog!: HTMLElement & { open: boolean };
|
|
|
|
/** Whether the wizard should be shown at all (no library configured). */
|
|
@state() private active = false;
|
|
|
|
/** Directory chosen in the picker, not yet saved. */
|
|
@state() private selectedDirectory = '';
|
|
|
|
/** True while SetLibraryDirectory is in flight. */
|
|
@state() private saving = false;
|
|
|
|
/** Error message from a failed pick/save, if any. */
|
|
@state() private errorMessage = '';
|
|
|
|
override async connectedCallback(): Promise<void> {
|
|
super.connectedCallback();
|
|
|
|
try {
|
|
const existing = await GetAllLibrariesWithTrackCounts();
|
|
|
|
// An existing library means setup is already complete.
|
|
if (existing && existing.length > 0) return;
|
|
} catch (err) {
|
|
console.error(
|
|
'First-run wizard: failed to read libraries:',
|
|
err,
|
|
);
|
|
|
|
return;
|
|
}
|
|
|
|
this.active = true;
|
|
|
|
await this.updateComplete;
|
|
|
|
if (this.dialog) this.dialog.open = true;
|
|
}
|
|
|
|
static override styles = css`
|
|
wa-dialog {
|
|
--width: 480px;
|
|
}
|
|
|
|
wa-dialog::part(dialog) {
|
|
background: var(--yj-bg-surface, #212529);
|
|
color: var(--yj-text-primary, #fff);
|
|
border: 1px solid var(--yj-border, #444);
|
|
border-radius: 8px;
|
|
}
|
|
|
|
wa-dialog::part(body) {
|
|
padding: 24px;
|
|
}
|
|
|
|
.welcome {
|
|
text-align: center;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.welcome wa-icon {
|
|
font-size: 40px;
|
|
color: var(--yj-accent-text, #f5c518);
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.welcome h2 {
|
|
margin: 0 0 4px;
|
|
font-size: 20px;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.welcome p {
|
|
margin: 0;
|
|
font-size: 13px;
|
|
color: var(--yj-text-secondary, #b3b3b3);
|
|
}
|
|
|
|
.chosen {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
padding: 10px 12px;
|
|
margin-bottom: 16px;
|
|
font-size: 13px;
|
|
background: var(--yj-bg-elevated, #2a2f34);
|
|
border: 1px solid var(--yj-border, #444);
|
|
border-radius: 6px;
|
|
word-break: break-all;
|
|
}
|
|
|
|
.chosen wa-icon {
|
|
color: var(--yj-accent-text, #f5c518);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.placeholder {
|
|
color: var(--yj-text-tertiary, #888);
|
|
}
|
|
|
|
.error {
|
|
font-size: 13px;
|
|
color: var(--yj-danger, #e5484d);
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.actions {
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
gap: 8px;
|
|
}
|
|
|
|
.btn {
|
|
padding: 8px 16px;
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
border: 1px solid var(--yj-border, #444);
|
|
border-radius: 6px;
|
|
background: transparent;
|
|
color: var(--yj-text-primary, #fff);
|
|
cursor: pointer;
|
|
}
|
|
|
|
.btn:hover:not(:disabled) {
|
|
background: var(--yj-bg-elevated, #2a2f34);
|
|
}
|
|
|
|
.btn-primary {
|
|
background: var(--yj-accent, #f5c518);
|
|
border-color: var(--yj-accent, #f5c518);
|
|
color: var(--yj-accent-fg, #000);
|
|
}
|
|
|
|
.btn-primary:hover:not(:disabled) {
|
|
filter: brightness(1.08);
|
|
}
|
|
|
|
.btn:disabled {
|
|
opacity: 0.5;
|
|
cursor: not-allowed;
|
|
}
|
|
`;
|
|
|
|
/**
|
|
* Web Awesome renders `label` into a heading it never points the
|
|
* `<dialog>` at, so the dialog has no accessible name until
|
|
* something sets one. See `utils/name-dialog.ts`.
|
|
*/
|
|
override updated() {
|
|
nameDialogsIn(this.shadowRoot);
|
|
}
|
|
|
|
override render() {
|
|
if (!this.active) return nothing;
|
|
|
|
return html`
|
|
<wa-dialog
|
|
label="Welcome to YellowJacket"
|
|
without-header
|
|
@wa-hide=${this.preventClose}
|
|
>
|
|
<div class="welcome">
|
|
<wa-icon name="music"></wa-icon>
|
|
<h2>Welcome to YellowJacket</h2>
|
|
<p>
|
|
Choose the folder where your music lives to
|
|
get started.
|
|
</p>
|
|
</div>
|
|
|
|
<div class="chosen">
|
|
<wa-icon name="folder"></wa-icon>
|
|
${this.selectedDirectory
|
|
? html`<span>${this.selectedDirectory}</span>`
|
|
: html`<span class="placeholder"
|
|
>No folder selected yet</span
|
|
>`}
|
|
</div>
|
|
|
|
${this.errorMessage
|
|
? html`<div class="error">${this.errorMessage}</div>`
|
|
: nothing}
|
|
|
|
<div class="actions">
|
|
<button
|
|
class="btn"
|
|
?disabled=${this.saving}
|
|
@click=${this.handleChoose}
|
|
>
|
|
${this.selectedDirectory
|
|
? 'Change Folder'
|
|
: 'Choose Folder'}
|
|
</button>
|
|
<button
|
|
class="btn btn-primary"
|
|
?disabled=${!this.selectedDirectory || this.saving}
|
|
@click=${this.handleFinish}
|
|
>
|
|
${this.saving ? 'Saving…' : 'Get Started'}
|
|
</button>
|
|
</div>
|
|
</wa-dialog>
|
|
`;
|
|
}
|
|
|
|
/** Set once setup is finished so we allow the dialog to close. */
|
|
private finished = false;
|
|
|
|
/**
|
|
* Block every close attempt (Escape, programmatic, backdrop) until
|
|
* setup is finished, so the user can't skip picking a folder.
|
|
* wa-hide is cancelable via preventDefault().
|
|
*/
|
|
private preventClose = (e: Event): void => {
|
|
if (!this.finished) e.preventDefault();
|
|
};
|
|
|
|
private handleChoose = async (): Promise<void> => {
|
|
this.errorMessage = '';
|
|
|
|
try {
|
|
const dir = await pickDirectory();
|
|
|
|
if (dir) this.selectedDirectory = dir;
|
|
} catch (err) {
|
|
this.errorMessage = describeError(
|
|
err,
|
|
'The folder picker could not be opened.',
|
|
);
|
|
console.error('First-run wizard: directory picker failed:', err);
|
|
}
|
|
};
|
|
|
|
private handleFinish = async (): Promise<void> => {
|
|
if (!this.selectedDirectory) return;
|
|
|
|
this.saving = true;
|
|
this.errorMessage = '';
|
|
|
|
try {
|
|
await AddLibrary(this.selectedDirectory);
|
|
|
|
this.finished = true;
|
|
|
|
if (this.dialog) this.dialog.open = false;
|
|
|
|
this.active = false;
|
|
} catch (err) {
|
|
this.errorMessage = explainError(
|
|
err,
|
|
'That folder could not be added.',
|
|
);
|
|
console.error('First-run wizard: add library failed:', err);
|
|
} finally {
|
|
this.saving = false;
|
|
}
|
|
};
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'first-run-wizard': FirstRunWizard;
|
|
}
|
|
}
|