MCPcopy Create free account
hub / github.com/ClassicOldSong/Apollo / pause

Method pause

src/process.cpp:648–704  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

646 }
647
648 void proc_t::pause() {
649 if (!running()) {
650 BOOST_LOG(info) << "Session already stopped, do not run pause commands.";
651 return;
652 }
653
654 if (_app.terminate_on_pause) {
655 BOOST_LOG(info) << "Terminating app [" << _app_name << "] when all clients are disconnected. Pause commands are skipped.";
656 terminate();
657 return;
658 }
659
660 BOOST_LOG(info) << "Session pausing for app [" << _app_name << "].";
661
662 if (!_app.state_cmds.empty()) {
663 auto exec_thread = std::thread([cmd_list = _app.state_cmds, app_working_dir = _app.working_dir, _env = _env]() mutable {
664 _env["APOLLO_APP_STATUS"] = "PAUSING";
665
666 std::error_code ec;
667 auto _state_pause_it = std::begin(cmd_list);
668
669 for (; _state_pause_it != std::end(cmd_list); ++_state_pause_it) {
670 auto &cmd = *_state_pause_it;
671
672 // Skip empty commands
673 if (cmd.undo_cmd.empty()) {
674 continue;
675 }
676
677 boost::filesystem::path working_dir = app_working_dir.empty() ?
678 find_working_directory(cmd.undo_cmd, _env) :
679 boost::filesystem::path(app_working_dir);
680 BOOST_LOG(info) << "Executing Pause Cmd: ["sv << cmd.undo_cmd << "] elevated: " << cmd.elevated;
681 auto child = platf::run_command(cmd.elevated, true, cmd.undo_cmd, working_dir, _env, nullptr, ec, nullptr);
682
683 if (ec) {
684 BOOST_LOG(error) << "Couldn't run ["sv << cmd.undo_cmd << "]: System: "sv << ec.message();
685 break;
686 }
687
688 child.wait();
689
690 auto ret = child.exit_code();
691 if (ret != 0 && ec != std::errc::permission_denied) {
692 BOOST_LOG(error) << '[' << cmd.undo_cmd << "] failed with code ["sv << ret << ']';
693 break;
694 }
695 }
696 });
697
698 exec_thread.detach();
699 }
700
701#if defined SUNSHINE_TRAY && SUNSHINE_TRAY >= 1
702 system_tray::update_tray_pausing(proc::proc.get_last_run_app_name());
703#endif
704 }
705

Callers 1

joinFunction · 0.80

Calls 6

find_working_directoryFunction · 0.85
pathClass · 0.85
update_tray_pausingFunction · 0.85
waitMethod · 0.80
get_last_run_app_nameMethod · 0.80
run_commandFunction · 0.50

Tested by

no test coverage detected