-
Notifications
You must be signed in to change notification settings - Fork 48
fix: improve Toast and add InAppBrowser dark mode for V2EX #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR improves the Toast component's visual design and consecutive display handling, while also adding automatic dark mode CSS injection for V2EX pages in the InAppBrowser.
Key Changes:
- Toast shadow made lighter (opacity 0.3 → 0.12) with improved positioning for a softer appearance
- Added version tracking to properly reset toast timers when consecutive toasts appear with the same
isPresentedstate - Implemented dark mode CSS injection for V2EX and v2er.app domains when the app is in dark mode
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| V2er/View/Widget/Toast.swift | Added version property to track toast updates and trigger timer resets; updated shadow for softer appearance |
| V2er/State/DataFlow/Actions/GlobalActions.swift | Increment toast version on each ShowToastAction to ensure onChange handlers detect new toasts |
| V2er/View/Login/LoginPage.swift | Pass toast version to the toast view modifier to enable timer reset functionality |
| V2er/General/RootView.swift | Pass toast version to the toast view modifier to enable timer reset functionality |
| V2er/View/InAppBrowserView.swift | Added dark mode detection and CSS injection for V2EX pages in the InAppBrowser |
| background-color: #444 !important; | ||
| } | ||
| """ | ||
| let js = "var style = document.createElement('style'); style.innerHTML = `\(darkModeCSS)`; document.head.appendChild(style);" |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CSS string is embedded in a JavaScript template literal using string interpolation. While the current hardcoded CSS is safe, this pattern is fragile—if the CSS string ever contains backticks (`) or template literal expressions (${...}), it could break the JavaScript or create an injection vulnerability. Consider using proper escaping or a safer injection method, such as replacing backticks with escaped backticks in the CSS string before interpolation.
| let js = "var style = document.createElement('style'); style.innerHTML = `\(darkModeCSS)`; document.head.appendChild(style);" | |
| let safeDarkModeCSS = darkModeCSS | |
| .replacingOccurrences(of: "\\", with: "\\\\") | |
| .replacingOccurrences(of: "`", with: "\\`") | |
| .replacingOccurrences(of: "${", with: "\\${") | |
| let js = "var style = document.createElement('style'); style.innerHTML = `\(safeDarkModeCSS)`; document.head.appendChild(style);" |
| background-color: #444 !important; | ||
| } | ||
| """ | ||
| let js = "var style = document.createElement('style'); style.innerHTML = `\(darkModeCSS)`; document.head.appendChild(style);" |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dark mode CSS is injected on every page load completion without checking if it was already injected. This could result in duplicate style tags if a page reloads or navigates within the same webView. Consider checking if the styles are already present or using a unique ID on the style tag to prevent duplicates.
| let js = "var style = document.createElement('style'); style.innerHTML = `\(darkModeCSS)`; document.head.appendChild(style);" | |
| let js = """ | |
| if (!document.getElementById('v2er-dark-mode-style')) { | |
| var style = document.createElement('style'); | |
| style.id = 'v2er-dark-mode-style'; | |
| style.innerHTML = `\(darkModeCSS)`; | |
| document.head.appendChild(style); | |
| } | |
| """ |
Code Coverage Report ❌Current coverage: 30.24% |
Toast improvements: - Reduce shadow opacity from 0.3 to 0.12 for softer appearance - Add version tracking to fix consecutive toast not clearing issue - Reset dismiss timer when new toast content arrives InAppBrowser improvements: - Add dark mode CSS injection for V2EX pages when app is in dark mode - Auto-detect app's appearance setting and apply matching theme - Comprehensive styling: boxes, cells, tags, links, code blocks, buttons, etc. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
364282c to
de25d0b
Compare
Code Coverage Report ❌Current coverage: 31.01% |
Summary
Changes
Toast Improvements
versionproperty to track toast updatesisPresentedstays true)InAppBrowser Dark Mode
Test plan
🤖 Generated with Claude Code