MCPcopy Create free account
hub / github.com/XorTroll/uLaunch / MainLoop

Function MainLoop

projects/uSystem/source/main.cpp:1190–1281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1188 }
1189
1190 void MainLoop() {
1191 HandleGeneralChannelMessage();
1192 HandleAppletMessage();
1193 HandleMenuMessage();
1194
1195 auto consumed_action = false;
1196 // Try to consume one action per loop
1197 if(!g_ActionQueue.empty()) {
1198 UL_LOG_INFO("Action queue has %lu actions", g_ActionQueue.size());
1199 }
1200 for(u32 i = 0; i < g_ActionQueue.size(); i++) {
1201 auto &action = g_ActionQueue.at(i);
1202 consumed_action |= HandleAction(action);
1203 if(consumed_action) {
1204 // Action consumed, remove it from the queue
1205 g_ActionQueue.erase(g_ActionQueue.begin() + i);
1206 break;
1207 }
1208 }
1209
1210 auto something_done = consumed_action;
1211
1212 // Handle finalized active library applet
1213
1214 if(!la::IsActive() && g_LastLibraryAppletLaunchedNotMenu) {
1215 // The library applet that we launched and was active just finished, and it's not uMenu --> we either collect output (if needed) or just return to uMenu
1216
1217 UL_LOG_INFO("Active library applet finished, checking if we need to collect any output before launching uMenu...");
1218
1219 // If we launched uLoader to choose a homebrew, we need to collect the output
1220 ul::loader::TargetOutput target_opt;
1221 if(g_ExpectsLoaderChooseOutput) {
1222 UL_LOG_INFO("Getting loader chosen output...");
1223
1224 AppletStorage target_opt_st;
1225 UL_RC_ASSERT(la::Pop(&target_opt_st));
1226 UL_RC_ASSERT(appletStorageRead(&target_opt_st, 0, &target_opt, sizeof(target_opt)));
1227 }
1228
1229 // Pick correct uMenu state to launch to, and launch uMenu
1230 auto menu_start_mode = ul::smi::MenuStartMode::MainMenu;
1231 if(g_NextMenuLaunchAtStartup) {
1232 menu_start_mode = ul::smi::MenuStartMode::StartupMenu;
1233 g_NextMenuLaunchAtStartup = false;
1234 }
1235 if(g_NextMenuLaunchAtSettings) {
1236 menu_start_mode = ul::smi::MenuStartMode::SettingsMenu;
1237 g_NextMenuLaunchAtSettings = false;
1238 }
1239 UL_RC_ASSERT(LaunchMenu(menu_start_mode));
1240
1241 // If we collected output from uLoader, send it to the just-launched uMenu
1242 if(g_ExpectsLoaderChooseOutput) {
1243 ul::smi::MenuMessageContext msg_ctx = {
1244 .msg = ul::smi::MenuMessage::ChosenHomebrew,
1245 .chosen_hb = {}
1246 };
1247 memcpy(msg_ctx.chosen_hb.nro_path, target_opt.nro_path, sizeof(msg_ctx.chosen_hb.nro_path));

Callers 1

MainFunction · 0.70

Calls 11

HandleAppletMessageFunction · 0.85
HandleMenuMessageFunction · 0.85
HandleActionFunction · 0.85
PopFunction · 0.85
LaunchMenuFunction · 0.85
PushMenuMessageContextFunction · 0.85
GetIdFunction · 0.85
FormatResultDisplayFunction · 0.85
PushSimpleMenuMessageFunction · 0.85
IsActiveFunction · 0.50

Tested by

no test coverage detected