Max Lv:计划把小组件与控制中心的重载移入数据包隧道进程
Max Lv(madeye)在自己提交的 meow iOS issue #393(承接 #392 的审查)中说明:小组件与控制中心的重载目前只来自应用进程(WidgetReloader 在阶段变化时,以及自 #392 起在应用变为活跃时)和小组件的 intent,因此应用未运行时发生的状态变化,要到下次打开 meow 才会反映到控制中心开关上,主屏与锁屏小组件则要等 30 分钟时间线才追上。受影响的变化包括:在「设置 › VPN」中关闭 VPN、另一个 VPN 应用占用该位置、数据包隧道崩溃或 intent 的 10 秒稳定超时后启动失败、按需重连。由于每次启动和停止都要经过数据包隧道提供者,他认为那里是调用 `WidgetCenter.shared.reloadAllTimelines()` 与 `ControlCenter.shared.reloadAllControls()` 更稳妥的位置。动手前需要确认:`PacketTunnel/` 是纯 Objective-C,而这两个 API 仅 Swift 可用,需要在网络扩展中加一个链接 WidgetKit 的小型 Swift shim;在设备上测量网络扩展前后的 RSS(设置 › 关于 › 内存),因为网络扩展运行在约 50 MB 的 jetsam 上限下,而 WidgetKit 会把 SwiftUI 拉进进程;在设备上确认从网络扩展进程调用两个重载均可用;停止时阶段是 `.stopping`(不是 `isActive`),所以从 `stopTunnel` 触发重载会显示 Off,而 `startTunnel` 的重载落在连接中、读作 On,两者都是正确的最终状态。
作者原文@madeyeFollow-up from the #392 review (@gengjiawen).
Widget and Control Center reloads currently come only from the app process (
WidgetReloader: on stage change, and since #392 on becoming active) and from the widget intents. State changes made while the app isn't running don't reach the Control Center toggle until meow is next opened. The Home Screen and Lock Screen widgets catch up on their 30-minute timeline. The affected changes:
- the VPN turned off in Settings › VPN
- another VPN app taking the slot
- the packet tunnel dying, or a start failing after the intent's 10 s settle timeout
- on-demand reconnects
Every start and stop goes through the packet tunnel provider, so it is the sturdier place for
WidgetCenter.shared.reloadAllTimelines()andControlCenter.shared.reloadAllControls().Before doing it:
PacketTunnel/is pure Objective-C, and both APIs are Swift-only. This needs a small Swift shim in the NE that links WidgetKit.- Measure the NE's RSS on device before and after (Settings › About › Memory). The NE runs under the ~50 MB jetsam cap, and WidgetKit pulls SwiftUI into the process.
- Confirm on device that both reloads work when called from an NE process.
- While stopping, the stage is
.stopping, which isn'tisActive, so a reload fromstopTunnelshows Off. A reload fromstartTunnellands while connecting, which reads as On. Both are the right end states.