Skip to content

Commit e1d51c9

Browse files
authored
Link: for terminal=true apps use TerminalDialog (#104)
* LinkApp: for `terminal=true` apps use gmenu2x's TerminalDialog() * editLink(): add "Terminal" bool option
1 parent 8c69ef5 commit e1d51c9

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

src/gmenu2x.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,7 @@ void GMenu2X::editLink() {
20972097
string linkSelDir = menu->selLinkApp()->getSelectorDir();
20982098
bool useSelector = !linkSelDir.empty();
20992099
bool linkSelBrowser = menu->selLinkApp()->getSelectorBrowser();
2100+
bool linkTerminal = menu->selLinkApp()->getTerminal();
21002101
string linkSelScreens = menu->selLinkApp()->getSelectorScreens();
21012102
string linkSelAliases = menu->selLinkApp()->getAliasFile();
21022103
int linkClock = menu->selLinkApp()->getCPU();
@@ -2163,6 +2164,7 @@ void GMenu2X::editLink() {
21632164
sd.addSetting(new MenuSettingFile( this, tr["Aliases"], tr["File containing a list of aliases for the selector"], &linkSelAliases, ".txt,.dat", linkExec, dialogTitle, dialogIcon));
21642165
sd.addSetting(new MenuSettingImage( this, tr["Backdrop"], tr["Select an image backdrop"], &linkBackdrop, ".png,.bmp,.jpg,.jpeg", linkExec, dialogTitle, dialogIcon));
21652166
sd.addSetting(new MenuSettingFile( this, tr["Manual"], tr["Select a Manual or Readme file"], &linkManual, ".png,.bmp,.jpg,.jpeg,.txt,.me", linkExec, dialogTitle, dialogIcon));
2167+
sd.addSetting(new MenuSettingBool( this, tr["Terminal"], tr["Output app via Terminal Dialog"], &linkTerminal));
21662168
#if defined(TARGET_WIZ) || defined(TARGET_CAANOO)
21672169
bool linkUseGinge = menu->selLinkApp()->getUseGinge();
21682170
string ginge_prep = exe_path() + "/ginge/ginge_prep";
@@ -2206,6 +2208,7 @@ void GMenu2X::editLink() {
22062208
menu->selLinkApp()->setCPU(linkClock);
22072209
menu->selLinkApp()->setKbdLayout(linkKbdLayout);
22082210
menu->selLinkApp()->setTefix(linkTefix);
2211+
menu->selLinkApp()->setTerminal(linkTerminal);
22092212

22102213
#if defined(HW_GAMMA)
22112214
menu->selLinkApp()->setGamma(linkGamma);

src/linkapp.cpp

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "menu.h"
2727
#include "selector.h"
2828
#include "messagebox.h"
29+
#include "terminaldialog.h"
2930
#include "debug.h"
3031

3132
using namespace std;
@@ -412,7 +413,9 @@ void LinkApp::launch(const string &selectedFile, string dir) {
412413
}
413414
}
414415

415-
INFO("Executing '%s' (%s %s)", title.c_str(), exec.c_str(), params.c_str());
416+
string execcmd = exec + " " + params;
417+
418+
INFO("Executing '%s' (%s)", title.c_str(), execcmd.c_str());
416419

417420
#if defined(OPK_SUPPORT)
418421
if (isOPK()) {
@@ -478,28 +481,39 @@ void LinkApp::launch(const string &selectedFile, string dir) {
478481
command = "HOME=" + params + " " + command;
479482
}
480483

481-
gmenu2x->quit(false);
482-
483-
if (getTerminal()) gmenu2x->enableTerminal();
484-
485-
// execle("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL, environ);
486-
pid_t son = fork();
487-
if (!son) {
488-
execlp("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL);
489-
ERROR("execlp of shell cmd \"%s\" failed", command.c_str());
490-
}
491-
int status;
492-
waitpid(son, &status, 0);
493-
INFO("Last launched app \"%s\" exited with status=%i", command.c_str(), status);
494-
495-
if (gmenu2x->confInt["saveAutoStart"]) {
496-
// gmenu2x->confStr["datetime"] = get_date_time();
497-
// gmenu2x->writeConfig();
498-
gmenu2x->shutdownOS();
499-
} else {
500-
//we already called SDL_Quit try relaunching gmenu2x
501-
chdir(exe_path().c_str());
502-
execlp("./gmenu2x", "./gmenu2x", NULL); // can't use gmenu2x->reinit() since we've called quit()
484+
if (getTerminal())
485+
#if defined(CUS_TERM)
486+
gmenu2x->enableTerminal();
487+
#else
488+
{
489+
chdir(exe_path().c_str()); // we're returrning to menu so change cur wdir back to gmenu2x
490+
TerminalDialog td(gmenu2x, this->getTitle().c_str(), execcmd, "icons/configure.png");
491+
td.exec(command);
492+
gmenu2x->initMenu();
493+
return;
494+
} else
495+
#endif
496+
{
497+
gmenu2x->quit(false);
498+
// execle("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL, environ);
499+
pid_t son = fork();
500+
if (!son) {
501+
execlp("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL);
502+
ERROR("execlp of shell cmd \"%s\" failed", command.c_str());
503+
}
504+
int status;
505+
waitpid(son, &status, 0);
506+
INFO("Last launched app \"%s\" exited with status=%i", command.c_str(), status);
507+
508+
if (gmenu2x->confInt["saveAutoStart"]) {
509+
// gmenu2x->confStr["datetime"] = get_date_time();
510+
// gmenu2x->writeConfig();
511+
gmenu2x->shutdownOS();
512+
} else {
513+
//we already called SDL_Quit try relaunching gmenu2x
514+
chdir(exe_path().c_str());
515+
execlp("./gmenu2x", "./gmenu2x", NULL); // can't use gmenu2x->reinit() since we've called quit()
516+
}
503517
}
504518
}
505519

0 commit comments

Comments
 (0)