Skip to content

Commit

Permalink
[remux] add more API methods (#208)
Browse files Browse the repository at this point in the history
* add pause and stop APIs
* add methods to list all/paused/current app
* add remux-api script
  • Loading branch information
Eeems authored Dec 20, 2023
1 parent d584bc4 commit b2df05f
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/remux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ FILES=launcher.cpy
CPP_FLAGS+=-Wno-psabi
install:
make copy
make install_api
make install_service

install_service:
scp ./remux.service root@${HOST}:/etc/systemd/system/

install_api:
scp ./remux-api root@${HOST}:${DEST}/

start_service:
ssh root@${HOST} systemctl enable --now remux
129 changes: 123 additions & 6 deletions src/remux/launcher.cpy
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,16 @@ class App: public IApp:
if len(tokens) > 1:
name := tokens[1]
api_launch_app(name)
else if line.find("pause ") == 0:
tokens := str_utils::split(line, ' ')
if len(tokens) > 1:
name := tokens[1]
api_pause_app(name)
else if line.find("stop ") == 0:
tokens := str_utils::split(line, ' ')
if len(tokens) > 1:
name := tokens[1]
api_stop_app(name)

else:
debug "UNKNOWN API LINE:", line
Expand Down Expand Up @@ -568,6 +578,30 @@ class App: public IApp:
debug "NO SUCH APP:", name


void api_pause_app(string name):
app := find_app(name)
get_current_app()
if app.name == CURRENT_APP:
debug "USING API TO PAUSE", name
self.show_launcher()

void api_stop_app(string name):
app := find_app(name)
if app.bin != "":
debug "USING API TO STOP", name
get_current_app()
self.kill(name)
if name == CURRENT_APP:
self.show_launcher()
#ifdef REMARKABLE
else if name == "xochitl" and CURRENT_APP == APP_XOCHITL.name:
self.show_launcher()
#elif KOBO
else if name == "nickel" and CURRENT_APP == APP_NICKEL.name:
self.show_launcher()
#endif


void show_launcher():
if ui::MainLoop::overlay_is_visible():
return
Expand Down Expand Up @@ -784,6 +818,13 @@ class App: public IApp:
for auto app : app_dialog->get_apps():
if app.name == name:
bin = app.bin
#ifdef REMARKABLE
else if name == "xochitl" and app.name == APP_XOCHITL.name:
bin = app.bin
#elif KOBO
else if name == "nickel" and app.name == APP_NICKEL.name:
bin = app.bin
#endif

if bin == "":
return
Expand Down Expand Up @@ -912,8 +953,6 @@ class App: public IApp:
putenv((char*) "KO_DONT_SET_DEPTH=1")
putenv((char*) "KO_DONT_GRAB_INPUT=1")



#if defined(REMARKABLE)
_ := system("systemctl stop xochitl")
self.term_apps()
Expand All @@ -928,7 +967,6 @@ class App: public IApp:
fb->set_screen_depth(APP_MAIN.bpp)
#endif


ui::Style::DEFAULT.font_size = 32

// launches a thread that suspends on idle
Expand Down Expand Up @@ -959,7 +997,86 @@ class App: public IApp:
ui::MainLoop::read_input(1000)
ui::MainLoop::handle_gestures()

vector<RMApp> get_apps():
return self.app_dialog->get_apps()

App app
def main():
LAST_ACTION = time(NULL)
app.run()
def main(int argc, char **argv):
if argc > 1:
std::string flag(argv[1])
str_utils::trim(flag)
if flag == "--all-apps":
vector<string> apps
for auto a : app.get_apps():
#ifdef REMARKABLE
if a.name == APP_XOCHITL.name:
apps.push_back("xochitl")
else:
apps.push_back(a.name)
#elif KOBO
if a.name == APP_NICKEL.name:
apps.push_back("nickel")
else:
apps.push_back(a.name)
#else
apps.push_back(a.name)
#endif

for auto name : apps:
print name

else if flag == "--current-app":
for auto a : app.get_apps():
// Only if it is running
if !a.is_running or (!proc::is_running(a.which) and !proc::is_running(a.bin)):
continue

#ifdef REMARKABLE
if a.name == APP_XOCHITL.name:
print "xochitl"
else:
print a.name
#elif KOBO
if a.name == APP_NICKEL.name:
print "nickel"
else:
print a.name
#else
print a.name
#endif
break

else if flag == "--paused-apps":
vector<string> apps
for auto a : app.get_apps():
// Only if not in the list, and if it is currently running
if !a.is_running or std::find(apps.begin(), apps.end(), a.name) != apps.end():
continue

// Ignore current application
if proc::is_running(a.which) or proc::is_running(a.bin):
continue

#ifdef REMARKABLE
if a.name == APP_XOCHITL.name:
apps.push_back("xochitl")
else:
apps.push_back(a.name)
#elif KOBO
if a.name == APP_NICKEL.name:
apps.push_back("nickel")
else:
apps.push_back(a.name)
#else
apps.push_back(a.name)
#endif

for auto name : apps:
print name

else:
print "Usage:", argv[0], "[--help|--current-app|--paused-apps|--all-apps]"

else:
LAST_ACTION = time(NULL)
app.run()
66 changes: 66 additions & 0 deletions src/remux/remux-api
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

help() {
echo "Usage: remux-api <command>"
echo ""
echo " Commands:"
echo " --help | help: Show this message and exit"
echo " list-paused: List all paused apps"
echo " list-apps: List all installed apps"
echo " current-app: Output name of current app"
echo " show: Show the remux UI"
echo " hide: Hide the remux UI"
echo " suspend: Suspend the device"
echo " launch [name]: Launch an app"
echo " pause [name]: Pause an app if it's the current app"
echo " stop [name]: Stop an app"
}

case "$1" in
list-paused | list-apps | current-app | show | hide | suspend)
if [ $# -ne 1 ]; then
help
exit 1
fi
case "$1" in
list-paused)
remux --paused-apps 2>/dev/null
;;
list-apps)
remux --all-apps 2>/dev/null
;;
current-app)
remux --current-app 2>/dev/null
;;
show)
echo "show" > /run/remux.api
;;
hide)
echo "hide" > /run/remux.api
;;
suspend)
echo "suspend" > /run/remux.api
;;
esac
;;
launch | pause | stop)
if [ $# -ne 2 ]; then
help
exit 1
fi
case "$1" in
launch)
echo "launch $2" > /run/remux.api
;;
pause)
echo "pause $2" > /run/remux.api
;;
stop)
echo "stop $2" > /run/remux.api
;;
esac
;;
* | help | --help)
help
;;
esac

0 comments on commit b2df05f

Please sign in to comment.