Allow plugins to be installed from URL queries

This commit is contained in:
JannisX11 2022-11-25 23:30:58 +01:00
parent 5bf9f5a88d
commit dc33f59d0f
3 changed files with 39 additions and 2 deletions

View File

@ -71,12 +71,46 @@ try {
if (!Blockbench.isMobile) $('#web_download_button').hide();
}
function loadInfoFromURL() {
async function loadInfoFromURL() {
if (Blockbench.queries.session) {
EditSession.token = Blockbench.queries.session;
BarItems.edit_session.click();
}
if (Blockbench.queries.plugins) {
let plugin_ids = Blockbench.queries.plugins.split(/,/);
let plugins = plugin_ids.map(id => Plugins.all.find(plugin => plugin.id == id)).filter(p => p instanceof Plugin && p.installed == false);
if (plugins.length) {
await new Promise(resolve => {
let form = {
info: {type: 'info', text: 'dialog.load_plugins_from_query.text'}
}
plugins.forEach(plugin => {
form[plugin.id] = {type: 'checkbox', label: plugin.name, description: plugin.description, value: true}
})
new Dialog({
id: 'load_plugins_from_query',
title: 'dialog.load_plugins_from_query.title',
form,
buttons: ['dialog.plugins.install', 'dialog.cancel'],
onConfirm: async function(result) {
let promises = [];
plugins.forEach(plugin => {
if (result[plugin.id]) {
promises.push(plugin.download());
}
})
await Promise.all(promises);
resolve();
},
onCancel() {
resolve();
}
}).show();
})
}
}
if (Blockbench.queries.m) {
$.getJSON(`https://blckbn.ch/api/models/${Blockbench.queries.m}`, (model) => {
Codecs.project.load(model, {path: ''});

File diff suppressed because one or more lines are too long

View File

@ -483,6 +483,9 @@
"dialog.plugins.author": "by %0",
"dialog.plugins.show_less": "Show Less",
"dialog.load_plugins_from_query.title": "Load Plugins",
"dialog.load_plugins_from_query.text": "You used a link that requires plugins to be installed. Would you like to install them?",
"dialog.toolbar_edit.title": "Customize Toolbar",
"dialog.toolbar_edit.hidden": "Hidden",
"dialog.toolbar_edit.hidden_tools": "Some tools might be hidden because they are not available in the current mode, format, or situation.",