forked from Blendman974/faceclaw
Add calendar app and accelerometer demo
This commit is contained in:
1 parent
3cdc5ba262
commit
ff447d5161
18 files changed
+911
-5
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import { ensureCalendarPermission, hasCalendarPermission } from "../../g2/android-permissions";
|
||||
import { invalidateCalendarCache } from "../../native/calendar";
|
||||
import { CalendarLayer } from "../apps/calendar";
|
||||
import {
|
||||
createInProcessWindow,
|
||||
YieldAtRootLayer,
|
||||
type InProcessAppOptions,
|
||||
type InProcessWindow,
|
||||
} from "./in-process-window";
|
||||
|
||||
export const CALENDAR_WINDOW_ID = "calendar";
|
||||
export const CALENDAR_SURFACE_ID = "window:calendar";
|
||||
|
||||
/**
|
||||
* The Calendar app: a single screen listing upcoming events from the Android
|
||||
* Calendar provider. If calendar permission is missing it shows a prompt and
|
||||
* fires the system permission dialog (on launch and on any tap); once granted
|
||||
* it re-renders with the event list.
|
||||
*/
|
||||
export function createCalendarAppWindow(options: InProcessAppOptions): InProcessWindow {
|
||||
let requesting = false;
|
||||
let app: InProcessWindow;
|
||||
|
||||
const requestPermission = () => {
|
||||
if (requesting || hasCalendarPermission()) return;
|
||||
requesting = true;
|
||||
void ensureCalendarPermission().then((granted) => {
|
||||
requesting = false;
|
||||
if (granted) {
|
||||
invalidateCalendarCache();
|
||||
app.requestRender();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
app = createInProcessWindow({
|
||||
appId: "calendar",
|
||||
windowId: CALENDAR_WINDOW_ID,
|
||||
title: "Calendar",
|
||||
iconLetter: "Ca",
|
||||
icon: "calendar",
|
||||
closeable: true,
|
||||
actions: options.actions,
|
||||
baseLayer: new YieldAtRootLayer(new CalendarLayer(requestPermission)),
|
||||
submitFrame: options.submitFrame,
|
||||
setSurfaceVisible: options.setSurfaceVisible,
|
||||
removeSurface: options.removeSurface,
|
||||
onClosed: options.onClosed,
|
||||
});
|
||||
|
||||
// Prompt immediately on launch so the user doesn't have to discover the tap.
|
||||
requestPermission();
|
||||
return app;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { MenuLayer } from "../menu";
|
||||
import { ScreenTestLayer } from "../apps/screen-test";
|
||||
import { BuzzerDemoLayer } from "../apps/buzzer-demo";
|
||||
import { AccelerometerDemoLayer } from "../apps/accelerometer-demo";
|
||||
import { APP_VIEWPORT } from "./geometry";
|
||||
import {
|
||||
createInProcessWindow,
|
||||
@@ -29,6 +30,12 @@ export function createDebugTestsAppWindow(options: InProcessAppOptions): InProce
|
||||
ctx.stack.push(new BuzzerDemoLayer());
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Accelerometer demo",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new AccelerometerDemoLayer(DEBUG_TESTS_WINDOW_ID, ctx.actions.requestRender));
|
||||
},
|
||||
},
|
||||
],
|
||||
{
|
||||
x: 8,
|
||||
|
||||
@@ -84,6 +84,9 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
||||
surfaceId: `window:${options.windowId}`,
|
||||
closeable: options.closeable,
|
||||
close: () => {
|
||||
// Fire onRemoved for any pushed layers so they release resources (e.g. a
|
||||
// demo that enabled a hardware stream) even when closed from within.
|
||||
stack.clearToBase();
|
||||
options.onClosed?.();
|
||||
options.removeSurface?.();
|
||||
},
|
||||
|
||||
@@ -367,6 +367,15 @@ class Shell {
|
||||
return this.screenOn && this.focus === "window" && this.foregroundWindow()?.windowId === windowId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a window's content is on screen: it's the foreground window and the
|
||||
* screen is on. Focus-independent — the app viewport stays visible while the
|
||||
* sidebar is focused (the sidebar is just the left strip).
|
||||
*/
|
||||
isWindowVisible(windowId: string): boolean {
|
||||
return this.screenOn && this.foregroundWindow()?.windowId === windowId;
|
||||
}
|
||||
|
||||
private handleSidebarInput(event: DashboardInputEvent): ShellInputOutcome {
|
||||
switch (event.type) {
|
||||
case "double-click":
|
||||
|
||||
Reference in new issue
Block a user