forked from Blendman974/faceclaw
Autoconnect on reaching main screen; play sound effect on first launch
This commit is contained in:
1 parent
ea80d05607
commit
d97429a21a
5 files changed
+91
No files matched your search
@@ -95,6 +95,9 @@ export function loaded(args: EventData) {
|
||||
dashboardController.refreshEvenAppStatus()
|
||||
|
||||
const model = page.bindingContext as MainViewModel | null
|
||||
// Automatically connect on reaching the main page (no-op if already
|
||||
// connected or if no glasses are configured).
|
||||
void model?.autoConnect()
|
||||
const scrollViews = [
|
||||
page.getViewById<ScrollView>('logScrollView'),
|
||||
page.getViewById<ScrollView>('logScrollViewLandscape'),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Application, Frame, ImageSource, Observable, Screen } from "@nativescript/core";
|
||||
import { dashboardController } from "../g2/dashboard-controller";
|
||||
import { isValidMacAddress, loadDeviceAddresses } from "../g2/device-addresses";
|
||||
|
||||
type LayoutOrientation = "portrait" | "landscape";
|
||||
|
||||
@@ -327,6 +328,22 @@ export class MainViewModel extends Observable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to connect automatically on reaching the main page. No-op if already
|
||||
* connecting/connected, or if no glasses are configured (e.g. preview-only
|
||||
* users, who have nothing to connect to).
|
||||
*/
|
||||
async autoConnect(): Promise<void> {
|
||||
if (this.phase !== "disconnected") return;
|
||||
const addresses = loadDeviceAddresses();
|
||||
if (!isValidMacAddress(addresses.right) || !isValidMacAddress(addresses.left)) return;
|
||||
try {
|
||||
await dashboardController.connect();
|
||||
} catch {
|
||||
// The controller surfaces failures via status/log; nothing to add here.
|
||||
}
|
||||
}
|
||||
|
||||
onConfigureTap(): void {
|
||||
if (!this.canRun) return;
|
||||
Frame.topmost()?.navigate("phone-ui/config-page");
|
||||
|
||||
@@ -2,13 +2,32 @@ import { ApplicationSettings } from "@nativescript/core";
|
||||
|
||||
const ONBOARDING_COMPLETE_KEY = "onboarding.complete";
|
||||
const PREVIEW_ONLY_KEY = "onboarding.previewOnly";
|
||||
const WELCOME_SOUND_PENDING_KEY = "onboarding.welcomeSoundPending";
|
||||
|
||||
export function hasCompletedOnboarding(): boolean {
|
||||
return ApplicationSettings.getBoolean(ONBOARDING_COMPLETE_KEY, false);
|
||||
}
|
||||
|
||||
export function setOnboardingCompleted(completed: boolean): void {
|
||||
const wasCompleted = hasCompletedOnboarding();
|
||||
ApplicationSettings.setBoolean(ONBOARDING_COMPLETE_KEY, completed);
|
||||
// Arm the one-time welcome sound on the first-ever completion (not on the
|
||||
// idempotent re-completions that happen when installing from the main menu).
|
||||
if (completed && !wasCompleted) {
|
||||
setWelcomeSoundPending(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* True when onboarding just completed and the celebratory sound hasn't played
|
||||
* yet. Consumed (and cleared) on the first successful glasses connection.
|
||||
*/
|
||||
export function isWelcomeSoundPending(): boolean {
|
||||
return ApplicationSettings.getBoolean(WELCOME_SOUND_PENDING_KEY, false);
|
||||
}
|
||||
|
||||
export function setWelcomeSoundPending(pending: boolean): void {
|
||||
ApplicationSettings.setBoolean(WELCOME_SOUND_PENDING_KEY, pending);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user