mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
feat(native): pick the trip a widget shows in Edit Widget
Widgets followed the dashboard's trip only, which is the one under way, so a packing list or to-dos for a trip still being planned could not sit on the home screen. The trip, today, bookings, to-dos, packing and group widgets now take a trip in Edit Widget (an AppIntent with the trips running or ahead, Automatic by default, which keeps following the dashboard); the world map needs none. - The app writes a snapshot per trip running or ahead (at most six, the dashboard's order) and the list to pick from, under their own keys (feature widgetTrips, so an older binary never mistakes one for the dashboard's); bags, chat and polls are kept ten minutes, covers per trip - The widget extension targets iOS 17, which configurable widgets need; the apps are not released, so no installed widget goes away - The choices and their texts in the 28 languages of the gallery
This commit is contained in:
@@ -144,6 +144,16 @@ export function pickTrip(trips: Trip[], today: string): Trip | null {
|
||||
return heroTrip(sortTripsByRelevance(active, today), today);
|
||||
}
|
||||
|
||||
/**
|
||||
* The trips a widget can be set to in Edit Widget: the ones running or coming
|
||||
* up, in the dashboard's order (so the hero's trip comes first), at most `limit`,
|
||||
* each of which gets a snapshot of its own.
|
||||
*/
|
||||
export function widgetTripChoices(trips: Trip[], today: string, limit = 6): Trip[] {
|
||||
const ahead = trips.filter((t) => !t.is_archived && t.start_date && (t.end_date ?? t.start_date) >= today);
|
||||
return sortTripsByRelevance(ahead, today).slice(0, limit);
|
||||
}
|
||||
|
||||
/** The symbols of the booking kinds a day's timeline shows next to its stops. */
|
||||
const RESERVATION_SYMBOLS: Record<string, string> = {
|
||||
flight: 'airplane',
|
||||
@@ -294,12 +304,32 @@ export function tripDayState(day: TripDay, nowMinutes: number, allDone: string)
|
||||
};
|
||||
}
|
||||
|
||||
/** A trip a widget can be set to in Edit Widget, and its snapshot. */
|
||||
export interface TripWidgetSnapshot {
|
||||
id: number;
|
||||
title: string;
|
||||
start: string;
|
||||
end: string;
|
||||
snapshot: WidgetSnapshot;
|
||||
}
|
||||
|
||||
export async function publishWidgets(
|
||||
snapshot: WidgetSnapshot,
|
||||
liveDay: ReturnType<typeof tripDayState> | null
|
||||
liveDay: ReturnType<typeof tripDayState> | null,
|
||||
trips: TripWidgetSnapshot[] = []
|
||||
): Promise<void> {
|
||||
if (!widgetsActive()) return;
|
||||
await TrekShell.setWidgetSnapshot({ json: JSON.stringify(snapshot) }).catch(reportNativeFailure);
|
||||
// An app binary without widgetTrips would take every one of these for the dashboard's snapshot.
|
||||
if (hasNativeFeature('widgetTrips')) {
|
||||
for (const trip of trips) {
|
||||
await TrekShell.setWidgetSnapshot({ json: JSON.stringify(trip.snapshot), key: `trip.${trip.id}` }).catch(
|
||||
reportNativeFailure
|
||||
);
|
||||
}
|
||||
const index = trips.map(({ id, title, start, end }) => ({ id, title, start, end }));
|
||||
await TrekShell.setWidgetSnapshot({ json: JSON.stringify(index), key: 'trips' }).catch(reportNativeFailure);
|
||||
}
|
||||
if (!hasNativeFeature('liveActivity')) return;
|
||||
if (liveDay && liveDay.total > 0) await TrekShell.syncTripDay(liveDay).catch(reportNativeFailure);
|
||||
else await TrekShell.endTripDay().catch(reportNativeFailure);
|
||||
|
||||
Reference in New Issue
Block a user