Explorar o código

added new progress event types

Gildas %!s(int64=7) %!d(string=hai) anos
pai
achega
657eb8c71d
Modificáronse 1 ficheiros con 10 adicións e 0 borrados
  1. 10 0
      lib/single-file/single-file-core.js

+ 10 - 0
lib/single-file/single-file-core.js

@@ -67,6 +67,10 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 	const RESOURCES_INITIALIZED = "resources-initialized";
 	const RESOURCE_LOADED = "resource-loaded";
 	const PAGE_ENDED = "page-ended";
+	const STAGE_STARTED = "stage-started";
+	const STAGE_ENDED = "stage-ended";
+	const STAGE_TASK_STARTED = "stage-task-started";
+	const STAGE_TASK_ENDED = "stage-task-ended";
 
 	class ProgressEvent {
 		constructor(type, details) {
@@ -200,13 +204,16 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			if (DEBUG) {
 				log("**** STARTED STAGE", step, "****");
 			}
+			this.onprogress(new ProgressEvent(STAGE_STARTED, { pageURL: this.options.url, step }));
 			STAGES[step].sequential.forEach(task => {
 				let startTime;
 				if (DEBUG) {
 					startTime = Date.now();
 					log("  -- STARTED task =", task.action);
 				}
+				this.onprogress(new ProgressEvent(STAGE_TASK_STARTED, { pageURL: this.options.url, task: task.action }));
 				this.executeTask(task);
+				this.onprogress(new ProgressEvent(STAGE_TASK_ENDED, { pageURL: this.options.url, step, task: task.action }));
 				if (DEBUG) {
 					log("  -- ENDED   task =", task.action, "delay =", Date.now() - startTime);
 				}
@@ -218,13 +225,16 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 						startTime = Date.now();
 						log("  // STARTED task =", task.action);
 					}
+					this.onprogress(new ProgressEvent(STAGE_TASK_STARTED, { pageURL: this.options.url, task: task.action }));
 					const promise = this.executeTask(task);
+					promise.then(() => this.onprogress(new ProgressEvent(STAGE_TASK_ENDED, { pageURL: this.options.url, step, task: task.action })));
 					if (DEBUG) {
 						promise.then(() => log("  // ENDED task =", task.action, "delay =", Date.now() - startTime));
 					}
 					return promise;
 				}));
 			}
+			this.onprogress(new ProgressEvent(STAGE_ENDED, { pageURL: this.options.url, step }));
 			if (DEBUG) {
 				log("**** ENDED   STAGE", step, "****");
 			}