Compare commits

..

No commits in common. "master" and "0.4.0" have entirely different histories.

2 changed files with 34 additions and 29 deletions

View file

@ -75,17 +75,19 @@ class Monkey {
// Install a Monkeydo manifest // Install a Monkeydo manifest
async loadManifest(manifest) { async loadManifest(manifest) {
if(typeof manifest !== "object") { return await new Promise((resolve,reject) => {
try { if(typeof manifest !== "object") {
manifest = JSON.parse(manifest); try {
manifest = JSON.parse(manifest);
}
catch {
reject("Failed to load manifest");
}
} }
catch { this.tasks.manifest = manifest.tasks;
Promise.reject("Failed to load manifest"); this.flags[0] = 1; // Manifest loaded: true
} resolve();
} });
this.tasks.manifest = manifest.tasks;
this.flags[0] = 1; // Manifest loaded: true
return true;
} }
} }

View file

@ -48,12 +48,14 @@ export default class MonkeyMaster {
this.comlink = await new Monkey(); this.comlink = await new Monkey();
// Wait for comlink to spin up // Wait for comlink to spin up
if(!this.comlink) Promise.reject("Failed to establish Comlink with worker"); return await new Promise((resolve,reject) => {
if(!this.comlink) reject("Failed to establish Comlink with worker");
this.ready = true; this.ready = true;
// Send queued flags when worker is ready // Send queued flags when worker is ready
this.queue.sendAllFlags(); this.queue.sendAllFlags();
return true; resolve();
});
} }
// Return a flag array index by name // Return a flag array index by name
@ -102,20 +104,21 @@ export default class MonkeyMaster {
// Load a Monkeydo manifest by URL or JSON string // Load a Monkeydo manifest by URL or JSON string
async loadManifest(manifest) { async loadManifest(manifest) {
if(!this.ready) await this.init(); if(!this.ready) await this.init();
let load = null; return await new Promise((resolve,reject) => {
// Attempt load string as URL and fetch manifest let load = null;
try { // Attempt load string as URL and fetch manifest
const url = new URL(manifest); try {
// If the URL parsed but fetch failed, this promise will reject const url = new URL(manifest);
load = this.comlink.fetchManifest(url.toString()); // If the URL parsed but fetch failed, this promise will reject
} load = this.comlink.fetchManifest(url.toString());
// Or attempt to load string as JSON if it's not a URL }
catch { // Or attempt to load string as JSON if it's not a URL
load = this.comlink.loadManifest(manifest); catch {
} load = this.comlink.loadManifest(manifest);
}
load.then(() => Promise.resolve()) load.then(() => resolve())
.catch(() => Promise.reject("Failed to load manifest")); .catch(() => reject("Failed to load manifest"));
});
} }
async stop() { async stop() {