Skip to content

feat(weather): add iOS current weather widget foundation - #576

Open
YinCheng0106 wants to merge 16 commits into
mainfrom
feat/ios-widget-current-weather
Open

YinCheng0106 wants to merge 16 commits into
mainfrom
feat/ios-widget-current-weather

Conversation

@YinCheng0106

@YinCheng0106 YinCheng0106 commented Sep 16, 2026

Copy link
Copy Markdown

這個 PR 做了什麼

新增 iOS 目前天氣 Widget 的基礎功能,讓 Widget 可顯示 DPIP 所選地區的目前天氣,並支援 stale 狀態、日夜圖示切換、Deep Link 與中英文介面。

此 PR 為 iOS Weather Widget 的第一階段實作,先建立 Current Weather Widget 與相關基礎架構;後續地點設定、獨立背景更新、Medium / Large Widget 與預報功能將以獨立 PR 逐步加入。

相關 issue

目前無。

怎麼驗

基本功能

  1. 使用 tool/run.sh 啟動 DPIP。
  2. 在 App 中選擇一個台灣地區。
  3. 將「目前天氣」Widget 加入 iOS 主畫面。
  4. 確認 Widget 可顯示:
    • 所選地區
    • 目前天氣
    • 溫度
    • 濕度
    • 雨量
    • 觀測時間

地區同步

  1. 在 DPIP 中切換地區。
  2. 等待新地區天氣資料載入。
  3. 確認 Widget 更新為新的地區及天氣資料。
  4. 確認切換期間不會將上一個地區的資料誤認為目前地區。

stale 狀態

Widget 資料超過目前設定的 stale threshold 後,確認:

  • Widget 仍保留最後一筆有效天氣資料。
  • 顯示「較舊 / Outdated」狀態。
  • 不會把舊資料表示成即時資料。

日夜切換

確認目前天氣 Widget 可依所在地日出、日落時間切換圖示,例如:

  • 晴天白天:sun.max.fill
  • 晴天夜晚:moon.stars.fill
  • 多雲白天:cloud.sun.fill
  • 多雲夜晚:cloud.moon.fill

WidgetKit timeline 會安排下一個日夜 transition,不需要重新開啟 App 才能完成已排定的圖示切換。

Deep Link

點擊 Widget 後,確認可透過:

dpip:///home

開啟 DPIP 首頁。

本地化

確認 Widget Extension 支援:

  • English
  • 繁體中文(zh-Hant)

包含:

  • Widget Gallery 名稱
  • Widget Gallery 描述
  • stale 狀態
  • 無資料狀態
  • 天氣狀態文字(例如 Clear / 晴、Rain / 雨)

原生 Widget 字串使用 Extension 專用 String Catalog,不使用 Flutter AppLocalizations

自動測試與建置

已驗證:

  • tool/dev/analyze.sh 通過
  • tool/dev/test.sh 通過
  • tool/check.sh repository gates 通過
  • Widget 相關 Dart tests 通過
  • Native RunnerTests / Widget XCTest 通過
  • iOS Debug build 成功
  • Runner.appDPIPWidgetsExtension.appex 成功產出
  • git diff --check 通過

後續開發

此功能採分階段 PR 開發:

  1. feat/ios-widget-current-weather — 本 PR

    • Current Weather Widget 基礎
    • App Group snapshot
    • stale / day-night timeline
    • localization
  2. feat/ios-widget-configuration

    • 將 DPIP 已儲存地點同步至 App Group
    • 建立 Widget location catalog
  3. feat/ios-widget-intent-configuration

    • 每個 Widget instance 可獨立選擇所在地或已儲存地點
    • per-location snapshot cache
    • Intent Extension 與 Widget configuration
  4. feat/ios-widget-weather-refresh — 開發中

    • Widget 原生天氣 fetch 基礎架構
    • location resolver
    • 後續整合 WidgetKit refresh 與背景更新

各階段刻意拆分,以避免將 Widget configuration、storage migration
與 native networking 混入同一個 PR。

Reviewer 建議重點

建議優先確認:

  • Dart → App Group → Swift Widget 的資料流與 schema contract
  • Widget snapshot storage / MethodChannel 邊界
  • Region 切換時舊 snapshot 的處理
  • stale 與 day/night timeline composition
  • v4 + v2/v3 backwards compatibility
  • Widget Extension target membership
  • Native localization resource 是否只進入 Widget Extension
  • 後續擴充 configurable Widget 與 self-refresh 時,現有架構是否有不必要耦合

