I have a settings component which is opened in a secondary window where a user can enter a license key. Now is I put showMessageBox in the constructor it shows fine however when I do it on a button press it bings like it’s opened but doesn’t display on desktop and controls become unresponsive because it’s expecting response from show message box.
If I do this in the main window e.g. setup a button to show message on click it’s all good below is my component. I’m curious as to what’s going on because the app feels and responds like a dialog message window has been opened but it doesn’t show.
#include "SettingsComponent.h"
SettingsComponent::SettingsComponent(std::shared_ptr<Assets> _assets)
: assets(_assets),
ctrlActivate(_assets),
ctrlDeactivate(_assets)
{
appTitle.setFont(Font(16));
appTitle.setText("Summit Limiter", juce::NotificationType::dontSendNotification);
addAndMakeVisible(appTitle);
licenseTitle.setFont(Font(12));
licenseTitle.setText("License Key", juce::NotificationType::dontSendNotification);
addAndMakeVisible(licenseTitle);
inputLicense.setColour(TextEditor::ColourIds::backgroundColourId, assets->PanelDark);
inputLicense.setColour(TextEditor::ColourIds::outlineColourId, assets->PanelDark);
inputLicense.setColour(TextEditor::ColourIds::focusedOutlineColourId, assets->PanelDark);
inputLicense.setBorder(juce::BorderSize<int>(0));
addAndMakeVisible(inputLicense);
addAndMakeVisible(linkBtn);
ctrlActivate.setValue("ACTIVATE");
ctrlActivate.addButtonListener(this);
addAndMakeVisible(ctrlActivate);
ctrlDeactivate.setValue("DE-ACTIVATE");
ctrlDeactivate.addButtonListener(this);
addChildComponent(ctrlDeactivate);
// This works
NativeMessageBox::showMessageBox(AlertWindow::AlertIconType::InfoIcon
, "This works"
, "bla bla bla"
, nullptr);
}
SettingsComponent::~SettingsComponent()
{
}
void SettingsComponent::update()
{
if (assets->isTrial)
{
ctrlActivate.setVisible (true);
inputLicense.setEnabled(true);
}
else
{
ctrlDeactivate.setVisible (true);
inputLicense.setEnabled(false);
}
}
void SettingsComponent::paint(Graphics& g)
{
g.fillAll(assets->BackgroundClr);
}
void SettingsComponent::resized()
{
auto r = getLocalBounds();
r.reduce(20, 20);
appTitle.setBounds(r.removeFromTop(16));
r.removeFromTop(10);
linkBtn.setBounds(r.removeFromTop(16));
r.removeFromTop(10);
licenseTitle.setBounds(r.removeFromTop(12));
r.removeFromTop(10);
inputLicense.setBounds(r.removeFromTop(22));
r.removeFromTop(2);
auto btnRow = r.removeFromBottom(22);
auto firstBtn = btnRow.removeFromLeft(100);
ctrlActivate.setBounds(firstBtn);
ctrlDeactivate.setBounds(firstBtn);
}
void SettingsComponent::settingsButtonPressed(Settings::Button* btn)
{
if (btn == &ctrlActivate)
{
DBG("activate");
bool response = assets->activateLicense(inputLicense.getText().trim());
if (response)
{
assets->isTrial = false;
DBG("success");
NativeMessageBox::showMessageBox(AlertWindow::AlertIconType::InfoIcon
, "Upgraded Successfully"
, "You have successfully upgraded the application. Please restart to allow full changes to come into effect!"
, nullptr);
update();
}
else
{
DBG("false");
NativeMessageBox::showMessageBox(AlertWindow::AlertIconType::WarningIcon
, "Upgrade Failed"
, "There was a problem with your license key. Please check and try again!"
, nullptr);
}
}
else if(btn == &ctrlDeactivate)
{
DBG("de-activate");
assets->deactivateLicense();
update();
}
}
