fix(notify): open the activity view when an alert is tapped - #242
fix(notify): open the activity view when an alert is tapped#242TimeToBuildBob wants to merge 4 commits into
Conversation
ActivityWatch#225 already attached a MainActivity PendingIntent, so the notification no longer did nothing — but the extra was missing, so a tap still landed on dashboard home instead of the Activity drawer destination (/#/activity/unknown/). Pass EXTRA_OPEN_ACTIVITY_VIEW, honor it on cold start and onNewIntent (SINGLE_TOP), and share the URL with the drawer item so the two cannot drift.
If the process was killed, onCreate restores the previous fragment and used to return before reading EXTRA_OPEN_ACTIVITY_VIEW, so a notification tap could land on dashboard home. Replace the restored fragment when the extra is set, and consume it so a later rotation does not reload the WebView.
Greptile SummaryThe PR routes activity-time notification taps to the dashboard Activity view while safely handling cold starts, resumed activities, stopped activities, and process restoration.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the unsafe stopped-instance commit is deferred until Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
N[Activity-time notification tapped] --> M{MainActivity instance exists?}
M -- No --> C[Cold start in onCreate]
C --> A[Open Activity view and consume extra]
M -- Yes --> I[Deliver through onNewIntent]
I --> R{Activity resumed?}
R -- Yes --> A
R -- No --> D[Retain extra until onResume]
D --> A
Reviews (3): Last reviewed commit: "fix(notify): handle taps while activity ..." | Re-trigger Greptile |
🤖 AI code reviewAdds EXTRA_OPEN_ACTIVITY_VIEW extra to notification intents and loads the activity view URL in MainActivity when present. Refactors fragment creation into showWebUi, adds onNewIntent to set the new intent without committing fragments, and updates NotifyWorker to set SINGLE_TOP and the extra. Confidence Score: 3/5 — One P1 finding1 finding · ❌ **1** P1 — 🛑 **1 at P0/P1**❌ P1 high — When MainActivity is already in the foreground (resumed) and a notification is tapped, the system delivers the new intent via onNewIntent without calling onResume again. Since this PR processes EXTRA_OPEN_ACTIVITY_VIEW only in onCreate (cold start) and onResume (line 173), the extra is never consumed and the activity view does not open. The comment in onNewIntent (lines 143-144) claims commit() would throw, but onNewIntent can be called while the activity is resumed, so a fragment transaction is safe. The fix is to handle the extra in onNewIntent, e.g., by replacing the fragment immediately when the activity is in the resumed state, or setting a flag to be processed in a later lifecycle callback that is guaranteed to run. How this was verified: Traced the lifecycle: onResume's takeOpenActivityView(intent) is the only other consumer; with the extra gone, it returns false and skips showWebUi(replace=true). The saved instance state path (savedInstanceState != null) returns early in onCreate without adding a fragment, so the restored fragment is whatever the user had navigated to. Consensus: 3/3 passes agreed Files changed (3) — the diff as I read it
Previous review passes
Reviewed Maintainer commands
|
onNewIntent runs while MainActivity is still stopped, after onSaveInstanceState. commit() there throws IllegalStateException when the user taps a notification on a backgrounded app. Stash the intent and replace the fragment in onResume, which is also the process-death restore path.
|
@greptileai review |
|
@greptileai review |
|
CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click. This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted. |
Problem
#225 attached a
MainActivityPendingIntent, so tapping an activity-time alert no longer did nothing. It still opened dashboard home (http://127.0.0.1:5600) rather than the Activity view.Fix
EXTRA_OPEN_ACTIVITY_VIEWon the existing NotifyWorker PendingIntentFLAG_ACTIVITY_SINGLE_TOPso a runningMainActivitygetsonNewIntentinstead of stacking/#/activity/unknown/)savedInstanceStaterestore) and consume it so rotation does not reload the WebView#234 also edits
NotifyWorker.kt, but onlyparseCategorySeconds. This PR only changessendNotification. Should merge cleanly.Fixes #224