Repository navigation
feat: 包装载支持多 App 与包内 Service——第三方应用可自带多个窗口与服务 - #6
Merged
Merged
Conversation
让第三方 .emz 包能成为一个完整应用(而非只能一个 App),这是 AgentOS 桌面
包独立分发的前置能力:
- AppHost#evaluate! 放宽为注册 entry 定义的**全部** Emerald::App 子类(去掉
app_id 必须等于包 id 的硬断言,保留「至少一个新 App 子类」);reopen/reload
场景经包 id → 类列表的内存映射回查(重开类不触发 inherited)
- Emerald::Service 加子类追踪(inherited + service_subclasses,照 App 写法);
AppHost 暴露 defined_services(本轮 scan/reload 新定义的 Service 子类,
含 reopen 回查),DesktopShell 新增 register_package_services:注册进
ServiceHub 并幂等 activate_startup;启动扫描与 install_and_register、
on_app_source_saved 三处调用
- 新增能力面 ctx[:launch_app](->(id, argv = {}) { launch_app(id, **argv) }):
包内 App 拉起兄弟窗口的正规入口(此前 ctx 里只有裸 AppRegistry,
launch 只建实例不开窗)
- 贡献命令可指向包内窗口:contributes.commands[] 新增可选 app 字段,
取值链 cmd[:app] → 该包首个已注册 App → 包 id;无可用 App 时跳过并告警
- 卸载时清编译缓存(invalidate_cache),examples/*.emz 进 .gitignore
- SPEC §4.1 同步:多 App / 包内 Service / 命令 app 字段
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
动机
第三方
.emz包此前只能承载一个 App(AppHost 要求 entry 定义的类app_id必须等于包 id),且包内 Service 无人接管、ctx 里没有正式的开窗入口。因此一个真实应用(如 AgentOS 桌面:1 个轮询 Service + 4 个窗口 App)无法独立分发。本 PR 补齐这三项宿主能力,不含任何具体应用代码。
改动
AppHost#evaluate!注册 entry 定义的全部Emerald::App子类(去掉app_id == 包 id硬断言,保留「至少一个新 App 子类」);scan_one逐个注册,已注册的同app_id跳过。reopen/reload 场景经@package_apps(包 id → 类列表)回查——重开类不触发inheritedEmerald::Service加子类追踪(inherited+service_subclasses,与App同款);AppHost#defined_services暴露本轮新定义的 Service(含 reopen 回查@package_services);DesktopShell#register_package_services注册进ServiceHub并幂等activate_startup,在启动扫描 /install_and_register/on_app_source_saved三处调用ctx[:launch_app] = ->(id, argv = {}) { launch_app(id, **argv) }。包内 App 拉起兄弟窗口的正规入口(此前ctx[:launcher]是裸AppRegistry,launch只建实例不开窗,宿主只能替换服务对象这种非常规注入——这也是 emerald 侧示例里那个ShellLauncherBridge存在的原因)contributes.commands[]新增可选app字段,取值链cmd[:app]→ 该包首个已注册 App → 包 id;包内无可用 App 时跳过并notify告警(原先硬接launch_app(包id),多 App 包会抛「未注册的应用」)invalidate_cache(清/System/Cache/<id>.js);.gitignore补examples/*.emzctx[:launcher]/[:apps]语义未变(shell_test/about_test的断言仍成立)。docs/SPEC-package-format.md§4.1 同步:包 entry 可定义一个或多个 App 子类、可定义 Service 子类、命令可声明app。验证
bundle exec rake test:405 runs, 0 failures;rake compile通过pkg_apphost_test(多 App 注册、defined_services、扫描重置、失败包不贡献 Service、reopen 回查)、shell_e7_test(多 App.emz安装、启动期 Service 注册+激活、幂等、launch_appargv 透传、卸载清缓存)invalidate_cache/register_package_services调用 / reopen 回查 /defined_services重置,各自触发对应测试失败(非空断言).emz装入DesktopShell→ 四 App 注册、LinkService进 hub 且activated?、launch_app(:agentos_agent, endpoint: 'agent-1')开窗、卸载清缓存 —— 全通过配套
应用侧独立仓库:
agentos-desk(源码、打包器、测试、CI)。本 PR 与它配套;本仓不再持有该包源码。