Files
jrshikoku/components/AndroidWidget/widget-task-handler.tsx
harukin-expo-dev-env d4ad8c005e feat(widget): add Shortcut, Delay Info, and Felica Balance widgets
- Implemented ShortcutWidget for quick access to app features with customizable shortcuts.
- Added DelayInfoWidget to display train delay information fetched from a remote endpoint.
- Created FelicaBalanceWidget to show the balance of Felica-compatible IC cards.
- Introduced OperationInfoWidget for displaying train operation status.
- Set up shared data handling for Felica snapshots between the main app and widget.
- Configured widget assets and entitlements for proper functionality.
- Updated Info.plist and expo-target.config.js for widget deployment.
2026-03-22 11:45:58 +00:00

69 lines
1.7 KiB
TypeScript

import React from "react";
import { TraInfoEXWidget, getDelayData } from "./TraInfoEXWidget";
import { InfoWidget, getInfoString } from "./InfoWidget";
import {
FelicaQuickAccessWidget,
getFelicaQuickAccessData,
} from "./FelicaQuickAccessWidget";
import { ShortcutWidget, getShortcutData } from "./ShortcutWidget";
export const nameToWidget = {
JR_shikoku_train_info: TraInfoEXWidget,
Info_Widget: InfoWidget,
JR_shikoku_apps_shortcut: ShortcutWidget,
JR_shikoku_felica_balance: FelicaQuickAccessWidget,
};
export async function widgetTaskHandler(props) {
const {
widgetInfo,
widgetAction,
renderWidget,
clickAction,
clickActionData,
} = props;
switch (widgetAction) {
case "WIDGET_ADDED":
case "WIDGET_UPDATE":
case "WIDGET_CLICK":
case "WIDGET_RESIZED": {
const name = widgetInfo.widgetName;
if (name === "JR_shikoku_felica_balance") {
const quickData = await getFelicaQuickAccessData();
renderWidget(<FelicaQuickAccessWidget {...quickData} />);
break;
}
if (name === "JR_shikoku_apps_shortcut") {
const data = getShortcutData();
renderWidget(<ShortcutWidget {...data} />);
break;
}
if (name === "JR_shikoku_info") {
const { time, text } = await getInfoString();
renderWidget(
<InfoWidget time={time} text={text && text.toString()} />
);
break;
}
// JR_shikoku_train_info and default
{
const { time, delayString } = await getDelayData();
renderWidget(
<TraInfoEXWidget time={time} delayString={delayString} />
);
}
break;
}
case "WIDGET_DELETED":
break;
default:
break;
}
}