Sfoglia il codice sorgente

added new progress event types

Gildas 7 anni fa
parent
commit
657eb8c71d
1 ha cambiato i file con 10 aggiunte e 0 eliminazioni
  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, "****");
 			}