woodpecker-test/example/menu/connect.js

56 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2022-11-06 20:39:28 +01:00
import l1 from "../../stear/extra/Elements/loading1.js";
import showStatus from "../../stear/extra/Pages/showStatus.js";
import { Stear, SWindow, _ } from "../../stear/main.js";
import { fadein, fadeout, wait } from "../../stear/utils.js";
const pool = Stear.addLanguagePool("connect");
const connectingto = pool.add("connectingto", "Connecting to: {} ({})");
const connected = pool.add("connected", "connected");
const connecterror = pool.add("connecterror", "Error while Connecting to: {}");
export const call = async (stear, { find, resolve, render, call, event }, {name,id}) => {
event.onloaded = async ()=>{
await fadein(find.main, 200, true);
//do connection
await wait(1000);
if (Math.random() > 0.25) {
call(showStatus, { text: connected });
return resolve(true);
} else {
call(showStatus, { text: connecterror.r(name), color: "red" });
return resolve(false);
}
};
event.onresolve = async ()=>{
await fadeout(find.main);
}
return _({ find: "main" }, [
_({
type: "p",
style: {
position: "absolute",
minWidth: "90%",
textAlign: "center",
top: "25%",
left: "50%",
transform: "translate(-50%,-50%)",
}
}, connectingto.r(name, id)),
_({
style: {
position: "absolute",
left: "50%",
top: "50%",
transform: "translate(-50%, -50%)",
}
}, l1())
]);
}
export default new SWindow({ preRender: true, call, backgroundColor: "#dde" });