From 2fc3abc48770c4256ba18f3cbcd03c9129ea4167 Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Tue, 4 Aug 2026 20:55:16 -0400 Subject: [PATCH] feat(sys): expose canGoBack for the chrome that offers the control --- lua/api/core/sys.lua | 16 ++++++++++------ native/src/bindings/core/sys.cpp | 22 ++++++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lua/api/core/sys.lua b/lua/api/core/sys.lua index eea05a8..985e945 100644 --- a/lua/api/core/sys.lua +++ b/lua/api/core/sys.lua @@ -36,19 +36,23 @@ function sys.getAppDataPath() end ---@param title string function sys.setAppTitle(title) end ----Launches /.lua/apps//main.lua and pushes the current route. ----@param path string App-relative directory path; traversal is rejected. ----@param arg? string Passed to init(arg). +---Launches a route, which main.lua resolves, and pushes the current one. +---@param path string App-relative route; traversal is rejected. +---@param arg? string Passed to main.start(route, arg). function sys.launch(path, arg) end ----Launches an app path without retaining the current route. ----@param path string App-relative directory path; traversal is rejected. ----@param arg? string Passed to init(arg). +---Launches a route without retaining the current one. +---@param path string App-relative route; traversal is rejected. +---@param arg? string Passed to main.start(route, arg). function sys.replace(path, arg) end ---Returns to the previous app, or the launcher when history is empty. function sys.back() end +---Whether sys.back() would return somewhere rather than land on the launcher, which is what chrome needs to decide whether to offer a back control. +---@return boolean +function sys.canGoBack() end + ---Returns heap statistics. ---@return integer freeBytes ---@return integer totalBytes diff --git a/native/src/bindings/core/sys.cpp b/native/src/bindings/core/sys.cpp index 713ab4d..25b7402 100644 --- a/native/src/bindings/core/sys.cpp +++ b/native/src/bindings/core/sys.cpp @@ -50,6 +50,10 @@ int back(lua_State* state) { Runtime::from(state)->requestBack(); return 0; } +int canGoBack(lua_State* state) { + lua_pushboolean(state, Runtime::from(state)->canGoBack()); + return 1; +} int getMemory(lua_State* state) { const MemoryInfo memory = Runtime::from(state)->sys().memory(); @@ -88,16 +92,22 @@ const luaL_Reg FUNCTIONS[] = { // --- Changes the running app's display title. // @param title string {"setAppTitle", setAppTitle}, - // --- Launches /.lua/apps//main.lua and pushes the current route. - // @param path string App-relative directory path; traversal is rejected. - // @param arg string|nil Passed to init(arg). + // --- Launches a route, which main.lua resolves, and pushes the current + // one. + // @param path string App-relative route; traversal is rejected. + // @param arg string|nil Passed to main.start(route, arg). {"launch", launch}, - // --- Launches an app path without retaining the current route. - // @param path string App-relative directory path; traversal is rejected. - // @param arg string|nil Passed to init(arg). + // --- Launches a route without retaining the current one. + // @param path string App-relative route; traversal is rejected. + // @param arg string|nil Passed to main.start(route, arg). {"replace", replace}, // --- Returns to the previous app, or the launcher when history is empty. {"back", back}, + // --- Whether sys.back() would return somewhere rather than land on the + // launcher, which is what chrome needs to decide whether to offer a back + // control. + // @return boolean + {"canGoBack", canGoBack}, // --- Returns heap statistics. // @return integer freeBytes // @return integer totalBytes