Repository navigation
Expand file tree
/
Copy pathMain.cpp
More file actions
205 lines (177 loc) · 8.77 KB
/
Copy pathMain.cpp
File metadata and controls
205 lines (177 loc) · 8.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// Standalone sample app for the moonbase_licensing JUCE module.
//
// It mimics a real plugin editor ("Solstice") with a License button, and shows
// the activation flow as a MODAL OVERLAY on top of it. "Open Solstice" (shown
// once activation succeeds), "Continue" on the trial screen, and the close
// button dismiss the overlay to reveal the app underneath; the License button
// brings it back. The endpoint /
// product id / public key are the public Moonbase demo values.
#include <moonbase_licensing/moonbase_licensing.h>
#include <memory>
#include <vector>
namespace compat = moonbase::juce_integration::compat;
using moonbase::juce_integration::ActivationComponent;
using moonbase::juce_integration::ActivationConfig;
static ActivationConfig makeConfig()
{
ActivationConfig config;
config.endpoint = "https://demo.moonbase.sh";
config.productId = "demo-app";
config.publicKey = R"(-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAutOqeUiPMgYjAwQ53CyKhJSqojr2bejce0CshQi9Hd8mNZbkoROx
oS56eIzehFSlX4YwHnF47AR1+fPOe7Q33Cgzd6d9xqksiMH7sWK2mADIlB66vZdW
uk3Me0UMB22Biy1RQbSRMivu79MxCofsympoL/5CFjJLd1u37kxjuRWVLjJS84Rr
3L2W7R7Exnno/giC+L/Dv711mjgstmtlAQm5ZINvFvoLA1eFTDs6nlCs3dpJSiq3
fsBUMT9FtudzS5As54jeT/8MB66fJJ0A1LQ/v5CW8ACQYseFSIoOKErD3xU7QLIJ
ERUn++6CVMPvZo67jVbTY+GCXYfW4gGVZQIDAQAB
-----END RSA PUBLIC KEY-----)";
config.productName = "Solstice";
config.manufacturerName = "Helio Audio";
config.accent = juce::Colour(0xff186cdc);
config.overlayBackdrop = true; // render as a modal over the plugin editor
config.applicationVersion = JUCE_APPLICATION_VERSION_STRING;
config.showAddOns = true; // an "Add-ons" row on the license view, opening the add-ons screen
// Point the sample at your own store without editing it: MOONBASE_ENDPOINT,
// MOONBASE_PRODUCT_ID, MOONBASE_PUBLIC_KEY and MOONBASE_PRODUCT_NAME replace
// the demo values. Another product keeps its license apart from the demo's.
const auto fromEnvironment = [](const char* name, juce::String& value)
{
const auto set = juce::SystemStats::getEnvironmentVariable(name, {}).trim();
if (set.isNotEmpty())
value = set;
};
fromEnvironment("MOONBASE_ENDPOINT", config.endpoint);
fromEnvironment("MOONBASE_PRODUCT_ID", config.productId);
fromEnvironment("MOONBASE_PUBLIC_KEY", config.publicKey);
fromEnvironment("MOONBASE_PRODUCT_NAME", config.productName);
if (config.productId != "demo-app")
config.licenseFile = juce::File::getSpecialLocation(juce::File::userApplicationDataDirectory)
.getChildFile("Moonbase Activation Sample")
.getChildFile(juce::File::createLegalFileName(config.productId))
.getChildFile("license.mb");
// Telemetry: attach JUCE system/host metadata to activation requests.
config.analytics.enabled = true;
config.metadata["app.channel"] = "sample"; // a custom field, sent alongside
config.onDiagnostic = [] (const juce::String& message) {
juce::Logger::writeToLog("[activation] " + message);
};
return config;
}
//==============================================================================
// A stand-in plugin editor. The real point of the sample is the activation
// modal it hosts; the knobs are just so there's an app to reveal.
class PluginEditor : public juce::Component
{
public:
PluginEditor()
{
const char* knobNames[] = { "Drive", "Warmth", "Mix", "Output" };
for (int i = 0; i < 4; ++i)
{
auto knob = std::make_unique<juce::Slider>(juce::Slider::RotaryHorizontalVerticalDrag,
juce::Slider::NoTextBox);
knob->setRange(0.0, 1.0);
knob->setValue(0.25 + 0.18 * i);
knob->setColour(juce::Slider::rotarySliderFillColourId, juce::Colour(0xff186cdc));
knob->setColour(juce::Slider::rotarySliderOutlineColourId, juce::Colour(0x22ffffff));
knob->setColour(juce::Slider::thumbColourId, juce::Colour(0xfff5f8fb));
addAndMakeVisible(*knob);
auto label = std::make_unique<juce::Label>(juce::String(), knobNames[i]);
label->setJustificationType(juce::Justification::centred);
label->setColour(juce::Label::textColourId, juce::Colour(0xff90a0b8));
label->setFont(compat::font(12.5f));
addAndMakeVisible(*label);
knobs.push_back(std::move(knob));
labels.push_back(std::move(label));
}
licenseButton.setButtonText("License");
licenseButton.setColour(juce::TextButton::buttonColourId, juce::Colour(0x18ffffff));
licenseButton.setColour(juce::TextButton::textColourOffId, juce::Colour(0xffcdd8e6));
licenseButton.onClick = [this] { showActivation(); };
addAndMakeVisible(licenseButton);
// Added hidden: the overlay presents itself whenever the app is locked
// (at launch, or when the license is lost later), and the License button
// opens it on demand.
activation = std::make_unique<ActivationComponent>(makeConfig());
activation->onClose = [this] { hideActivation(); }; // "Open {product}", "Continue" and the close (X) dismiss
addChildComponent(*activation);
setSize(760, 520);
}
void showActivation() { activation->appear(); }
void hideActivation() { activation->dismiss(); }
void paint(juce::Graphics& g) override
{
auto b = getLocalBounds().toFloat();
juce::ColourGradient bg(juce::Colour(0xff151c29), b.getCentreX(), 0.0f,
juce::Colour(0xff090d15), b.getCentreX(), b.getHeight(), false);
g.setGradientFill(bg);
g.fillRect(b);
// top bar
auto header = getLocalBounds().removeFromTop(96).reduced(28, 0);
g.setColour(juce::Colour(0xfff5f8fb));
g.setFont(compat::font(30.0f, true));
g.drawText("SOLSTICE", header.removeFromTop(64), juce::Justification::bottomLeft);
g.setColour(juce::Colour(0xff768aa4));
g.setFont(compat::font(13.0f));
g.drawText("Saturator by Helio Audio", header, juce::Justification::topLeft);
g.setColour(juce::Colour(0x12ffffff));
g.fillRect(getLocalBounds().withTrimmedTop(96).removeFromTop(1).reduced(28, 0));
}
void resized() override
{
activation->setBounds(getLocalBounds());
licenseButton.setBounds(getWidth() - 28 - 96, 30, 96, 32);
auto row = getLocalBounds().withTrimmedTop(150).reduced(40, 0).removeFromTop(170);
const int cell = row.getWidth() / juce::jmax(1, (int) knobs.size());
for (size_t i = 0; i < knobs.size(); ++i)
{
auto c = row.removeFromLeft(cell);
knobs[i]->setBounds(c.removeFromTop(128).reduced(14));
labels[i]->setBounds(c.removeFromTop(22));
}
}
private:
std::vector<std::unique_ptr<juce::Slider>> knobs;
std::vector<std::unique_ptr<juce::Label>> labels;
juce::TextButton licenseButton;
std::unique_ptr<ActivationComponent> activation;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginEditor)
};
//==============================================================================
class MoonbaseActivationApplication : public juce::JUCEApplication
{
public:
const juce::String getApplicationName() override { return "Moonbase Activation"; }
const juce::String getApplicationVersion() override { return JUCE_APPLICATION_VERSION_STRING; }
bool moreThanOneInstanceAllowed() override { return true; }
void initialise(const juce::String&) override { mainWindow.reset(new MainWindow()); }
void shutdown() override { mainWindow = nullptr; }
void systemRequestedQuit() override { quit(); }
class MainWindow : public juce::DocumentWindow
{
public:
MainWindow()
: juce::DocumentWindow("Solstice", juce::Colour(0xff090d15),
juce::DocumentWindow::allButtons)
{
auto* editor = new PluginEditor();
setUsingNativeTitleBar(true);
setContentOwned(editor, true);
setResizable(true, false);
// Deliberately allow sizes below the modal's minimum so you can see
// the activation modal scale down to fit a small host window.
setResizeLimits(360, 320, 1400, 1000);
centreWithSize(editor->getWidth(), editor->getHeight());
setVisible(true);
}
void closeButtonPressed() override
{
juce::JUCEApplication::getInstance()->systemRequestedQuit();
}
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainWindow)
};
private:
std::unique_ptr<MainWindow> mainWindow;
};
START_JUCE_APPLICATION(MoonbaseActivationApplication)