///| Web apps (PWAs) Chrome installs, in the Applications menu: they are picked up when the menu /// next opens, in a "Chrome Apps" category, and the wheel scrolls the list. /// Needs the modules built: scripts/build-modules.sh. test "a web app installed while running is in the menu's Chrome Apps" { let data = "/tmp/chandra-webapps-" + @sys.getpid().to_string() let dir = data + "/applications" assert_true(@sys.mkdir_p(dir)) let app = fn(id : String, name : String, rest : String) { ignore( @sys.write_file_bytes( dir + "/" + id + ".desktop", @sys.str_to_utf8_bytes("[Desktop Entry]\nType=Application\nName=" + name + "\n" + rest), ), ) } for i = 0; i < 12; i = i + 1 { app("chandra-game" + i.to_string(), "Chandra Game " + i.to_string(), "Exec=true\nCategories=Game;\n") } let socket_path = "/tmp/wayland-moon-webapps-" + @sys.getpid().to_string() + ".sock" let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap() comp.shell.xdg_dirs = { ..comp.shell.xdg_dirs, data_home: data, data_dirs: [] } comp.shell.toggle_launcher() comp.shell.toggle_launcher() let id = "chrome-chandratestappid-Default" assert_eq(comp.shell.apps.length(), 12) assert_false(comp.shell.apps.iter().any(a => a.id == id)) // Chrome installs it. app( id, "Chandra Web App", "Exec=/opt/google/chrome/google-chrome --profile-directory=Default --app-id=chandratestappid\n", ) comp.shell.toggle_launcher() for _ in 0..<10 { @sys.sleep_ms(30) // the popup slides in ignore(comp.compose_frame()) } let a = comp.shell.apps.filter(a => a.id == id) assert_eq(a.map(a => (a.name, a.category)), [("Chandra Web App", "Chrome Apps")]) let slot = comp.shell.slot_of("launcher") let pr = comp.shell.slot_popup_rect(slot) let texts = fn() { comp.shell.slot_popup_texts(slot).map(t => t.0) } assert_true(texts().contains("Chrome Apps")) // The wheel over the list scrolls it (the shell's copy of the menu follows the module's). let (lx, ly) = (pr.x + pr.w - 60, pr.y + 60) comp.handle_input(@nested.InputEvent::PointerMove(lx.to_double(), ly.to_double()), 1U) comp.handle_input(@nested.InputEvent::Scroll(0U, 15.0, 1), 2U) assert_eq(comp.shell.launcher_state.scroll, 3) // Its category lists it. let cats = ["All", "Chrome Apps", "Games"] let i = cats.search("Chrome Apps").unwrap() click_at(comp, pr.x + 20, pr.y + 52 + i * 26 + 12, 10U) ignore(comp.compose_frame()) assert_eq(comp.shell.launcher_state.category, "Chrome Apps") assert_true(texts().contains("Chandra Web App")) assert_false(texts().contains("Chandra Game 0")) ignore(@sys.write_file_bytes("_build/launcher_webapps.png", @renderer.encode_png(comp.compose_frame()))) comp.shell.shutdown() }