add default sync sheme
This commit is contained in:
parent
d25ce49ede
commit
995513c9b8
@ -1,9 +1,20 @@
|
||||
import { requestAPI } from "./utils.js";
|
||||
|
||||
export async function setupClientSync (scheme, rate, callback) {
|
||||
export async function setupClientSync (callback) {
|
||||
let scheme = localStorage.getItem("sync-scheme");
|
||||
let rate = Number(localStorage.getItem("sync-rate"));
|
||||
if (!scheme) {
|
||||
scheme = "always";
|
||||
localStorage.setItem("sync-scheme", "always");
|
||||
}
|
||||
if (!rate) {
|
||||
rate = "5";
|
||||
localStorage.setItem("sync-rate", "5")
|
||||
}
|
||||
|
||||
if (scheme === "always") {
|
||||
callback();
|
||||
window.setInterval(callback, rate);
|
||||
window.setInterval(callback, rate * 1000);
|
||||
}
|
||||
else if (scheme === "hash") {
|
||||
const newHash = (await requestAPI("/sync/hash")).data;
|
||||
@ -15,7 +26,7 @@ export async function setupClientSync (scheme, rate, callback) {
|
||||
localStorage.setItem("sync-current-hash", newHash);
|
||||
callback();
|
||||
}
|
||||
}, rate);
|
||||
}, rate * 1000);
|
||||
}
|
||||
else if (scheme === "interrupt") {
|
||||
|
||||
|
@ -15,7 +15,7 @@ async function init () {
|
||||
const addInstanceBtn = document.querySelector("#instance-add");
|
||||
addInstanceBtn.addEventListener("click", handleInstanceAdd);
|
||||
|
||||
setupClientSync(localStorage.getItem("sync-scheme"), Number(localStorage.getItem("sync-rate")) * 1000, populateInstances);
|
||||
setupClientSync(populateInstances);
|
||||
}
|
||||
|
||||
async function populateInstances () {
|
||||
|
Loading…
Reference in New Issue
Block a user