From e9b1e25ca409c1f12f55e04158d511ab4fe577cc Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 19 Oct 2022 01:38:58 +0800 Subject: [PATCH] Update main.rs This is how I'd do the app switch. It's a special case going to the shellchat. shellchat is aliased to `INITIAL_APP_FOCUS`, so you can refer to that constant directly in this call, instead of using a more generic app-lookup mechanism. Also, because the idea is that we can allow *anyone* to call this method, there are no authorization tokens to check, unlike the SwitchToApp call, which can allow arbitrary apps to be foregrounded. The security assumption is that "no harm" can be done if a malicious process can bring shellchat to the foreground. This might not be a good assumption, but, I can't think of a scenario where this helps someone trying to get control of a device. --- services/gam/src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/services/gam/src/main.rs b/services/gam/src/main.rs index f0f157c97..97c42bbb6 100644 --- a/services/gam/src/main.rs +++ b/services/gam/src/main.rs @@ -665,8 +665,14 @@ fn wrapped_main() -> ! { buffer.replace(spec).unwrap(); } Some(Opcode::DefaultApp) => { - // FIXME: Switch to shellchat here - log::error!("not implemented yet, switch to shellchat: {:?}", msg); + if let Some(new_app_token) = context_mgr.find_app_token_by_name(INITIAL_APP_FOCUS) { + match context_mgr.activate(&gfx, &mut canvases, new_app_token, true) { + Ok(_) => (), + Err(_) => log::warn!("failed to switch to {}, silent error!", switchapp.app_name.as_str().unwrap()), + } + } else { + log::warn!("Request to switch to default app, but the default app has not registered itself yet!"); + } } Some(Opcode::Quit) => break, None => {log::error!("unhandled message {:?}", msg);}