Skip to main content

TaskManager

Import :

brackets.getModule("features/TaskManager")

features/TaskManager

TaskManager module deals with managing long running tasks in phcode. It handles the Tasks dropdown in the status bar where the user can see all running tasks, monitor its progress and close/pause the execution of the task if supported by the task.

features/TaskManager.renderSpinnerIcon()

determines what the spinner icon to show(green-for success), red-fail, blue normal based on the active tasks in list and renders. IF the active tasks has already been notified, it wont notify again.

Kind: inner method of features/TaskManager

features/TaskManager.addNewTask(taskTitle, message, [iconHTML], [options]) ⇒ TaskObject

The addNewTask is designed for adding new tasks to the task management system. This function is central to managing long-running tasks, providing a way to visually represent task progress, status, and control actions directly from the UI in the status bar.

Kind: inner method of features/TaskManager
Returns: TaskObject - Returns a task object with methods for updating the task's state and UI representation, such as setProgressPercent, setMessage, setSucceeded, setFailed, and control visibility methods like showStopIcon, hideStopIcon, etc.

ParamTypeDefaultDescription
taskTitlestringThe title of the task. This is a mandatory parameter and is displayed in the UI.
messagestringA message or status associated with the task. Displayed as additional information in the UI.
[iconHTML]stringnullOptional HTML string for the task's icon. Used to visually represent the task in the UI.
[options]ObjectOptional settings and callbacks for the task.
[options.onPauseClick]functionCallback function triggered when the pause button is clicked.
[options.onPlayClick]functionCallback function triggered when the play button is clicked.
[options.onStopClick]functionCallback function triggered when the stop button is clicked.
[options.onRetryClick]functionCallback function triggered when the retry button is clicked.
[options.onSelect]functionCallback function triggered when the task is selected from the dropdown.
[options.progressPercent]numberInitial progress percentage of the task.
[options.noSpinnerNotification]booleanIf set to true, will not show the task spinners for this task. This can be used for silent background tasks where user attention is not needed.

Example

// Example: Adding a new task with initial progress and attaching event handlers
const task = TaskManager.addNewTask(
'Data Processing',
'Processing data...',
'<i class="fa fa-spinner fa-spin"></i>',
{
onPauseClick: () => console.log('Task paused'),
onPlayClick: () => console.log('Task resumed'),
onStopClick: () => console.log('Task stopped'),
onRetryClick: () => console.log('Task retried'),
onSelect: () => console.log('Task selected'),
progressPercent: 20
}
);

// Updating task progress
task.setProgressPercent(60);

// Updating task message
task.setMessage('60% completed');

// Marking task as succeeded
task.setSucceeded();

features/TaskManager.TaskObject : Object

Methods for managing the task's state and UI representation in the TaskManager.

Kind: inner typedef of features/TaskManager
Properties

NameTypeDescription
showfunctionShows the task popup in the ui.
closefunctionCloses the task and removes it from the UI.
setTitlefunctionSets the task's title.
getTitlefunctionReturns the task's title.
setMessagefunctionSets the task's message.
getMessagefunctionReturns the task's message.
setProgressPercentfunctionSets the task's progress percentage.
getProgressPercentfunctionReturns the task's current progress percentage.
setFailedfunctionMarks the task as failed.
isFailedfunctionReturns true if the task is marked as failed.
setSuccededfunctionMarks the task as succeeded.
isSuccededfunctionReturns true if the task is marked as succeeded.
showStopIconfunctionShows the stop icon with an optional tooltip message.
hideStopIconfunctionHides the stop icon.
showPlayIconfunctionShows the play icon with an optional tooltip message.
hidePlayIconfunctionHides the play icon.
showPauseIconfunctionShows the pause icon with an optional tooltip message.
hidePauseIconfunctionHides the pause icon.
showRestartIconfunctionShows the restart (retry) icon with an optional tooltip message.
hideRestartIconfunctionHides the restart (retry) icon.
flashSpinnerForAttentionfunctionbriefly flashes the task spinner icon for attention.