forked from Blendman974/faceclaw
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e6bb8473a
|
No files matched your search
@@ -54,7 +54,8 @@ class FaceclawCalendarProvider private constructor() {
|
|||||||
* boundaries the provider stores them as.
|
* boundaries the provider stores them as.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getUpcomingEventsJson(context: Context?, maxEvents: Int, windowMs: Long): String {
|
@JvmOverloads
|
||||||
|
fun getUpcomingEventsJson(context: Context?, maxEvents: Int, windowMs: Long, selectedCalendarIdsJson: String = "null"): String {
|
||||||
if (context == null || maxEvents <= 0) {
|
if (context == null || maxEvents <= 0) {
|
||||||
return "[]"
|
return "[]"
|
||||||
}
|
}
|
||||||
@@ -73,11 +74,21 @@ class FaceclawCalendarProvider private constructor() {
|
|||||||
val events = ArrayList<Event>()
|
val events = ArrayList<Event>()
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
|
// Filter instances before the cutoff/limit so excluded calendars
|
||||||
|
// cannot crowd out selected calendars, including recurrences.
|
||||||
|
val ids = if (selectedCalendarIdsJson == "null") null else JSONArray(selectedCalendarIdsJson)
|
||||||
|
if (ids != null && ids.length() == 0) return "[]"
|
||||||
|
val args = ids?.let { values -> Array(values.length()) { index ->
|
||||||
|
values.getString(index).also { require(it.matches(Regex("[0-9]+"))) }
|
||||||
|
} }
|
||||||
|
val selection = args?.let {
|
||||||
|
CalendarContract.Instances.CALENDAR_ID + " IN (" + it.joinToString(",") { "?" } + ")"
|
||||||
|
}
|
||||||
cursor = context.contentResolver.query(
|
cursor = context.contentResolver.query(
|
||||||
uri,
|
uri,
|
||||||
PROJECTION,
|
PROJECTION,
|
||||||
null,
|
selection,
|
||||||
null,
|
args,
|
||||||
CalendarContract.Instances.BEGIN + " ASC")
|
CalendarContract.Instances.BEGIN + " ASC")
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
val utc = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
|
val utc = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
|
||||||
@@ -118,6 +129,33 @@ class FaceclawCalendarProvider private constructor() {
|
|||||||
return out.toString()
|
return out.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun getCalendarsJson(context: Context?): String {
|
||||||
|
if (context == null) return "[]"
|
||||||
|
val out = JSONArray()
|
||||||
|
try {
|
||||||
|
context.contentResolver.query(
|
||||||
|
CalendarContract.Calendars.CONTENT_URI,
|
||||||
|
arrayOf(CalendarContract.Calendars._ID, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,
|
||||||
|
CalendarContract.Calendars.ACCOUNT_NAME, CalendarContract.Calendars.ACCOUNT_TYPE),
|
||||||
|
null, null, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME + " ASC",
|
||||||
|
)?.use { cursor ->
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
out.put(JSONObject().apply {
|
||||||
|
put("id", cursor.getLong(0).toString())
|
||||||
|
put("name", cursor.getString(1) ?: "")
|
||||||
|
put("accountName", cursor.getString(2) ?: "")
|
||||||
|
put("accountType", cursor.getString(3) ?: "")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
Log.w(TAG, "failed to read calendars", t)
|
||||||
|
return "[]"
|
||||||
|
}
|
||||||
|
return out.toString()
|
||||||
|
}
|
||||||
|
|
||||||
private fun readEvent(cursor: Cursor, utc: Calendar, local: Calendar): Event {
|
private fun readEvent(cursor: Cursor, utc: Calendar, local: Calendar): Event {
|
||||||
val allDay = cursor.getInt(4) != 0
|
val allDay = cursor.getInt(4) != 0
|
||||||
var startMs = cursor.getLong(2)
|
var startMs = cursor.getLong(2)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { invalidateCalendarCache, onCalendarChanged } from "../../native/calenda
|
|||||||
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
|
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
|
||||||
import { CalendarLayer } from "./calendar";
|
import { CalendarLayer } from "./calendar";
|
||||||
import { renderCalendarDateIcon } from "./calendar-icon";
|
import { renderCalendarDateIcon } from "./calendar-icon";
|
||||||
|
import { calendarSelectionMenuItems } from "./calendar-filter";
|
||||||
import {
|
import {
|
||||||
createInProcessWindow,
|
createInProcessWindow,
|
||||||
YieldAtRootLayer,
|
YieldAtRootLayer,
|
||||||
@@ -44,6 +45,10 @@ export function createCalendarAppWindow(options: InProcessAppOptions): InProcess
|
|||||||
icon: "calendar",
|
icon: "calendar",
|
||||||
drawIcon: makeImageWindowIcon(renderCalendarDateIcon, windowIcon("calendar", "Ca")),
|
drawIcon: makeImageWindowIcon(renderCalendarDateIcon, windowIcon("calendar", "Ca")),
|
||||||
closeable: true,
|
closeable: true,
|
||||||
|
menuItems: () => calendarSelectionMenuItems().map(item => ({ ...item, onSelect: (ctx, menu) => {
|
||||||
|
ctx.stack.pop();
|
||||||
|
return item.onSelect(ctx, menu);
|
||||||
|
} })),
|
||||||
actions: options.actions,
|
actions: options.actions,
|
||||||
baseLayer: new YieldAtRootLayer(new CalendarLayer(requestPermission)),
|
baseLayer: new YieldAtRootLayer(new CalendarLayer(requestPermission)),
|
||||||
submitFrame: options.submitFrame,
|
submitFrame: options.submitFrame,
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||||
|
import { type GrayImage } from "../../graphics/image";
|
||||||
|
import { truncateText } from "../../graphics/textwrap";
|
||||||
|
import { readCalendarSelection, setCalendarSelection } from "../../native/calendar-selection";
|
||||||
|
import { readAvailableCalendars } from "../../native/calendar-sources";
|
||||||
|
import { hasCalendarPermission } from "../../native/calendar-permissions";
|
||||||
|
import { type InputEvent } from "../../ui/gestures";
|
||||||
|
import { type Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
|
||||||
|
import { drawToggleMenuItem, MenuLayer, type MenuItem } from "../../ui/menu";
|
||||||
|
|
||||||
|
/** Shared preference for every Android calendar reader. */
|
||||||
|
export class CalendarFilterLayer implements Layer {
|
||||||
|
private menu: MenuLayer | null = null;
|
||||||
|
private width = 0;
|
||||||
|
private keys: string[] = [];
|
||||||
|
|
||||||
|
private currentMenu(ctx: LayerContext): MenuLayer {
|
||||||
|
const calendars = readAvailableCalendars().sort((a, b) =>
|
||||||
|
a.name.localeCompare(b.name) || a.accountName.localeCompare(b.accountName) || a.id.localeCompare(b.id));
|
||||||
|
const selection = readCalendarSelection();
|
||||||
|
const known = new Set(calendars.map(calendar => calendar.id));
|
||||||
|
const keys = ["all", "none"];
|
||||||
|
const toggle = (id: string) => {
|
||||||
|
// Leaving all mode snapshots the current calendars. Newly added calendars
|
||||||
|
// then stay excluded until selected individually or all mode is restored.
|
||||||
|
const ids = new Set(readCalendarSelection() ?? calendars.map(calendar => calendar.id));
|
||||||
|
if (ids.has(id)) ids.delete(id); else ids.add(id);
|
||||||
|
setCalendarSelection(Array.from(ids));
|
||||||
|
};
|
||||||
|
const items: MenuItem[] = [{
|
||||||
|
label: "All calendars",
|
||||||
|
description: "Include all calendars, including calendars added later.",
|
||||||
|
onSelect: () => setCalendarSelection(null),
|
||||||
|
render: ({ image, x, y, width, selected }) => drawToggleMenuItem(image, getDefaultSmallFont(), x, y, width,
|
||||||
|
"All calendars", readCalendarSelection() === null, selected),
|
||||||
|
}, {
|
||||||
|
label: "No calendars",
|
||||||
|
onSelect: () => setCalendarSelection([]),
|
||||||
|
render: ({ image, x, y, width, selected }) => drawToggleMenuItem(image, getDefaultSmallFont(), x, y, width,
|
||||||
|
"No calendars", readCalendarSelection()?.length === 0, selected),
|
||||||
|
}];
|
||||||
|
const rows = [
|
||||||
|
...calendars.map(calendar => ({ id: calendar.id,
|
||||||
|
label: `${calendar.name || "(unnamed)"} / ${calendar.accountName || "Local"} (${calendar.accountType || "local"}) #${calendar.id}` })),
|
||||||
|
...(selection ?? []).filter(id => !known.has(id)).map(id => ({ id, label: `Unavailable calendar #${id}` })),
|
||||||
|
];
|
||||||
|
for (const row of rows) {
|
||||||
|
keys.push(`calendar:${row.id}`);
|
||||||
|
items.push({
|
||||||
|
label: row.label,
|
||||||
|
description: row.label,
|
||||||
|
onSelect: () => toggle(row.id),
|
||||||
|
render: ({ image, x, y, width, selected }) => {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
|
const ids = readCalendarSelection();
|
||||||
|
drawToggleMenuItem(image, font, x, y, width, truncateText(font, row.label, width - 48),
|
||||||
|
ids === null || ids.includes(row.id), selected);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!calendars.length) items.push({
|
||||||
|
label: hasCalendarPermission() ? "No calendars available" : "Grant calendar permission on your phone",
|
||||||
|
disabled: true, onSelect: () => {},
|
||||||
|
});
|
||||||
|
const key = this.menu?.selectedIndex != null ? this.keys[this.menu.selectedIndex] : "all";
|
||||||
|
const index = Math.max(0, keys.indexOf(key ?? "all"));
|
||||||
|
this.keys = keys;
|
||||||
|
const width = ctx.stack.getBaseSize().width;
|
||||||
|
if (!this.menu || this.width !== width) {
|
||||||
|
this.width = width;
|
||||||
|
this.menu = new MenuLayer("Calendars displayed", items, {
|
||||||
|
x: 8, y: 8, width: width - 16, opaque: true, showBorder: false,
|
||||||
|
footer: "Shared by Calendar and Glanceboard",
|
||||||
|
}).selectItem(index);
|
||||||
|
} else this.menu.setItems(items, index);
|
||||||
|
return this.menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
|
||||||
|
return this.currentMenu(ctx).paint(ctx, paintBelow);
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||||
|
await this.currentMenu(ctx).handleInput(event, ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function calendarSelectionMenuItems(): MenuItem[] {
|
||||||
|
return global.isAndroid ? [{
|
||||||
|
label: "Calendars displayed",
|
||||||
|
description: "Choose the calendars used by Calendar, Glanceboard and other calendar views.",
|
||||||
|
onSelect: ctx => ctx.stack.push(new CalendarFilterLayer()),
|
||||||
|
}] : [];
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { type GlanceWidgetDefinition, type GlanceWidgetId } from "../widget";
|
import { type GlanceWidgetDefinition, type GlanceWidgetId } from "../widget";
|
||||||
import { CalendarWidget } from "./calendar-widget";
|
import { CalendarWidget } from "./calendar-widget";
|
||||||
|
import { calendarSelectionMenuItems } from "../../calendar/calendar-filter";
|
||||||
import { CompassWidget } from "./compass-widget";
|
import { CompassWidget } from "./compass-widget";
|
||||||
import { MusicWidget, musicSettingsMenuItems } from "./music-widget";
|
import { MusicWidget, musicSettingsMenuItems } from "./music-widget";
|
||||||
import { NightscoutWidget } from "./nightscout-widget";
|
import { NightscoutWidget } from "./nightscout-widget";
|
||||||
@@ -11,7 +12,7 @@ import { HealthWidget } from "./health-widget";
|
|||||||
/** Every widget a board slot can hold. */
|
/** Every widget a board slot can hold. */
|
||||||
export const GLANCE_WIDGETS: readonly GlanceWidgetDefinition[] = [
|
export const GLANCE_WIDGETS: readonly GlanceWidgetDefinition[] = [
|
||||||
{ id: "system-card", label: "System card", settingsMenuItems: systemCardSettingsMenuItems, create: () => new SystemCardWidget() },
|
{ id: "system-card", label: "System card", settingsMenuItems: systemCardSettingsMenuItems, create: () => new SystemCardWidget() },
|
||||||
{ id: "calendar", label: "Calendar", tall: true, create: () => new CalendarWidget() },
|
{ id: "calendar", label: "Calendar", tall: true, settingsMenuItems: calendarSelectionMenuItems, create: () => new CalendarWidget() },
|
||||||
{ id: "terminal", label: "Terminal", tall: true, create: () => new TerminalWidget() },
|
{ id: "terminal", label: "Terminal", tall: true, create: () => new TerminalWidget() },
|
||||||
{ id: "t3code", label: "T3 Code", tall: true, create: () => new T3CodeWidget() },
|
{ id: "t3code", label: "T3 Code", tall: true, create: () => new T3CodeWidget() },
|
||||||
{ id: "nightscout", label: "Nightscout", create: () => new NightscoutWidget() },
|
{ id: "nightscout", label: "Nightscout", create: () => new NightscoutWidget() },
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { getStringSetting, setStringSetting } from "./settings-store";
|
||||||
|
|
||||||
|
export const CALENDAR_SELECTION_KEY = "calendar.selectedIds";
|
||||||
|
/** null means all calendars (including future ones); [] explicitly means none. */
|
||||||
|
export function readCalendarSelection(): string[] | null {
|
||||||
|
try {
|
||||||
|
const value = JSON.parse(getStringSetting(CALENDAR_SELECTION_KEY, "null"));
|
||||||
|
if (value === null) return null;
|
||||||
|
if (!Array.isArray(value) || !value.every(id => typeof id === "string" && /^\d+$/.test(id))) return null;
|
||||||
|
return Array.from(new Set<string>(value));
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setCalendarSelection(ids: readonly string[] | null): void {
|
||||||
|
if (ids !== null && !ids.every(id => /^\d+$/.test(id))) throw new Error("Invalid calendar ID");
|
||||||
|
setStringSetting(CALENDAR_SELECTION_KEY, JSON.stringify(ids === null ? null : Array.from(new Set(ids))));
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { Utils } from "@nativescript/core";
|
||||||
|
import { hasCalendarPermission } from "./calendar-permissions";
|
||||||
|
|
||||||
|
declare const com: any;
|
||||||
|
|
||||||
|
export type CalendarSource = { id: string; name: string; accountName: string; accountType: string };
|
||||||
|
|
||||||
|
/** Android calendar IDs survive renames and distinguish equal display names. */
|
||||||
|
export function readAvailableCalendars(): CalendarSource[] {
|
||||||
|
if (!global.isAndroid || !hasCalendarPermission()) return [];
|
||||||
|
try {
|
||||||
|
const context = Utils.android.getApplicationContext();
|
||||||
|
if (!context) return [];
|
||||||
|
const parsed = JSON.parse(String(com.faceclaw.app.FaceclawCalendarProvider.getCalendarsJson(context)));
|
||||||
|
if (!Array.isArray(parsed)) return [];
|
||||||
|
return parsed.filter(row => row && typeof row.id === "string" && /^\d+$/.test(row.id))
|
||||||
|
.map(row => ({ id: row.id, name: String(row.name ?? ""),
|
||||||
|
accountName: String(row.accountName ?? ""), accountType: String(row.accountType ?? "") }));
|
||||||
|
} catch {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
-3
@@ -2,6 +2,8 @@ import { Utils } from "@nativescript/core";
|
|||||||
import { hasCalendarPermission } from "../g2/android-permissions";
|
import { hasCalendarPermission } from "../g2/android-permissions";
|
||||||
import { spanCurrent } from "./frame-timings";
|
import { spanCurrent } from "./frame-timings";
|
||||||
import { type CalendarEvent, type CalendarReadState } from "./calendar-types";
|
import { type CalendarEvent, type CalendarReadState } from "./calendar-types";
|
||||||
|
import { CALENDAR_SELECTION_KEY, readCalendarSelection } from "./calendar-selection";
|
||||||
|
import { onSettingsStoreChanged } from "./settings-store";
|
||||||
export type { CalendarEvent } from "./calendar-types";
|
export type { CalendarEvent } from "./calendar-types";
|
||||||
|
|
||||||
declare const com: any;
|
declare const com: any;
|
||||||
@@ -13,14 +15,21 @@ declare const com: any;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Android reads synchronously; iOS notifies subscribers after background reads.
|
// Android reads synchronously; iOS notifies subscribers after background reads.
|
||||||
export function onCalendarChanged(_listener: () => void): () => void { return () => {}; }
|
export function onCalendarChanged(listener: () => void): () => void {
|
||||||
|
return onSettingsStoreChanged(key => {
|
||||||
|
if (key === CALENDAR_SELECTION_KEY || key == null) {
|
||||||
|
invalidateCalendarCache();
|
||||||
|
listener();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
export function getCalendarReadState(): CalendarReadState { return "ready"; }
|
export function getCalendarReadState(): CalendarReadState { return "ready"; }
|
||||||
|
|
||||||
const DEFAULT_MAX_EVENTS = 50;
|
const DEFAULT_MAX_EVENTS = 50;
|
||||||
const DEFAULT_WINDOW_MS = 14 * 24 * 60 * 60 * 1000;
|
const DEFAULT_WINDOW_MS = 14 * 24 * 60 * 60 * 1000;
|
||||||
const CACHE_MS = 30_000;
|
const CACHE_MS = 30_000;
|
||||||
|
|
||||||
let cache: { events: CalendarEvent[]; atMs: number; maxEvents: number; windowMs: number } | null = null;
|
let cache: { events: CalendarEvent[]; atMs: number; maxEvents: number; windowMs: number; selection: string } | null = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upcoming events from now through the given window, ordered by start time.
|
* Upcoming events from now through the given window, ordered by start time.
|
||||||
@@ -35,9 +44,11 @@ export function readUpcomingEvents(
|
|||||||
if (!global.isAndroid || !hasCalendarPermission()) return [];
|
if (!global.isAndroid || !hasCalendarPermission()) return [];
|
||||||
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
const selection = JSON.stringify(readCalendarSelection());
|
||||||
if (
|
if (
|
||||||
!forceRefresh &&
|
!forceRefresh &&
|
||||||
cache &&
|
cache &&
|
||||||
|
cache.selection === selection &&
|
||||||
cache.maxEvents === maxEvents &&
|
cache.maxEvents === maxEvents &&
|
||||||
cache.windowMs === windowMs &&
|
cache.windowMs === windowMs &&
|
||||||
now - cache.atMs < CACHE_MS
|
now - cache.atMs < CACHE_MS
|
||||||
@@ -55,6 +66,7 @@ export function readUpcomingEvents(
|
|||||||
context,
|
context,
|
||||||
Math.max(0, Math.round(maxEvents)),
|
Math.max(0, Math.round(maxEvents)),
|
||||||
Math.max(0, Math.round(windowMs)),
|
Math.max(0, Math.round(windowMs)),
|
||||||
|
selection,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -62,7 +74,7 @@ export function readUpcomingEvents(
|
|||||||
const events = Array.isArray(parsed)
|
const events = Array.isArray(parsed)
|
||||||
? parsed.map(normalizeEvent).filter((event): event is CalendarEvent => Boolean(event))
|
? parsed.map(normalizeEvent).filter((event): event is CalendarEvent => Boolean(event))
|
||||||
: [];
|
: [];
|
||||||
cache = { events, atMs: now, maxEvents, windowMs };
|
cache = { events, atMs: now, maxEvents, windowMs, selection };
|
||||||
return events;
|
return events;
|
||||||
} catch {
|
} catch {
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
@@ -601,14 +601,6 @@ export function getBrightnessPreferences() {
|
|||||||
curve: autoBrightnessCurveSetting.getValidValue(), fadeMs: scaleAnimationDuration(SCREEN_FADE_MS, screenFadeSetting.get()) };
|
curve: autoBrightnessCurveSetting.getValidValue(), fadeMs: scaleAnimationDuration(SCREEN_FADE_MS, screenFadeSetting.get()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const swapMenuGesturesSetting = new ConfigSettingBoolean({
|
|
||||||
id: "swap-menu-gestures",
|
|
||||||
label: "Long press for app menu",
|
|
||||||
storageKey: "input.swapMenuGestures",
|
|
||||||
defaultValue: false,
|
|
||||||
description: "Use long press for the app menu and tap then hold for the system menu. Apps using long press for a game action or voice capture keep their gestures. The app switcher keeps its system menu gestures.",
|
|
||||||
});
|
|
||||||
|
|
||||||
export const wakeToLastAppSetting = new ConfigSettingBoolean({
|
export const wakeToLastAppSetting = new ConfigSettingBoolean({
|
||||||
id: "wake-to-last-app",
|
id: "wake-to-last-app",
|
||||||
label: "Wake into last app",
|
label: "Wake into last app",
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ import {
|
|||||||
voiceProviderSetting,
|
voiceProviderSetting,
|
||||||
screenTimeoutSetting,
|
screenTimeoutSetting,
|
||||||
wakeToLastAppSetting,
|
wakeToLastAppSetting,
|
||||||
swapMenuGesturesSetting,
|
|
||||||
wakeWordActionSetting,
|
wakeWordActionSetting,
|
||||||
watchCanUnlockSetting,
|
watchCanUnlockSetting,
|
||||||
watchCrownClockwiseNextSetting,
|
watchCrownClockwiseNextSetting,
|
||||||
@@ -126,7 +125,6 @@ function settingsSections(): SettingsSection[] {
|
|||||||
}),
|
}),
|
||||||
toggleSettingMenuItem(lockScreenEnabledSetting),
|
toggleSettingMenuItem(lockScreenEnabledSetting),
|
||||||
toggleSettingMenuItem(wakeToLastAppSetting),
|
toggleSettingMenuItem(wakeToLastAppSetting),
|
||||||
toggleSettingMenuItem(swapMenuGesturesSetting),
|
|
||||||
// A band (at one of five heights) / Tall / Full Screen; the
|
// A band (at one of five heights) / Tall / Full Screen; the
|
||||||
// dashboard controller moves or reflows windows on change.
|
// dashboard controller moves or reflows windows on change.
|
||||||
enumSettingMenuItem(displayLayoutSetting),
|
enumSettingMenuItem(displayLayoutSetting),
|
||||||
|
|||||||
+6
-17
@@ -9,7 +9,6 @@ import {
|
|||||||
directionalFallback,
|
directionalFallback,
|
||||||
type DirectionalInputEvent,
|
type DirectionalInputEvent,
|
||||||
GESTURE_SHORT_THEN_LONG_PRESS,
|
GESTURE_SHORT_THEN_LONG_PRESS,
|
||||||
GESTURE_LONG_PRESS,
|
|
||||||
gestureHints,
|
gestureHints,
|
||||||
InputEvent,
|
InputEvent,
|
||||||
type InputEventPayload,
|
type InputEventPayload,
|
||||||
@@ -53,7 +52,6 @@ import {
|
|||||||
timeFormatSetting,
|
timeFormatSetting,
|
||||||
wakeWordActionSetting,
|
wakeWordActionSetting,
|
||||||
wakeToLastAppSetting,
|
wakeToLastAppSetting,
|
||||||
swapMenuGesturesSetting,
|
|
||||||
windowBorderSetting,
|
windowBorderSetting,
|
||||||
} from "../dashboard-settings";
|
} from "../dashboard-settings";
|
||||||
import { onAmbientCardsChanged } from "./ambient-cards";
|
import { onAmbientCardsChanged } from "./ambient-cards";
|
||||||
@@ -1063,15 +1061,7 @@ class Shell {
|
|||||||
return { shell: false, window: false };
|
return { shell: false, window: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remap menu intent only. Apps still receive the canonical context-menu
|
// Long-press is the shell's own gesture: it opens the system menu
|
||||||
// event, while owned holds (games / voice) retain their raw input.
|
|
||||||
const menuWindow = this.foregroundWindow();
|
|
||||||
const swapMenus = this.focus === "window" && swapMenuGesturesSetting.get() &&
|
|
||||||
!menuWindow?.holdToTalk && !menuWindow?.claimsLongPress?.();
|
|
||||||
const systemMenuGesture = swapMenus ? "short-then-long-press" : "long-press";
|
|
||||||
const appMenuGesture = swapMenus ? "long-press" : "short-then-long-press";
|
|
||||||
|
|
||||||
// The resolved system gesture opens the shell's own menu
|
|
||||||
// directly, never reaching the app — over the app's own context menu
|
// directly, never reaching the app — over the app's own context menu
|
||||||
// too (the window closes that on system-menu-opened), while an already
|
// too (the window closes that on system-menu-opened), while an already
|
||||||
// open system menu just stays. Its later generic release is consumed
|
// open system menu just stays. Its later generic release is consumed
|
||||||
@@ -1079,7 +1069,7 @@ class Shell {
|
|||||||
// app. The exception is a window that claims long-press for a move of
|
// app. The exception is a window that claims long-press for a move of
|
||||||
// its own: it gets the press forwarded, with the escape timer running
|
// its own: it gets the press forwarded, with the escape timer running
|
||||||
// so that holding the press long enough still opens the system menu.
|
// so that holding the press long enough still opens the system menu.
|
||||||
if (event.type === systemMenuGesture) {
|
if (event.type === "long-press") {
|
||||||
if (this.activeVoiceLayer || !this.stack.isAtBase()) {
|
if (this.activeVoiceLayer || !this.stack.isAtBase()) {
|
||||||
return { shell: true, window: false };
|
return { shell: true, window: false };
|
||||||
}
|
}
|
||||||
@@ -1101,11 +1091,11 @@ class Shell {
|
|||||||
return { shell: true, window: true };
|
return { shell: true, window: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
// The resolved app-menu gesture is delivered as tap-then-hold: it
|
// The 2.2.9 tap-then-hold gesture is the app's context-menu gesture: it
|
||||||
// goes to the foreground window (from the sidebar it focuses the window
|
// goes to the foreground window (from the sidebar it focuses the window
|
||||||
// first), which answers with its own menu or asks for the system menu
|
// first), which answers with its own menu or asks for the system menu
|
||||||
// when it has none.
|
// when it has none.
|
||||||
if (event.type === appMenuGesture) {
|
if (event.type === "short-then-long-press") {
|
||||||
const window = this.foregroundWindow();
|
const window = this.foregroundWindow();
|
||||||
if (window?.holdToTalk) {
|
if (window?.holdToTalk) {
|
||||||
this.openEscapeMenu();
|
this.openEscapeMenu();
|
||||||
@@ -1133,7 +1123,7 @@ class Shell {
|
|||||||
window.onFocus?.(this.lastInput);
|
window.onFocus?.(this.lastInput);
|
||||||
}
|
}
|
||||||
// The window owns frameId from here (render or explicit finish).
|
// The window owns frameId from here (render or explicit finish).
|
||||||
await window.handleInput(swapMenus ? { ...event, type: "short-then-long-press" } : event, frameId);
|
await window.handleInput(event, frameId);
|
||||||
return { shell: true, window: true };
|
return { shell: true, window: true };
|
||||||
}
|
}
|
||||||
if (event.type === "long-press-release") {
|
if (event.type === "long-press-release") {
|
||||||
@@ -1990,8 +1980,7 @@ class Shell {
|
|||||||
// when the app has one (otherwise it opens this very menu, not worth a
|
// when the app has one (otherwise it opens this very menu, not worth a
|
||||||
// hint).
|
// hint).
|
||||||
const footer = foreground.hasAppMenu?.()
|
const footer = foreground.hasAppMenu?.()
|
||||||
? (foreground.holdToTalk ? undefined : gestureHints([[this.focus === "window" && swapMenuGesturesSetting.get() && !foreground.claimsLongPress?.()
|
? (foreground.holdToTalk ? undefined : gestureHints([[GESTURE_SHORT_THEN_LONG_PRESS, "app menu"]]))
|
||||||
? GESTURE_LONG_PRESS : GESTURE_SHORT_THEN_LONG_PRESS, "app menu"]]))
|
|
||||||
: undefined;
|
: undefined;
|
||||||
const layer = new ShellOverlayMenuLayer(items, footer, () => this.yieldFocusToSidebar());
|
const layer = new ShellOverlayMenuLayer(items, footer, () => this.yieldFocusToSidebar());
|
||||||
layer.selectItem(initialSelection);
|
layer.selectItem(initialSelection);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { swapMenuGesturesSetting } from "./dashboard-settings";
|
|
||||||
import { GrayImage } from "../graphics/image";
|
import { GrayImage } from "../graphics/image";
|
||||||
import { singlePlane, type Plane } from "../graphics/plane";
|
import { singlePlane, type Plane } from "../graphics/plane";
|
||||||
import { GESTURE_LONG_PRESS, GESTURE_SHORT_THEN_LONG_PRESS, gestureHints, type InputEvent } from "./gestures";
|
import { GESTURE_LONG_PRESS, GESTURE_SHORT_THEN_LONG_PRESS, gestureHints, type InputEvent } from "./gestures";
|
||||||
@@ -7,9 +6,8 @@ import { CONTEXT_MENU_DIM, MenuLayer, type MenuItem, type MenuLayout } from "./m
|
|||||||
import type { WorkerAppReply } from "./shell/worker-window";
|
import type { WorkerAppReply } from "./shell/worker-window";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The window context menu, opened by tap-then-hold by default: an app's own menu,
|
* The window context menu, opened by tap-then-hold: an app's own menu,
|
||||||
* holding its app-specific actions. The menu gesture preference can swap
|
* holding its app-specific actions. The shell's system menu (long-press)
|
||||||
* these bindings unless the app owns long-press. The shell's system menu
|
|
||||||
* carries the entries every window shares — Focus app switcher, Voice input,
|
* carries the entries every window shares — Focus app switcher, Voice input,
|
||||||
* Close window — so an app with nothing of its own to offer has no menu of
|
* Close window — so an app with nothing of its own to offer has no menu of
|
||||||
* its own: tap-then-hold then opens the system menu in its place, so both
|
* its own: tap-then-hold then opens the system menu in its place, so both
|
||||||
@@ -30,8 +28,8 @@ export const WINDOW_MENU_LAYOUT: MenuLayout = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class WindowMenuLayer extends MenuLayer {
|
export class WindowMenuLayer extends MenuLayer {
|
||||||
constructor(title: string | null, items: MenuItem[], holdToTalk = false, claimsLongPress = false) {
|
constructor(title: string | null, items: MenuItem[], holdToTalk = false) {
|
||||||
super(title, items, (holdToTalk || (swapMenuGesturesSetting.get() && !claimsLongPress))
|
super(title, items, holdToTalk
|
||||||
? { ...WINDOW_MENU_LAYOUT, footer: gestureHints([[GESTURE_SHORT_THEN_LONG_PRESS, "system menu"]]) }
|
? { ...WINDOW_MENU_LAYOUT, footer: gestureHints([[GESTURE_SHORT_THEN_LONG_PRESS, "system menu"]]) }
|
||||||
: WINDOW_MENU_LAYOUT);
|
: WINDOW_MENU_LAYOUT);
|
||||||
}
|
}
|
||||||
@@ -125,7 +123,7 @@ export class WindowMenu {
|
|||||||
handleInput: () => {},
|
handleInput: () => {},
|
||||||
};
|
};
|
||||||
const stack = new LayerStack(base, this.layerActions(), this.options.size, this.options.isFocused);
|
const stack = new LayerStack(base, this.layerActions(), this.options.size, this.options.isFocused);
|
||||||
const layer = new WindowMenuLayer(title, items, false, this.options.claimsLongPress?.() ?? false);
|
const layer = new WindowMenuLayer(title, items);
|
||||||
if (selectedIndex !== undefined) layer.selectItem(selectedIndex);
|
if (selectedIndex !== undefined) layer.selectItem(selectedIndex);
|
||||||
stack.push(layer);
|
stack.push(layer);
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# Android calendar selection validation
|
||||||
|
|
||||||
|
Software: `npm test` and `bash lint.sh` for changed TypeScript files.
|
||||||
|
`tests/calendar-selection.test.cjs` covers preference reloads, all versus none,
|
||||||
|
duplicate names/accounts, selection changes with cached readers, deleted IDs,
|
||||||
|
recurrence occurrences and forwarding the selection to the provider before its
|
||||||
|
limit. Provider SQL structure is checked statically; the mocked bridge does not
|
||||||
|
replace an Android CalendarContract integration test.
|
||||||
|
|
||||||
|
On an Android device (pending):
|
||||||
|
|
||||||
|
1. With no saved preference, compare events with the current release.
|
||||||
|
2. Open Calendar's window menu > Calendars displayed (also available through
|
||||||
|
Glanceboard's Calendar widget settings). Select between two equal-named
|
||||||
|
calendars belonging to different accounts. Check ID/account labels.
|
||||||
|
3. Create more than 50 early events in an excluded calendar and later recurring
|
||||||
|
events in a selected calendar. Check those later occurrences still appear.
|
||||||
|
4. Select “No calendars”: Calendar, Glanceboard and any other readers must be
|
||||||
|
empty immediately. Restart and confirm the selection persists.
|
||||||
|
5. Select individual calendars, rename one, then delete one. Remaining selections
|
||||||
|
must stay unchanged. A missing selected ID is shown as unavailable and may be
|
||||||
|
removed; it never causes a fallback to all calendars.
|
||||||
|
6. Select “All calendars”, add a calendar, and check it is included. In individual
|
||||||
|
mode, newly added calendars stay excluded. Check all-day and timed recurring
|
||||||
|
events in both Calendar and Glanceboard, including timezone/DST boundaries.
|
||||||
|
|
||||||
|
IDs are Android CalendarContract IDs, stable across display-name changes within
|
||||||
|
an installation. Removing/re-adding an account can create new calendar IDs.
|
||||||
|
The iOS calendar reader and its behavior are unchanged; iOS selection is deferred.
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# Configurable menu gestures
|
|
||||||
|
|
||||||
Settings > Display > Long press for app menu is off by default, preserving existing installations. When enabled with an app focused, long press opens its context menu and tap then hold opens the system menu. The preference uses the existing ConfigSettingBoolean/settings store and takes effect on subsequent input without restarting.
|
|
||||||
|
|
||||||
Windows claiming long press retain that input, their existing tap-then-hold app menu and the extended-hold system escape. Hold-to-talk windows retain voice capture and tap-then-hold for the system menu. The app switcher retains its existing bindings. Empty app menus continue to fall back to the system menu. The shell delivers the canonical tap-then-hold context-menu event to apps, so worker and EvenHub input contracts do not change. Menu gesture hints follow the preference and exceptions.
|
|
||||||
|
|
||||||
Software validation: TypeScript and changed-source lint; full JavaScript suite (1072 passed, 2 skipped on the independent branch). Routing tests cover both mappings, overlay switching, input metadata, dynamic hold ownership, switcher behavior and screen-off input. Persistence tests cover default, enabled and disabled values after store reload. App-menu hint tests cover owned holds and voice capture.
|
|
||||||
|
|
||||||
Hardware validation remains pending: test both bindings on the glasses/ring, app-specific holds, voice release, extended-hold escape, switching menus, app switcher, and restart. No firmware was flashed.
|
|
||||||
@@ -266,7 +266,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
|
|||||||
handleInput(event, ctx) { if (event.type === 'double-click') ctx.stack.pop(); }
|
handleInput(event, ctx) { if (event.type === 'double-click') ctx.stack.pop(); }
|
||||||
}
|
}
|
||||||
const voiceDialogs = [];
|
const voiceDialogs = [];
|
||||||
const settings = { swapMenuGesturesSetting: { get: () => false }, wakeWordActionSetting: { get: () => wakeAction }, brightnessSetting: { get: () => 'auto' },
|
const settings = { wakeWordActionSetting: { get: () => wakeAction }, brightnessSetting: { get: () => 'auto' },
|
||||||
assistantSkipConfirmationSetting: { get: () => skipConfirmation } };
|
assistantSkipConfirmationSetting: { get: () => skipConfirmation } };
|
||||||
const { shell, rawInputEventToInputEvent } = load('app/ui/shell/shell.ts', {
|
const { shell, rawInputEventToInputEvent } = load('app/ui/shell/shell.ts', {
|
||||||
'../../graphics/shell-scene': { encodeShellScene: () => new Uint8Array([0, 0]) },
|
'../../graphics/shell-scene': { encodeShellScene: () => new Uint8Array([0, 0]) },
|
||||||
|
|||||||
@@ -59,14 +59,3 @@ test('curve drafts preview exactly while brightness keeps the previous valid sav
|
|||||||
assert.equal(curve.validationError(), null);
|
assert.equal(curve.validationError(), null);
|
||||||
assert.equal(api.getBrightnessPreferences().curve, '0:0,2:50,6:100');
|
assert.equal(api.getBrightnessPreferences().curve, '0:0,2:50,6:100');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('menu gesture preference preserves defaults and survives restart in either state', () => {
|
|
||||||
const store = new Map();
|
|
||||||
let api = settingsFixture(store);
|
|
||||||
assert.equal(api.swapMenuGesturesSetting.get(), false);
|
|
||||||
api.swapMenuGesturesSetting.set(true);
|
|
||||||
api = settingsFixture(store);
|
|
||||||
assert.equal(api.swapMenuGesturesSetting.get(), true);
|
|
||||||
api.swapMenuGesturesSetting.set(false);
|
|
||||||
assert.equal(settingsFixture(store).swapMenuGesturesSetting.get(), false);
|
|
||||||
});
|
|
||||||
@@ -39,7 +39,6 @@ const menu = load('app/ui/menu.ts', {
|
|||||||
function fixture(initial = '50', viewport = { x: 64, y: 124, width: 576, height: 260 }) {
|
function fixture(initial = '50', viewport = { x: 64, y: 124, width: 576, height: 260 }) {
|
||||||
let value = initial, writes = 0, closed = 0;
|
let value = initial, writes = 0, closed = 0;
|
||||||
const settings = {
|
const settings = {
|
||||||
swapMenuGesturesSetting: { get: () => false },
|
|
||||||
brightnessSetting: { get: () => value, set: (next) => { value = next; writes++; } },
|
brightnessSetting: { get: () => value, set: (next) => { value = next; writes++; } },
|
||||||
brightnessSettingToLevel: (value) => value === 'auto' ? null : Number(value),
|
brightnessSettingToLevel: (value) => value === 'auto' ? null : Number(value),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,150 @@
|
|||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
const vm = require('node:vm');
|
||||||
|
const ts = require('typescript');
|
||||||
|
const source = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
|
||||||
|
function load(file, modules, globals = {}) {
|
||||||
|
const context = { exports: {}, require: name => {
|
||||||
|
assert.ok(name in modules, `Unexpected import ${name}`);
|
||||||
|
return modules[name];
|
||||||
|
}, ...globals };
|
||||||
|
vm.runInNewContext(ts.transpileModule(source(file), {
|
||||||
|
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||||
|
}).outputText, context);
|
||||||
|
return context.exports;
|
||||||
|
}
|
||||||
|
function fixture(settings = new Map()) {
|
||||||
|
const listeners = new Set();
|
||||||
|
const storage = {
|
||||||
|
getStringSetting: (key, fallback) => settings.get(key) ?? fallback,
|
||||||
|
setStringSetting: (key, value) => { settings.set(key, value); for (const fn of listeners) fn(key); },
|
||||||
|
onSettingsStoreChanged: fn => { listeners.add(fn); return () => listeners.delete(fn); },
|
||||||
|
};
|
||||||
|
const prefs = load('app/native/calendar-selection.ts', { './settings-store': storage });
|
||||||
|
let permitted = true;
|
||||||
|
const calls = [];
|
||||||
|
const calendars = [
|
||||||
|
{ id: '1', name: 'Work', accountName: 'one@example.com', accountType: 'google' },
|
||||||
|
{ id: '2', name: 'Work', accountName: 'two@example.com', accountType: 'google' },
|
||||||
|
];
|
||||||
|
const events = [
|
||||||
|
{ id: 1, calendarId: '1', startMs: 10000, endMs: 20000, title: 'Excluded early' },
|
||||||
|
{ id: 9, calendarId: '2', startMs: 30000, endMs: 40000, title: 'Recurrence one' },
|
||||||
|
{ id: 9, calendarId: '2', startMs: 50000, endMs: 60000, title: 'Recurrence two' },
|
||||||
|
];
|
||||||
|
const modules = {
|
||||||
|
'@nativescript/core': { Utils: { android: { getApplicationContext: () => ({}) } } },
|
||||||
|
'../g2/android-permissions': { hasCalendarPermission: () => permitted },
|
||||||
|
'./calendar-permissions': { hasCalendarPermission: () => permitted },
|
||||||
|
'./frame-timings': { spanCurrent: (_name, fn) => fn() },
|
||||||
|
'./calendar-selection': prefs,
|
||||||
|
'./settings-store': storage,
|
||||||
|
};
|
||||||
|
const globals = { global: { isAndroid: true }, com: { faceclaw: { app: { FaceclawCalendarProvider: {
|
||||||
|
getCalendarsJson: () => JSON.stringify(calendars),
|
||||||
|
getUpcomingEventsJson: (_ctx, max, window, selection) => {
|
||||||
|
calls.push({ max, window, selection });
|
||||||
|
const ids = JSON.parse(selection);
|
||||||
|
return JSON.stringify(events.filter(event => ids === null || ids.includes(event.calendarId)).slice(0, max));
|
||||||
|
},
|
||||||
|
} } } } };
|
||||||
|
const api = load('app/native/calendar.ts', modules, globals);
|
||||||
|
const sources = load('app/native/calendar-sources.ts', modules, globals);
|
||||||
|
return { api, prefs, sources, modules, globals, settings, calls, calendars,
|
||||||
|
permissions: value => { permitted = value; } };
|
||||||
|
}
|
||||||
|
|
||||||
|
test('calendar selection distinguishes all and none, survives restart and rejects invalid data', () => {
|
||||||
|
const f = fixture();
|
||||||
|
assert.equal(f.prefs.readCalendarSelection(), null);
|
||||||
|
f.prefs.setCalendarSelection([]);
|
||||||
|
assert.deepEqual(Array.from(fixture(f.settings).prefs.readCalendarSelection()), []);
|
||||||
|
f.prefs.setCalendarSelection(['2', '2', '1']);
|
||||||
|
assert.deepEqual(Array.from(fixture(f.settings).prefs.readCalendarSelection()), ['2', '1']);
|
||||||
|
f.prefs.setCalendarSelection(null);
|
||||||
|
assert.equal(fixture(f.settings).prefs.readCalendarSelection(), null);
|
||||||
|
assert.throws(() => f.prefs.setCalendarSelection(['1 OR 1=1']));
|
||||||
|
for (const value of ['oops', '{}', '[false]', '["bad"]']) {
|
||||||
|
f.settings.set(f.prefs.CALENDAR_SELECTION_KEY, value);
|
||||||
|
assert.equal(f.prefs.readCalendarSelection(), null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('shared reader forwards IDs before limiting, preserves recurrence occurrences and invalidates all cached query variants', async () => {
|
||||||
|
const f = fixture();
|
||||||
|
assert.equal(f.api.readUpcomingEvents(1)[0].title, 'Excluded early');
|
||||||
|
f.api.readUpcomingEvents(1);
|
||||||
|
assert.equal(f.calls.length, 1);
|
||||||
|
let notifications = 0;
|
||||||
|
const off = f.api.onCalendarChanged(() => notifications++);
|
||||||
|
f.prefs.setCalendarSelection(['2']);
|
||||||
|
const rows = f.api.readUpcomingEvents(2);
|
||||||
|
assert.deepEqual(Array.from(rows, event => event.id), [9, 9]);
|
||||||
|
assert.equal(f.calls.at(-1).selection, '["2"]');
|
||||||
|
assert.equal(notifications, 1);
|
||||||
|
assert.equal((await f.api.readUpcomingEventsAsync(1))[0].title, 'Recurrence one');
|
||||||
|
off();
|
||||||
|
f.prefs.setCalendarSelection([]);
|
||||||
|
assert.equal(notifications, 1);
|
||||||
|
assert.equal(f.api.readUpcomingEvents(1).length, 0, 'selection cache key works even without subscriptions');
|
||||||
|
assert.equal(fixture(f.settings).api.readUpcomingEvents().length, 0);
|
||||||
|
f.prefs.setCalendarSelection(['999']);
|
||||||
|
assert.equal(f.api.readUpcomingEvents().length, 0, 'deleted calendar does not revert to all');
|
||||||
|
f.permissions(false);
|
||||||
|
assert.equal(f.api.readUpcomingEvents().length, 0);
|
||||||
|
assert.equal(f.sources.readAvailableCalendars().length, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('calendar menu distinguishes equal names by account and ID; all, none, deleted and individual selections share preferences', () => {
|
||||||
|
const f = fixture();
|
||||||
|
const { CalendarFilterLayer } = load('app/apps/calendar/calendar-filter.ts', {
|
||||||
|
'../../graphics/ui-fonts': { getDefaultSmallFont: () => ({}) },
|
||||||
|
'../../graphics/textwrap': { truncateText: (_font, text) => text },
|
||||||
|
'../../native/calendar-selection': f.prefs,
|
||||||
|
'../../native/calendar-sources': f.sources,
|
||||||
|
'../../native/calendar-permissions': { hasCalendarPermission: () => true },
|
||||||
|
'../../ui/menu': {
|
||||||
|
drawToggleMenuItem: () => {},
|
||||||
|
MenuLayer: class {
|
||||||
|
constructor(_title, items) { this.items = items; this.selectedIndex = 0; }
|
||||||
|
selectItem(index) { this.selectedIndex = index; return this; }
|
||||||
|
setItems(items, index) { this.items = items; this.selectedIndex = index; }
|
||||||
|
paint() { return this.items; }
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, f.globals);
|
||||||
|
const layer = new CalendarFilterLayer();
|
||||||
|
const ctx = { stack: { getBaseSize: () => ({ width: 576 }) } };
|
||||||
|
const rows = () => layer.paint(ctx, () => {});
|
||||||
|
assert.ok(rows()[2].label.includes('one@example.com'));
|
||||||
|
assert.ok(rows()[3].label.includes('two@example.com'));
|
||||||
|
rows()[2].onSelect();
|
||||||
|
assert.deepEqual(Array.from(f.prefs.readCalendarSelection()), ['2']);
|
||||||
|
rows()[1].onSelect();
|
||||||
|
assert.equal(f.api.readUpcomingEvents().length, 0);
|
||||||
|
rows()[3].onSelect();
|
||||||
|
assert.deepEqual(Array.from(f.prefs.readCalendarSelection()), ['2']);
|
||||||
|
f.calendars.pop();
|
||||||
|
const missing = rows().find(row => row.label === 'Unavailable calendar #2');
|
||||||
|
assert.ok(missing);
|
||||||
|
missing.onSelect();
|
||||||
|
assert.equal(f.prefs.readCalendarSelection().length, 0);
|
||||||
|
rows()[0].onSelect();
|
||||||
|
assert.equal(f.prefs.readCalendarSelection(), null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Android provider restricts Instances with bound calendar IDs before cutoff and limit', () => {
|
||||||
|
const kotlin = source('App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCalendarProvider.kt');
|
||||||
|
assert.match(kotlin, /Instances\.CALENDAR_ID/);
|
||||||
|
assert.match(kotlin, /if \(ids != null && ids.length\(\) == 0\) return "\[\]"/);
|
||||||
|
assert.match(kotlin, /PROJECTION,\s+selection,\s+args,/);
|
||||||
|
assert.ok(kotlin.indexOf('selection,\n args,') < kotlin.indexOf('events.take(limit)'));
|
||||||
|
assert.match(kotlin, /CalendarContract\.Calendars\._ID/);
|
||||||
|
assert.match(kotlin, /CalendarContract\.Calendars\.ACCOUNT_NAME/);
|
||||||
|
for (const file of ['app/apps/calendar/calendar.ts', 'app/apps/glanceboard/widgets/calendar-widget.ts']) {
|
||||||
|
assert.match(source(file), /readUpcomingEvents/);
|
||||||
|
assert.match(source(file), /native\/calendar"/);
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -199,6 +199,7 @@ test('Calendar window subscribes, refreshes periodically, and cleans up on close
|
|||||||
'../../native/calendar': { onCalendarChanged: fn => { listener = fn; return () => unsubscribed++; } },
|
'../../native/calendar': { onCalendarChanged: fn => { listener = fn; return () => unsubscribed++; } },
|
||||||
'../../ui/shell/chrome-layer': { makeImageWindowIcon() {}, windowIcon() {} },
|
'../../ui/shell/chrome-layer': { makeImageWindowIcon() {}, windowIcon() {} },
|
||||||
'./calendar': { CalendarLayer: class {} }, './calendar-icon': {},
|
'./calendar': { CalendarLayer: class {} }, './calendar-icon': {},
|
||||||
|
'./calendar-filter': { calendarSelectionMenuItems: () => [] },
|
||||||
'../../ui/shell/in-process-window': { YieldAtRootLayer: class {}, createInProcessWindow: value => { options = value; return app; } },
|
'../../ui/shell/in-process-window': { YieldAtRootLayer: class {}, createInProcessWindow: value => { options = value; return app; } },
|
||||||
}, { setInterval: fn => { tick = fn; return 1; }, clearInterval: () => cleared++ });
|
}, { setInterval: fn => { tick = fn; return 1; }, clearInterval: () => cleared++ });
|
||||||
createCalendarAppWindow({ onClosed: () => closed++ });
|
createCalendarAppWindow({ onClosed: () => closed++ });
|
||||||
|
|||||||
@@ -1,106 +0,0 @@
|
|||||||
const test = require('node:test');
|
|
||||||
const assert = require('node:assert/strict');
|
|
||||||
const fs = require('node:fs');
|
|
||||||
const vm = require('node:vm');
|
|
||||||
const ts = require('typescript');
|
|
||||||
|
|
||||||
function fixture(swap = false, app = {}) {
|
|
||||||
const source = ts.createSourceFile('shell.ts', fs.readFileSync('app/ui/shell/shell.ts', 'utf8'), ts.ScriptTarget.Latest, true);
|
|
||||||
const cls = source.statements.find(n => ts.isClassDeclaration(n) && n.name.text === 'Shell');
|
|
||||||
const route = cls.members.find(n => n.name?.getText(source) === 'routeInput');
|
|
||||||
class Overlay {}
|
|
||||||
const context = { exports: {}, ShellOverlayMenuLayer: Overlay,
|
|
||||||
swapMenuGesturesSetting: { get: () => swap }, isWatchInput: () => false };
|
|
||||||
vm.runInNewContext(ts.transpileModule(`export class Shell { ${route.getText(source)} }`, {
|
|
||||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
|
||||||
}).outputText, context);
|
|
||||||
const s = new context.exports.Shell();
|
|
||||||
const delivered = [];
|
|
||||||
const window = { handleInput: async e => delivered.push(e), hasAppMenu: () => true, ...app };
|
|
||||||
let overlay = false, escapes = 0;
|
|
||||||
Object.assign(s, { focus: 'window', screenOn: true, lastInput: null,
|
|
||||||
foregroundWindow: () => window, cancelEscapeMenuTimer() {},
|
|
||||||
startEscapeMenuTimer() { escapes++; }, config: { requestShellRender() {} },
|
|
||||||
openEscapeMenu() { overlay = true; },
|
|
||||||
stack: { isAtBase: () => !overlay, popIfTop(fn) { if (overlay && fn(new Overlay())) { overlay = false; return true; } return false; } },
|
|
||||||
});
|
|
||||||
return { s, delivered, setSwap: value => { swap = value; }, overlay: () => overlay, escapes: () => escapes,
|
|
||||||
input: type => s.routeInput({ type, source: 'ring', timestampMs: 42 }, 17) };
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const swap of [false, true]) {
|
|
||||||
test(`menu routing, overlay switching and metadata with inversion ${swap}`, async () => {
|
|
||||||
const h = fixture(swap);
|
|
||||||
const system = swap ? 'short-then-long-press' : 'long-press';
|
|
||||||
const app = swap ? 'long-press' : 'short-then-long-press';
|
|
||||||
await h.input(app);
|
|
||||||
assert.equal(h.delivered.at(-1).type, 'short-then-long-press');
|
|
||||||
assert.equal(h.delivered.at(-1).source, 'ring');
|
|
||||||
assert.equal(h.delivered.at(-1).timestampMs, 42);
|
|
||||||
await h.input(system);
|
|
||||||
assert.equal(h.overlay(), true);
|
|
||||||
await h.input(app);
|
|
||||||
assert.equal(h.overlay(), false);
|
|
||||||
assert.equal(h.delivered.length, 2);
|
|
||||||
});
|
|
||||||
for (const app of [{ claimsLongPress: () => true }, { holdToTalk: true }]) {
|
|
||||||
test(`owned long press remains intact with inversion ${swap}: ${JSON.stringify(Object.keys(app))}`, async () => {
|
|
||||||
const h = fixture(swap, app);
|
|
||||||
await h.input('long-press');
|
|
||||||
assert.equal(h.delivered[0].type, 'long-press');
|
|
||||||
assert.equal(h.escapes(), app.holdToTalk ? 0 : 1);
|
|
||||||
await h.input('short-then-long-press');
|
|
||||||
if (app.holdToTalk) assert.equal(h.overlay(), true);
|
|
||||||
else assert.equal(h.delivered[1].type, 'short-then-long-press');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
test('gesture inversion never wakes a sleeping screen', async () => {
|
|
||||||
const h = fixture(true); h.s.screenOn = false;
|
|
||||||
await h.input('long-press'); await h.input('short-then-long-press');
|
|
||||||
assert.equal(h.delivered.length, 0); assert.equal(h.overlay(), false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('the switcher retains its existing gestures when inversion is enabled', async () => {
|
|
||||||
for (const type of ['long-press', 'short-then-long-press']) {
|
|
||||||
const snapshots = [];
|
|
||||||
for (const swap of [false, true]) {
|
|
||||||
const h = fixture(swap); h.s.focus = 'sidebar';
|
|
||||||
await h.input(type);
|
|
||||||
snapshots.push({ overlay: h.overlay(), delivered: h.delivered.map(e => e.type) });
|
|
||||||
}
|
|
||||||
assert.deepEqual(snapshots[0], snapshots[1]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('the setting applies immediately and follows changing app hold ownership', async () => {
|
|
||||||
let claims = false;
|
|
||||||
const h = fixture(false, { claimsLongPress: () => claims });
|
|
||||||
h.setSwap(true);
|
|
||||||
await h.input('long-press');
|
|
||||||
assert.equal(h.delivered.at(-1).type, 'short-then-long-press');
|
|
||||||
claims = true;
|
|
||||||
await h.input('long-press');
|
|
||||||
assert.equal(h.delivered.at(-1).type, 'long-press');
|
|
||||||
claims = false;
|
|
||||||
await h.input('long-press');
|
|
||||||
assert.equal(h.delivered.at(-1).type, 'short-then-long-press');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('app menu hints reflect inversion, voice capture and owned holds', () => {
|
|
||||||
const source = ts.createSourceFile('window-menu.ts', fs.readFileSync('app/ui/window-menu.ts', 'utf8'), ts.ScriptTarget.Latest, true);
|
|
||||||
const cls = source.statements.find(n => ts.isClassDeclaration(n) && n.name.text === 'WindowMenuLayer');
|
|
||||||
let swap = false;
|
|
||||||
const context = { exports: {}, MenuLayer: class { constructor(_title, _items, layout) { this.layout = layout; } },
|
|
||||||
WINDOW_MENU_LAYOUT: { footer: 'long-press' }, GESTURE_SHORT_THEN_LONG_PRESS: 'tap-hold',
|
|
||||||
swapMenuGesturesSetting: { get: () => swap }, gestureHints: hints => hints[0][0] };
|
|
||||||
vm.runInNewContext(ts.transpileModule(cls.getText(source), {
|
|
||||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
|
||||||
}).outputText, context);
|
|
||||||
const hint = (voice = false, claims = false) => new context.exports.WindowMenuLayer('App', [], voice, claims).layout.footer;
|
|
||||||
assert.equal(hint(), 'long-press');
|
|
||||||
swap = true;
|
|
||||||
assert.equal(hint(), 'tap-hold');
|
|
||||||
assert.equal(hint(false, true), 'long-press');
|
|
||||||
assert.equal(hint(true), 'tap-hold');
|
|
||||||
});
|
|
||||||
Reference in new issue
Block a user