Hi,
I checked the different ways to restart a JUCE app on the forum and stumble uppon different discussions:
I also went from the “request from the outside to do the restart” route as well via an apple script or external app.
I faced permissions issues, it’s very feasable but requires codesigned app etc
So I did the following restart function called from the component window destructor with an alertWindow async, it’s ok but the “childProcess.start()” function never works and falls back to “child.startAsProcess()” which is not as good since it’s restarting the app from the terminal which shows up on the user’s screen and if the terminal is closed the JUCE app is shut down as well.
I added xcode loggers at each steps to track down the culprit and even if child.start() is not working it’s returning (1 | True) .
i checked if the app can go multi instance as well, it returns true, so not the problem apparently.
Any idea to make it work properly with “childProcess.start()” and not “startAsProcess()” ?
Here is my script :
CtrlrSettings::~CtrlrSettings()
{
deleteAndZero (propertyPanel);
if (JUCEApplication::isStandaloneApp())
{
// Show Ok/Cancel dialog to confirm restart
const auto callbackRestart = juce::ModalCallbackFunction::create([this] (int resultBox){
if (resultBox == 0){nullptr;} // for Cancel
if (resultBox == 1){restart();} // for OK
});
juce::NativeMessageBox::showOkCancelBox(juce::AlertWindow::QuestionIcon,"CtrlrX", "Restarting CtrlrX is required to apply new settings.", nullptr, callbackRestart);
}
else{
// For VST/AU instances
AlertWindow::showMessageBox (AlertWindow::WarningIcon, "CtrlrX", "Restart to apply new settings."); // Added v5.6.31
}
}
void CtrlrSettings::restart()
{
// Check if multiple instances are allowed
auto runningInstance = JUCEApplication::getInstance();
bool multiInstance = runningInstance->JUCEApplication::moreThanOneInstanceAllowed();
if (multiInstance) {
Logger::writeToLog("Multiple instances allowed.");
}
else{
Logger::writeToLog("Multiple instances not allowed.");
}
String executablePath = File::getSpecialLocation(File::currentExecutableFile).getFullPathName();
File exeFile = File(executablePath);
if (exeFile.exists())
{
Logger::writeToLog("Executable file found");
int result = 1; // Assume failure initially
auto osType = SystemStats::getOperatingSystemType();
Logger::writeToLog("OS type: " + String(osType));
String osName = SystemStats::getOperatingSystemName();
Logger::writeToLog("OS Name: " + String(osName));
if ((SystemStats::getOperatingSystemType() & juce::SystemStats::MacOSX) != 0) { // To test whether any version of OSX is running
// For OSX & macOS
Logger::writeToLog("Launching on macOS using ChildProcess.");
ChildProcess childProcess;
// Attempt to start the process with ChildProcess
if (childProcess.start(exeFile.getFullPathName())) {
Logger::writeToLog("ChildProcess start() successful."); // This is not properly working
result = 0;
} else {
Logger::writeToLog("ChildProcess start() failed.");
// If ChildProcess fails, try startAsProcess()
Logger::writeToLog("Trying startAsProcess().");
result = exeFile.startAsProcess();
if (result == 0) {
Logger::writeToLog("startAsProcess() successful.");
} else {
Logger::writeToLog("startAsProcess() failed.");
}
}
}
else if (SystemStats::getOperatingSystemType() == SystemStats::Windows){
// For Windows
Logger::writeToLog("Launching on Windows using exeFile.startAsProcess().");
result = exeFile.startAsProcess();
}
else{
// Handle unsupported operating systems
Logger::writeToLog("Launching on other operating system.");
std::cerr << "Launching on other operating system." << std::endl;
result = 1;
}
if (result == 1){
// Handle error (e.g., log error message)
std::cerr << "Error launching executable: " << result << std::endl;
Logger::writeToLog("Error launching executable: " + String(result));
}
else
{
Logger::writeToLog("Executable launched successfully.");
}
}
else{
// Handle error: executable file not found
std::cerr << "Executable file not found." << std::endl;
Logger::writeToLog("Executable file not found.");
}
Logger::writeToLog("Sending quit request to current application.");
JUCEApplication::getInstance()->systemRequestedQuit();
Logger::writeToLog("Quit request sent. Waiting for 500ms.");
Thread::sleep(500);
}
And this is my Xcode log :
Executable file found
OS type: 270
OS Name: Mac OSX 10.14.6
Launching on macOS using ChildProcess.
ChildProcess start() successful.
Executable launched successfully.
Sending quit request to current application.
Quit request sent. Waiting for 500ms.
Thanks for your help and happy JUCY year for 2025 to everyone ![]()
Damien
