Add GAM menu token handling

This adds the tokens for app submenus. I am now successfully able to
load `vault'!
This commit is contained in:
Vihaan Jim 2023-08-10 20:09:19 -04:00
parent 7532a34769
commit 5186a723f5
2 changed files with 18 additions and 9 deletions

View file

@ -14,7 +14,7 @@ pub(crate) struct AppLoader {
load_menu: MenuMatic,
conn: xous::CID,
apps: Vec<xous_ipc::String<64>>,
possible_apps: Vec<xous_ipc::String<64>>,
possible_apps: Vec<(xous_ipc::String<64>, usize)>,
server: Option<String>,
current_menu: String,
}
@ -63,7 +63,7 @@ impl AppLoader {
}
pub(crate) fn add_app(&mut self, index: usize) {
let name = self.possible_apps[index];
let (name, menus) = self.possible_apps[index];
self.modals.start_progress(t!("apploader.addapp.loading", locales::LANG), 0, 3, 0).expect("Couldn't set up progress bar");
@ -130,6 +130,9 @@ impl AppLoader {
// add its name to GAM
self.gam.register_name(name.to_str(), self.auth).expect("Couldn't register name");
for menu in 0..menus {
self.gam.register_name(&format!("{} Submenu {}", name, menu), self.auth).expect("Couldn't register name");
}
// add it to the menu
self.menu.insert_item(MenuItem { name,
@ -191,7 +194,7 @@ impl AppLoader {
return;
}
}
.into_json::<Vec<String>>()
.into_json::<Vec<(String, usize)>>()
{
Ok(json) => { self.modals.update_progress(2).expect("Couldn't update progress"); json },
Err(e) => {
@ -200,14 +203,14 @@ impl AppLoader {
}
}
.iter()
.map(|s| xous_ipc::String::<64>::from_str(&s))
.map(|(name, menus)| (xous_ipc::String::<64>::from_str(&name), *menus))
.collect();
for old_name in old {
for (old_name, _) in old {
self.load_menu.delete_item(old_name.as_str().unwrap());
}
for (i, app) in self.possible_apps.iter().enumerate() {
for (i, (app, _)) in self.possible_apps.iter().enumerate() {
self.load_menu.insert_item(MenuItem { name: xous_ipc::String::from_str(app.to_str()),
action_conn: Some(self.conn),
action_opcode: Opcode::AddApp.to_u32().unwrap(),

View file

@ -6,10 +6,11 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import unquote
class XousAppServer(BaseHTTPRequestHandler):
def __init__(self, profile, target, context_to_app, *args):
def __init__(self, profile, target, context_to_app, context_to_menus, *args):
self.profile = profile
self.target = target
self.context_to_app = context_to_app
self.context_to_menus = context_to_menus
BaseHTTPRequestHandler.__init__(self, *args)
def do_GET(self):
@ -20,7 +21,7 @@ class XousAppServer(BaseHTTPRequestHandler):
self.send_header('Content-Type', 'application/json')
self.end_headers()
l = json.dumps(list(self.context_to_app.keys()))
l = json.dumps(list(self.context_to_menus.items()))
self.wfile.write(l.encode())
else:
@ -52,12 +53,17 @@ def main():
manifest = json.loads(f.read())
context_to_app = {}
context_to_menus = {}
for app in args.apps:
context_name = manifest[app]['context_name']
context_to_app[context_name] = app
if 'submenu' in manifest[app]:
context_to_menus[context_name] = manifest[app]['submenu']
else:
context_to_menus[context_name] = 0
server = HTTPServer(('0.0.0.0', args.port), lambda *server_args: XousAppServer(args.profile, args.target, context_to_app, *server_args))
server = HTTPServer(('0.0.0.0', args.port), lambda *server_args: XousAppServer(args.profile, args.target, context_to_app, context_to_menus, *server_args))
server.serve_forever()
if __name__ == "__main__":