Make progressDialog return a promise
This way the continuation hasn't to be passed as argument.
This commit is contained in:
parent
78ef0c1682
commit
706ea7c758
@ -131,17 +131,19 @@ var g_ModIOState = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function init(data)
|
async function init(data)
|
||||||
{
|
{
|
||||||
progressDialog(
|
const promise = progressDialog(
|
||||||
translate("Initializing mod.io interface."),
|
translate("Initializing mod.io interface."),
|
||||||
translate("Initializing"),
|
translate("Initializing"),
|
||||||
false,
|
false,
|
||||||
translate("Cancel"),
|
translate("Cancel"));
|
||||||
closePage);
|
|
||||||
|
|
||||||
g_Failure = false;
|
g_Failure = false;
|
||||||
Engine.ModIoStartGetGameId();
|
Engine.ModIoStartGetGameId();
|
||||||
|
|
||||||
|
await promise;
|
||||||
|
closePage();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTick()
|
function onTick()
|
||||||
@ -242,44 +244,48 @@ function cancelModListUpdate()
|
|||||||
Engine.GetGUIObjectByName('refreshButton').enabled = true;
|
Engine.GetGUIObjectByName('refreshButton').enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateModList()
|
async function updateModList()
|
||||||
{
|
{
|
||||||
clearModList();
|
clearModList();
|
||||||
Engine.GetGUIObjectByName("refreshButton").enabled = false;
|
Engine.GetGUIObjectByName("refreshButton").enabled = false;
|
||||||
|
|
||||||
progressDialog(
|
const promise = progressDialog(
|
||||||
translate("Fetching and updating list of available mods."),
|
translate("Fetching and updating list of available mods."),
|
||||||
translate("Updating"),
|
translate("Updating"),
|
||||||
false,
|
false,
|
||||||
translate("Cancel Update"),
|
translate("Cancel Update"));
|
||||||
cancelModListUpdate);
|
|
||||||
|
|
||||||
g_Failure = false;
|
g_Failure = false;
|
||||||
g_RequestCancelled = false;
|
g_RequestCancelled = false;
|
||||||
Engine.ModIoStartListMods();
|
Engine.ModIoStartListMods();
|
||||||
|
|
||||||
|
await promise;
|
||||||
|
cancelModListUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadMod()
|
async function downloadMod()
|
||||||
{
|
{
|
||||||
let selected = selectedModIndex();
|
let selected = selectedModIndex();
|
||||||
|
|
||||||
if (isSelectedModInvalid(selected))
|
if (isSelectedModInvalid(selected))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
progressDialog(
|
const promise = progressDialog(
|
||||||
sprintf(translate("Downloading “%(modname)s”"), {
|
sprintf(translate("Downloading “%(modname)s”"), {
|
||||||
"modname": g_ModsAvailableOnline[selected].name
|
"modname": g_ModsAvailableOnline[selected].name
|
||||||
}),
|
}),
|
||||||
translate("Downloading"),
|
translate("Downloading"),
|
||||||
true,
|
true,
|
||||||
translate("Cancel Download"),
|
translate("Cancel Download"));
|
||||||
() => { Engine.GetGUIObjectByName("downloadButton").enabled = true; });
|
|
||||||
|
|
||||||
Engine.GetGUIObjectByName("downloadButton").enabled = false;
|
Engine.GetGUIObjectByName("downloadButton").enabled = false;
|
||||||
|
|
||||||
g_Failure = false;
|
g_Failure = false;
|
||||||
g_RequestCancelled = false;
|
g_RequestCancelled = false;
|
||||||
Engine.ModIoStartDownloadMod(selected);
|
Engine.ModIoStartDownloadMod(selected);
|
||||||
|
|
||||||
|
await promise;
|
||||||
|
Engine.GetGUIObjectByName("downloadButton").enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelRequest()
|
function cancelRequest()
|
||||||
@ -304,7 +310,7 @@ function showErrorMessageBox(caption, title, buttonCaptions)
|
|||||||
return messageBox(500, 250, caption, title, buttonCaptions);
|
return messageBox(500, 250, caption, title, buttonCaptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
function progressDialog(dialogCaption, dialogTitle, showProgressBar, buttonCaption, buttonAction)
|
async function progressDialog(dialogCaption, dialogTitle, showProgressBar, buttonCaption)
|
||||||
{
|
{
|
||||||
Engine.GetGUIObjectByName("downloadDialog_title").caption = dialogTitle;
|
Engine.GetGUIObjectByName("downloadDialog_title").caption = dialogTitle;
|
||||||
|
|
||||||
@ -318,13 +324,14 @@ function progressDialog(dialogCaption, dialogTitle, showProgressBar, buttonCapti
|
|||||||
Engine.GetGUIObjectByName("downloadDialog_progress").hidden = !showProgressBar;
|
Engine.GetGUIObjectByName("downloadDialog_progress").hidden = !showProgressBar;
|
||||||
Engine.GetGUIObjectByName("downloadDialog_status").hidden = !showProgressBar;
|
Engine.GetGUIObjectByName("downloadDialog_status").hidden = !showProgressBar;
|
||||||
|
|
||||||
let downloadDialog_button = Engine.GetGUIObjectByName("downloadDialog_button");
|
|
||||||
downloadDialog_button.caption = buttonCaption;
|
|
||||||
downloadDialog_button.onPress = () => { cancelRequest(); buttonAction(); };
|
|
||||||
|
|
||||||
Engine.GetGUIObjectByName("downloadDialog").hidden = false;
|
Engine.GetGUIObjectByName("downloadDialog").hidden = false;
|
||||||
|
|
||||||
g_RequestStartTime = Date.now();
|
g_RequestStartTime = Date.now();
|
||||||
|
|
||||||
|
const downloadDialog_button = Engine.GetGUIObjectByName("downloadDialog_button");
|
||||||
|
downloadDialog_button.caption = buttonCaption;
|
||||||
|
await new Promise(resolve => {downloadDialog_button.onPress = resolve;});
|
||||||
|
cancelRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user