protected-resources-list/plugins/updates/plugin.js

22 lines
976 B
JavaScript

import {JSONRPC} from "/assets/jrpc.js";
(async function () {
$("#panel").prepend(`<div id="update-panel">Checking for updates...</div><hr>`);
let state = (await JSONRPC.__invoke("updates::check"));
if (state === null) {
$("#update-panel").html(`<span style="color:red;">Error checking updates</span>`);
} else if (state === false) {
$("#update-panel").html(`<span style="color:black;">There is no updates</span>`);
} else if (state === true) {
$("#update-panel").html(`<span style="color:green;">Some updates are available</span>&nbsp;<button>Update</button>`);
$("#update-panel button").click(async function () {
$("#panel").hide();
$("#loading").show().text("Installing updates...");
try {
console.log(await JSONRPC.__invoke("updates::install"));
} finally {
setTimeout(() => location.reload(), 10000);
}
});
}
})();