檢查清單

  • tool/check/commits.sh origin/main..HEAD 通過
    —— commit 訊息就是更新日誌,格式見 commit.md
  • 一個 commit 一件事(這條 gate 驗不了,靠自己和 review)
  • tool/dev/analyze.shtool/dev/test.sh 通過
  • tool/check.sh repository gates 通過
  • 新的使用者可見字串皆有本地化
    - Flutter UI 維持 AppLocalizations
    - Widget Extension 使用原生 Localizable.xcstrings
  • 有 UI 變更的話:深色模式與文字顯示已確認;Widget UI 使用原生 SwiftUI layout

@YinCheng0106 YinCheng0106 self-assigned this Sep 16, 2026
@YinCheng0106 YinCheng0106 added the ios Issues or pull requests related to the iOS platform. label Sep 16, 2026
@YinCheng0106
YinCheng0106 changed the base branch from feat/ios-weather-widget to main September 16, 2026 15:11
@YinCheng0106
YinCheng0106 marked this pull request as draft September 16, 2026 15:26
@YinCheng0106
YinCheng0106 marked this pull request as ready for review September 16, 2026 15:26
Copilot AI lite review requested due to automatic review settings September 16, 2026 15:26

This comment was marked as resolved.

This comment was marked as resolved.

@lowrt lowrt added this to the v26.3 milestone Sep 17, 2026
@YinCheng0106
YinCheng0106 force-pushed the feat/ios-widget-current-weather branch 2 times, most recently from e2c3fd2 to 4542ada Compare September 19, 2026 09:13
@codecov

codecov Bot commented Sep 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.21%. Comparing base (7766ff5) to head (e27ee6a).

Files with missing lines Patch % Lines
lib/features/home/home_providers.dart 30.00% 14 Missing ⚠️
lib/features/weather/weather_providers.dart 0.00% 5 Missing ⚠️
lib/bootstrap.dart 0.00% 1 Missing ⚠️
lib/core/error/failure.dart 0.00% 1 Missing ⚠️
lib/core/platform/widget_snapshot_writer.dart 96.15% 1 Missing ⚠️

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@YinCheng0106

Copy link
Copy Markdown
Author

UI 調整

  • observationTime(觀測時間) 放在 regionName (區域名稱)下方
  • 右上 condition icon 放大,與 condition DisplayName 垂直排列

Old:

old small widget

Updated:

new small widget

其他資料部分顯示將會規劃成其他Widget(small、medium、large、ExtraLarge),避免資訊過度擁擠,可讀信下降

@YinCheng0106
YinCheng0106 force-pushed the feat/ios-widget-current-weather branch from fcc09b2 to e647478 Compare September 20, 2026 04:15
Platform: ios

New(zh-Hant): iOS 小工具可顯示 DPIP 所選地區的目前天氣
New(en-US): iOS widgets can show current weather for the area selected in DPIP
Platform: ios

New(zh-Hant): iOS 天氣小工具新增天氣圖示、資料狀態與點擊開啟首頁
New(en-US): iOS weather widgets add condition icons, data states, and Home deep linking
Platform: ios

New(zh-Hant): iOS 天氣小工具可依日出日落自動切換日夜天氣圖示
New(en-US): iOS weather widgets can switch day and night icons based on sunrise and sunset
Platform: ios

New(zh-Hant): iOS 天氣小工具支援繁體中文與英文介面
New(en-US): iOS weather widgets support Traditional Chinese and English
Fix(zh-Hant): 修正天氣請求競態造成舊資料覆蓋新資料
Fix(en-US): Prevent stale weather requests from overwriting newer data
Platform: ios

Fix(zh-Hant): 啟動時清除尚未驗證地區的舊天氣小工具資料
Fix(en-US): Clear unverified weather widget snapshots on app startup
Platform: ios

Fix(zh-Hant): 修正未校時與裝置時間偏移造成的小工具時間誤差
Fix(en-US): Calibrate widget timing and reject unsynced weather snapshots
Platform: ios

Fix(zh-Hant): 天氣小工具改用本地化的語意天氣狀態
Fix(en-US): Show localized semantic weather conditions in iOS widgets
Platform: ios

Fix(zh-Hant): 調整目前天氣小工具的資訊層級,保留觀測時間與天氣狀態並強化天氣圖示
Fix(en-US): Refine the current weather widget hierarchy while preserving observation time and weather condition
@PiscesXD

Copy link
Copy Markdown
Member

如果在首頁切到全國 並查看 小組件 會出現 尚無天氣資料
看能不能弄成所在地的?

@YinCheng0106

Copy link
Copy Markdown
Author

如果在首頁切到全國 並查看 小組件 會出現 尚無天氣資料 看能不能弄成所在地的?

後續PR會直接覆蓋掉這一個問題 會改成利用Widget 設定來實現切換地區功能
預設是「所在地」

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ios Issues or pull requests related to the iOS platform. size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants