export async function performLaunch(
ctx: Context,
logger: RecordingLogger,
cave: Cave,
game: Game
) {
ctx.emitProgress({ progress: -1, stage: "configure" });
const { store } = ctx;
const taskId = ctx.getTaskId();
store.dispatch(
actions.taskProgress({
id: taskId,
progress: -1,
stage: "prepare",
})
);
// TODO: have butler check morphing and queue a heal if needed
const { appVersion } = store.getState().system;
logger.info(`itch ${appVersion} launching '${game.title}' (#${game.id})`);
const { preferences } = store.getState();
const prereqsDir = paths.prereqsPath();
// TODO: extract that to another module
let prereqsModal: TypedModal<any, any>;
let prereqsStateParams: PrereqsStateParams;
function closePrereqsModal() {
if (!prereqsModal) {
return;
}
store.dispatch(
actions.closeModal({
wind: "root",
id: prereqsModal.id,
})
);
prereqsModal = null;
}
let powerSaveBlockerId: number = null;
let cancelled = false;
let launchConvo: Conversation;
await ctx.withStopper({
work: async () => {
try {
await mcall(
messages.Launch,
{
caveId: cave.id,
prereqsDir,
sandbox: preferences.isolateApps,
},
convo => {
launchConvo = convo;
hookLogging(convo, logger);
convo.on(messages.PickManifestAction, async ({ actions }) => {
const index = await pickManifestAction(store, actions, game);
return { index };
});
convo.on(messages.AcceptLicense, async ({ text }) => {
const res = await promisedModal(
store,
modals.naked.make({
wind: "root",
title: ["prompt.sla.title"],
message: ["prompt.sla.message"],
detail: text,
widgetParams: {} as any,
buttons: [
{
label: ["prompt.sla.accept"],
action: actions.modalResponse({}),
},
"cancel",
],
})
);
if (res) {
return { accept: true };
}
return { accept: false };
});
convo.on(messages.HTMLLaunch, async params => {
return await performHTMLLaunch({
ctx,
logger,
game,
params,
});
});
//.........这里部分代码省略.........
请发表评论