forked from HeyPuter/puter
-
Notifications
You must be signed in to change notification settings - Fork 155
feat: Enhanced alert system with multiple types and flexible configuration #32
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
Open
PrayagCodes
wants to merge
2
commits into
codepath:main
Choose a base branch
from
PrayagCodes:feat/enhanced-alert-system
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
…ation
Implement comprehensive alert system supporting multiple alert types (info,
success, warning, error, question) with type-specific icons and buttons,
string array button syntax, and custom UI content injection.
Features Added:
- Multiple alert types with appropriate icons
* Info: reminder icon
* Success: checkmark icon
* Warning: warning sign icon
* Error: danger icon
* Question: reminder icon
- Type-specific default buttons
* Question alerts default to Yes/No
* Warning alerts default to OK/Cancel
* Other types default to OK only
- String array button support
* Simple syntax: buttons: ['Save', 'Cancel']
* Auto-converts to button objects
* First button gets primary styling
* Returns clicked button text as value
- Modern SDK API with backward compatibility
* Object-style parameters: puter.ui.alert({ type, message, buttons })
* Legacy string/array parameters still supported
- Custom UI content injection
* Inject custom HTML between message and buttons
* HTML sanitization with safe tag allowlist (<strong>, <p>, <br>)
* Prevents XSS attacks while allowing basic formatting
Files modified:
- src/gui/src/UI/UIAlert.js: Icon mapping, button conversion, custom UI
- src/puter-js/src/modules/UI.js: Object-based API
- src/gui/src/IPC.js: CustomUI parameter forwarding
Breaking Changes: for exisitng alert usage
Example Usage:
// Typed alert with string array buttons
const choice = await puter.ui.alert({
type: 'question',
message: 'Save changes?',
buttons: ['Save', "Don't Save", 'Cancel']
});
// Custom UI content
puter.ui.alert({
type: 'info',
message: 'Upload Progress',
customUI: '<p><strong>File:</strong> doc.pdf</p><p>75% complete</p>'
});
israx
reviewed
Nov 8, 2025
israx
reviewed
Nov 8, 2025
israx
reviewed
Nov 8, 2025
israx
reviewed
Nov 8, 2025
israx
left a comment
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.
Looks good, we just need to be careful when dealing with different data types to avoid any possible bugs. Let's address the comments
- Remove redundant undefined check in IPC ALERT handler (lines 163-166) The outer condition already ensures message is defined - Fix data loss in IPC message normalization When event.data.message is a string (legacy format), pull buttons, type, and customUI from event.data.options to prevent data loss - Improve button array conversion logic in UIAlert Check each element type individually instead of assuming all elements match the first element's type. Handles mixed string/object arrays gracefully while maintaining backward compatibility
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.
Enhanced Alert System with Multi-Type Support and Custom UI
PR Overview
This pull request introduces a comprehensive enhancement to the Puter alert system, transforming it from a single-type warning dialog into a flexible, multi-purpose notification framework. The implementation adds support for five distinct alert types (info, success, warning, error, question), enables simplified button configuration through string arrays, introduces custom UI content injection, and provides a modern object-based API while maintaining complete backward compatibility with existing codebases.
Branch:
feat/enhanced-alert-systemType: Feature Enhancement
Complexity: Moderate
Closes Feature
Closes Issue #3 - [FEATURE] Add multiple alert box types and customization options #7
##Before
Video: https://cap.link/v677g7a9ps1c0nj
Key Changes
1. Multi-Type Alert System
Introduced five semantic alert types with distinct visual identities:
2. Intelligent Default Button Sets
Type-aware default button configurations eliminate boilerplate code:
3. String Array Button Syntax
Simplified button definition through string arrays with automatic conversion:
4. Object-Based API
Modern fluent API design with single object parameter:
5. Custom UI Content Injection
Extensible content area between message and buttons:
<strong>,<p>,<br>)Implementation
Video: https://cap.link/yc7j6957rfn3hmx
Architecture Overview
The alert system follows a three-layer architecture with cross-iframe communication:
Implementation Details
Type-Specific Default Buttons
String Array Conversion
Icon Mapping System
API Flexibility
Custom UI Sanitization
IPC Message Normalization
Design Philosophy
Non-Breaking Evolution - Every enhancement layers atop existing functionality rather than replacing it. Type system added through icon lookup, button arrays through preprocessing, custom UI through template injection.
Security-First - Custom UI uses allowlist-based sanitization assuming all input is malicious. Only explicitly verified formatting tags render, preventing XSS vulnerabilities.
Semantic Type System - Alert types match universal UX patterns (info, success, warning, error, question) found across all major platforms for immediate developer intuitiveness.
Progressive API - Object-based API introduced as alternative, not replacement. Developers can use positional parameters indefinitely, adopt object syntax selectively, or mix both styles.
Testing
After: https://cap.link/fv5wvbnhrptwxbs
Manual Testing Checklist
Type System Verification:
Button Functionality:
Default Button Behavior:
API Compatibility:
alert('message')string syntax worksalert({ message, type, buttons })syntax worksCustom UI:
<strong>,<p>,<br>) render correctlyIntegration:
Breaking Changes
None. This implementation maintains complete backward compatibility.
Compatibility Analysis
Existing Call Patterns:
puter.ui.alert('message')- Continues to work identicallyputer.ui.alert('message', [buttons])- Continues to work identicallyputer.ui.alert('message', [buttons], {options})- Continues to work identicallyUIAlert('message')- Internal usage unaffectedUIAlert({message, buttons})- Internal usage unaffectedBehavioral Consistency:
Risk Assessment:
Migration Path: None required. Applications can adopt new features incrementally without modifying existing alert calls.
Files Modified:
src/gui/src/UI/UIAlert.js- Core alert rendering logicsrc/puter-js/src/modules/UI.js- SDK public APIsrc/gui/src/IPC.js- Cross-frame message handling