Files
MeowOS-For-R3P2/patch_v2/files_app/app.c
T
MeowOS c187b7bce3 feat(files): 新增外置系统文件管理器 os.meow.files (agent-183) — 目录浏览(虚拟化列表/空态)+文本预览(≤256KB截断)+删除/重命名/新建/属性(BottomSheet+IME);路径写操作限 TF 卡内(拒 .. 越界);多文件结构(app.c+ui/{browser,viewer}.c+ui/common/chrome.c+logic/fsx.c) 按批次②范本
files md5 6f6b0a6d; 0 warning; 宿主 test_fsx 全过(路径安全/格式化/排序/虚拟化/写操作/文本嗅探); qemu 离屏冒烟通过
SDK 缺口记录: listview 仅单行 label(本 App 用 custom 画布自绘行); common 档字库中文缺字(未声明 fonts:full)
真机待验证: 列表渲染/滚动手感/IME 重命名/弹窗交互
2026-08-31 04:03:56 +08:00

107 lines
3.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* app.c — files 应用装配层:main + 组装 + 事件分发。
*
* 职责(对齐 hello_app/app.c):main 只做初始化/建页/跑事件循环/清理;把 meow_ui_run 的平铺输入
* 回调(key/tap/swipe/tick/touch)路由到当前活动页(browser/viewer)。页面切换统一走
* meow_view_page_push/pop(活动栈 + on_enter/on_leave 唯一驱动)。
*
* 铁律(APPS.md §3.4.1 / WORK_STATE.md):物理键禁映射——不处理任何 key 语义;返回=左缘左滑
* (on_swipe LEFT)/返回钮/meow_ui_request_exit。目录进退不换页(browser 改 cur_dir 重扫);
* 文本预览换页(push ACT_VIEWER)。退出=在根目录左滑或 SIGTERM(看门狗)。
*/
#include "files_internal.h"
#include <signal.h>
static meow_view *g_browser_view;
static meow_view *g_viewer_view;
static void on_sigterm(int s) { (void)s; meow_ui_request_exit(); }
/* ============================================================ */
/* 事件分发:meow_ui_run 平铺回调 → 当前页 */
/* ============================================================ */
/* 物理键系统语义(息屏/音量/媒体)由 SDK 消化;App 不映射(§3.4.1)。 */
static void app_on_key(int keycode, int is_down)
{
(void)keycode; (void)is_down;
}
static void app_on_tap(int x, int y)
{
if (viewer_is_active()) { viewer_on_tap(x, y); return; }
if (browser_is_active()) { browser_on_tap(x, y); return; }
}
static void app_on_swipe(int dir, int dx, int dy)
{
(void)dx;
if (dir == MEOW_SWIPE_LEFT) {
/* 左缘返回:预览页→回目录;浏览器→上级目录;到根→退出 App。 */
if (viewer_is_active()) { meow_view_page_pop(); return; }
if (browser_is_active() && browser_go_up()) return;
meow_log(MEOW_LOG_INFO, "exit:swipe");
meow_ui_request_exit();
return;
}
if (viewer_is_active()) { viewer_swipe(dir, dy); return; }
if (browser_is_active()) { browser_swipe(dir, dy); return; }
}
/* 左缘返回手势过程视觉条(SDK 自动画顶部进度条,App 转发)。 */
static void app_on_swipe_progress(int x_start, int dx)
{
meow_ui_swipe_hint(x_start + dx);
}
/* 拖拽过程(跟手):列表/文本内容滚动。 */
static void app_on_touch_down(int x, int y)
{
if (viewer_is_active()) viewer_touch_down(x, y);
else if (browser_is_active()) browser_touch_down(x, y);
}
static void app_on_touch_move(int x, int y)
{
if (viewer_is_active()) viewer_touch_move(x, y);
else if (browser_is_active()) browser_touch_move(x, y);
}
/* on_tick:长按检测(browser 页)。 */
static void app_on_tick(void)
{
if (browser_is_active()) browser_tick(meow_ui_time_ms());
}
/* ============================================================ */
/* main */
/* ============================================================ */
int main(void)
{
meow_log(MEOW_LOG_INFO, "start");
meow_ui_opts o = { APP_W, APP_H };
if (meow_ui_init(&o) != 0) { meow_log(MEOW_LOG_ERROR, "init failed"); return 1; }
meow_theme_add_listener(NULL);
signal(SIGTERM, on_sigterm);
/* 建两页 view(on_create 建各自控件/状态 + 读卡扫首个目录) */
g_browser_view = browser_view_create();
g_viewer_view = viewer_view_create();
/* 进入根页(ACT_BROWSER = 目录浏览;默认卡根 /usr/data/mnt/sd_0) */
meow_view_page_push(ACT_BROWSER);
meow_ui_events ev = {
app_on_key, app_on_tap, app_on_swipe, app_on_tick, app_on_swipe_progress,
app_on_touch_down, app_on_touch_move,
};
meow_ui_run(&ev);
/* 清理:meow_view_free 触发各页 on_destroy(控件 + 文本缓冲) */
meow_view_free(g_viewer_view);
meow_view_free(g_browser_view);
meow_ui_shutdown();
meow_log(MEOW_LOG_INFO, "exit");
return 0;
}