Should work apart from CORS issues
This commit is contained in:
parent
e68a498cb3
commit
4e9f97abfb
2 changed files with 37 additions and 5 deletions
|
@ -1,10 +1,20 @@
|
|||
// This file handles the "Confirm instance details" dialog
|
||||
|
||||
import { resize } from "./image.mjs";
|
||||
import knownSoftware from "./known_software.mjs";
|
||||
|
||||
const blankImage = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
|
||||
|
||||
export function initializeInstanceDetailsDialog(dialog: HTMLDialogElement): {
|
||||
export function initializeInstanceDetailsDialog(
|
||||
dialog: HTMLDialogElement,
|
||||
callback: (
|
||||
instanceName: string,
|
||||
instanceHost: string,
|
||||
instanceHostSecure: boolean,
|
||||
instanceSoftware: string,
|
||||
instanceIcon: string | null
|
||||
) => void
|
||||
): {
|
||||
showInstanceDetailsDialog: () => void,
|
||||
hideInstanceDetailsDialog: () => void,
|
||||
populateInstanceDetailsDialog: (
|
||||
|
@ -13,7 +23,7 @@ export function initializeInstanceDetailsDialog(dialog: HTMLDialogElement): {
|
|||
instanceHostSecureValue: boolean,
|
||||
instanceSoftwareValue: string,
|
||||
instanceIconValue: string | null
|
||||
) => void,
|
||||
) => void
|
||||
} {
|
||||
const showInstanceDetailsDialog = () => dialog.showModal();
|
||||
const hideInstanceDetailsDialog = () => dialog.close();
|
||||
|
@ -61,10 +71,16 @@ export function initializeInstanceDetailsDialog(dialog: HTMLDialogElement): {
|
|||
instanceHostSecure.checked = instanceHostSecureValue;
|
||||
instanceSoftware.value = instanceSoftwareValue;
|
||||
instanceIcon.src = instanceIconValue ?? blankImage;
|
||||
|
||||
};
|
||||
|
||||
form.addEventListener("submit", e => {
|
||||
callback(
|
||||
instanceName.value,
|
||||
instanceHost.value,
|
||||
instanceHostSecure.checked,
|
||||
instanceSoftware.value,
|
||||
instanceIcon.src == blankImage ? null : resize(instanceIcon)
|
||||
);
|
||||
form.reset();
|
||||
});
|
||||
|
||||
|
|
|
@ -10,6 +10,21 @@ export function getMainDialog(): HTMLDialogElement {
|
|||
return document.getElementById('mainDialog') as HTMLDialogElement;
|
||||
}
|
||||
|
||||
const instanceDetailsDialogCallback = (
|
||||
name: string,
|
||||
host: string,
|
||||
hostSecure: boolean,
|
||||
software: string,
|
||||
icon: string | null
|
||||
) => {
|
||||
storageManager.storage.instances.push({
|
||||
name,
|
||||
origin: `http${hostSecure ? "s" : ""}://${host}`,
|
||||
software,
|
||||
iconURL: icon ?? undefined
|
||||
});
|
||||
};
|
||||
|
||||
const detailsDialog = document.querySelector("#instanceDetails");
|
||||
if (!(detailsDialog instanceof HTMLDialogElement))
|
||||
throw new Error("Couldn't find instanceDetails dialog");
|
||||
|
@ -17,7 +32,7 @@ export const {
|
|||
showInstanceDetailsDialog,
|
||||
hideInstanceDetailsDialog,
|
||||
populateInstanceDetailsDialog
|
||||
} = initializeInstanceDetailsDialog(detailsDialog);
|
||||
} = initializeInstanceDetailsDialog(detailsDialog, instanceDetailsDialogCallback);
|
||||
|
||||
const addInstanceDialogCallback = async (
|
||||
host: string,
|
||||
|
@ -36,8 +51,9 @@ const addInstanceDialogCallback = async (
|
|||
)
|
||||
throw new Error("Invalid API response");
|
||||
populateInstanceDetailsDialog(name, host, secure, software, iconURL as string | null);
|
||||
} finally {
|
||||
} catch {
|
||||
populateInstanceDetailsDialog("", host, secure, "", null);
|
||||
} finally {
|
||||
showInstanceDetailsDialog();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue