Skip to content

Commit dcd0239

Browse files
committed
feat(task-popup): added disapearing task popups
Signed-off-by: Evzen Gasta <evzen.ml@seznam.cz>
1 parent 53cd53d commit dcd0239

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

packages/renderer/src/lib/toast/ToastCustomUi.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ interface Props {
1414
1515
let { toastId, taskInfo, onpop = (): void => {} }: Props = $props();
1616
17-
const closeAction = (): void => {
17+
function hideToast(): void {
1818
toast.pop(toastId);
19+
}
20+
21+
const closeAction = (): void => {
22+
hideToast();
1923
onpop();
2024
};
2125
2226
const executeAction = async (): Promise<void> => {
27+
hideToast();
2328
await window.executeTask(taskInfo.id);
2429
};
2530
</script>

packages/renderer/src/lib/toast/ToastTaskNotifications.svelte

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const CONFIGURATION_KEY = `${ExperimentalTasksSettings.SectionName}.${Experiment
1919
// keep a local copy of the tasks with their toast id
2020
const currentTasks: TaskInfoWithToastId[] = $state([]);
2121
22+
// stores a list of long-duration tasks (60+ seconds) that have been completed and showed
23+
const showedAgainTasks: TaskInfoWithToastId[] = $state([]);
24+
2225
// is that the configuration is enabled or not, will be updated by configuration
2326
let enabled = $state(false);
2427
@@ -50,11 +53,23 @@ function handleTasks(tasks: TaskInfo[]): void {
5053
// replace the task in the currentTasks
5154
currentTasks.splice(currentTasks.indexOf(currentTask), 1, { ...taskInfo, toastId: currentTask.toastId });
5255
toast.set(currentTask.toastId, createToastOptions(taskInfo));
56+
57+
const time = Date.now();
58+
// The task is completed, was running for at least 60s and is not in already showed tasks
59+
if (
60+
taskInfo.state === 'completed' &&
61+
time >= taskInfo.started + 60000 &&
62+
!showedAgainTasks.find(currentTask => currentTask.id === taskInfo.id)
63+
) {
64+
displayNewToast(taskInfo);
65+
}
66+
showedAgainTasks.push(currentTask);
5367
}
5468
}
5569
5670
// remove from currentTasks all the items from deletedTasks
5771
for (const taskInfo of toDeleteTasks) {
72+
showedAgainTasks.splice(showedAgainTasks.indexOf(taskInfo), 1);
5873
currentTasks.splice(currentTasks.indexOf(taskInfo), 1);
5974
toast.pop(taskInfo.toastId);
6075
}
@@ -73,7 +88,6 @@ function createToastOptions(taskInfo: TaskInfo): SvelteToastOptions {
7388
sendIdTo: 'toastId',
7489
},
7590
dismissable: false,
76-
initial: 0,
7791
};
7892
}
7993

0 commit comments

Comments
 (0)