@pipelab/plugin-construct 1.0.0-beta.23 → 1.0.0-beta.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/script.ts +36 -28
- package/dist/index.cjs +204 -109
- package/dist/index.mjs +145 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/assets/script.ts
CHANGED
|
@@ -31,7 +31,7 @@ export const script = async (
|
|
|
31
31
|
method: "POST",
|
|
32
32
|
body: formData,
|
|
33
33
|
});
|
|
34
|
-
const json = await res.json() as any;
|
|
34
|
+
const json = (await res.json()) as any;
|
|
35
35
|
if (json.request.status !== "ok") {
|
|
36
36
|
throw new Error(json.request.errorMessage || "Invalid credentials");
|
|
37
37
|
}
|
|
@@ -43,28 +43,31 @@ export const script = async (
|
|
|
43
43
|
await page.goto("https://account.construct.net/");
|
|
44
44
|
|
|
45
45
|
// Inject token into IndexedDB
|
|
46
|
-
await page.evaluate(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
46
|
+
await page.evaluate(
|
|
47
|
+
async ({ userID, token }) => {
|
|
48
|
+
return new Promise<void>((resolve, reject) => {
|
|
49
|
+
const request = indexedDB.open("localforage", 1);
|
|
50
|
+
request.onerror = () => reject(new Error("Failed to open DB"));
|
|
51
|
+
request.onsuccess = (e: any) => {
|
|
52
|
+
const db = e.target.result;
|
|
53
|
+
try {
|
|
54
|
+
const transaction = db.transaction(["keyvaluepairs"], "readwrite");
|
|
55
|
+
const store = transaction.objectStore("keyvaluepairs");
|
|
56
|
+
const putRequest = store.put({ userID, token }, "login-data");
|
|
57
|
+
putRequest.onsuccess = () => resolve();
|
|
58
|
+
putRequest.onerror = () => reject(new Error("Failed to put item"));
|
|
59
|
+
} catch (err) {
|
|
60
|
+
reject(err);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
request.onupgradeneeded = (e: any) => {
|
|
64
|
+
const db = e.target.result;
|
|
65
|
+
db.createObjectStore("keyvaluepairs");
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
{ userID, token },
|
|
70
|
+
);
|
|
68
71
|
log("Credentials injected successfully.");
|
|
69
72
|
}
|
|
70
73
|
|
|
@@ -109,10 +112,15 @@ export const script = async (
|
|
|
109
112
|
log("Got loading progress dialog");
|
|
110
113
|
|
|
111
114
|
const progressInterval = setInterval(async () => {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
try {
|
|
116
|
+
const text = await progessBar.getAttribute("value", { timeout: 100 });
|
|
117
|
+
if (text === null) return;
|
|
118
|
+
const textAsNumber = parseFloat(text);
|
|
119
|
+
const finalText = Number.isNaN(textAsNumber) ? 0 : textAsNumber;
|
|
120
|
+
log("progress", `${finalText * 100}%`);
|
|
121
|
+
} catch {
|
|
122
|
+
clearInterval(progressInterval);
|
|
123
|
+
}
|
|
116
124
|
}, 500);
|
|
117
125
|
|
|
118
126
|
registerInstallButtonListener(page, log);
|
|
@@ -127,7 +135,7 @@ export const script = async (
|
|
|
127
135
|
timeout: 0,
|
|
128
136
|
});
|
|
129
137
|
log("Got progress dialog to disapear");
|
|
130
|
-
|
|
138
|
+
clearInterval(progressInterval);
|
|
131
139
|
|
|
132
140
|
await page.getByRole("button", { name: "Menu" }).click();
|
|
133
141
|
await page.getByRole("menuitem", { name: "Project" }).click();
|