feat: Update showToast function to support options object and improve notification handling

fix: Adjust modal max-height for better responsiveness
This commit is contained in:
Will Miao
2025-08-22 08:18:43 +08:00
parent 52fa88b04c
commit 331ad8f644
3 changed files with 56 additions and 14 deletions

View File

@@ -23,7 +23,7 @@ body.modal-open {
position: relative;
max-width: 800px;
height: auto;
/* max-height: calc(90vh - 48px); */
max-height: calc(90vh);
margin: 1rem auto; /* Keep reduced top margin */
background: var(--lora-surface);
border-radius: var(--border-radius-base);

View File

@@ -171,10 +171,20 @@ app.registerExtension({
if (foundPaths.length === 1) {
// Single match found - success
showToast(`Updated path for ${fileName}: ${firstPath}`, 'info');
showToast({
severity: 'info',
summary: 'LoRA Manager Path Correction',
detail: `Updated path for ${fileName}: ${firstPath}`,
life: 5000
});
} else {
// Multiple matches found - warning
showToast(`Multiple paths found for ${fileName}, using: ${firstPath}`, 'warning');
showToast({
severity: 'warn',
summary: 'LoRA Manager Path Correction',
detail: `Multiple paths found for ${fileName}, using: ${firstPath}`,
life: 5000
});
}
// Mark node as modified

View File

@@ -25,21 +25,53 @@ export function getComfyUIFrontendVersion() {
/**
* Show a toast notification
* @param {string} message - The message to display
* @param {string} type - The type of toast (success, error, info, warning)
* @param {Object|string} options - Toast options object or message string for backward compatibility
* @param {string} [options.severity] - Message severity level (success, info, warn, error, secondary, contrast)
* @param {string} [options.summary] - Short title for the toast
* @param {any} [options.detail] - Detailed message content
* @param {boolean} [options.closable] - Whether user can close the toast (default: true)
* @param {number} [options.life] - Duration in milliseconds before auto-closing
* @param {string} [options.group] - Group identifier for managing related toasts
* @param {any} [options.styleClass] - Style class of the message
* @param {any} [options.contentStyleClass] - Style class of the content
* @param {string} [type] - Deprecated: severity type for backward compatibility
*/
export function showToast(message, type = 'info') {
export function showToast(options, type = 'info') {
// Handle backward compatibility: showToast(message, type)
if (typeof options === 'string') {
options = {
detail: options,
severity: type
};
}
// Set defaults
const toastOptions = {
severity: options.severity || 'info',
summary: options.summary,
detail: options.detail,
closable: options.closable !== false, // default to true
life: options.life,
group: options.group,
styleClass: options.styleClass,
contentStyleClass: options.contentStyleClass
};
// Remove undefined properties
Object.keys(toastOptions).forEach(key => {
if (toastOptions[key] === undefined) {
delete toastOptions[key];
}
});
if (app && app.extensionManager && app.extensionManager.toast) {
app.extensionManager.toast.add({
severity: type,
summary: type.charAt(0).toUpperCase() + type.slice(1),
detail: message,
life: 3000
});
app.extensionManager.toast.add(toastOptions);
} else {
console.log(`${type.toUpperCase()}: ${message}`);
const message = toastOptions.detail || toastOptions.summary || 'No message';
const severity = toastOptions.severity.toUpperCase();
console.log(`${severity}: ${message}`);
// Fallback alert for critical errors only
if (type === 'error') {
if (toastOptions.severity === 'error') {
alert(message);
}
}