feat(android): scaffold Capacitor 8 native project + hardware Back button
Add @capacitor/{core,android,app,cli,assets} to ui/, a capacitor.config.ts (appId ru.eruditgame.app, appName Эрудит, webDir dist — bundle model, no server.url), and the generated ui/android/ Gradle project (tracked; build outputs and the machine-specific local.properties gitignored, keystore patterns un-commented so signing material can never be committed). Wire the Android hardware Back button in ui/src/lib/native.ts behind a dynamic @capacitor/app import (web/mock bundles never load it), called from App.svelte onMount and reusing routeDepth for the navigation-root check. Whitelist sharp in pnpm-workspace.yaml for @capacitor/assets icon generation.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// Native shell integration for the Capacitor Android/iOS builds. Kept in its own
|
||||
// module behind a dynamic import so the web / Telegram / VK / mock bundles never load
|
||||
// @capacitor/app: initNativeShell early-returns off the native channels, so the import
|
||||
// statement is only ever reached inside the packaged native app.
|
||||
|
||||
import { clientChannel } from './channel';
|
||||
|
||||
/**
|
||||
* initNativeShell wires native-shell behaviour that only applies inside the packaged
|
||||
* Capacitor app. Currently it binds the Android hardware Back button: at the navigation
|
||||
* root it exits the app, otherwise it steps the in-app (hash) history back. It is a
|
||||
* no-op on the web/Telegram/VK channels and never loads @capacitor/app there.
|
||||
*
|
||||
* atNavigationRoot reports whether the current route is a navigation root (the lobby or
|
||||
* login screen) — mirror App.svelte's routeDepth(...) === 0.
|
||||
*/
|
||||
export async function initNativeShell(atNavigationRoot: () => boolean): Promise<void> {
|
||||
const ch = clientChannel();
|
||||
if (ch !== 'android' && ch !== 'ios') return;
|
||||
const { App } = await import('@capacitor/app');
|
||||
App.addListener('backButton', () => {
|
||||
if (atNavigationRoot()) void App.exitApp();
|
||||
else history.back();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user