summaryrefslogtreecommitdiff
path: root/gui/main.cpp
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-09-25 12:23:47 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-09-25 12:23:47 +0200
commitef0d5525b7c47d03b7577035e3394b450691e92b (patch)
tree0bda2eedba66718a4dcf90be77647d1b6bc84503 /gui/main.cpp
parent998b5cb54ad23be1f6df0ee8abd08af5614f38db (diff)
[refactor] grab appname from providers.json
Diffstat (limited to 'gui/main.cpp')
-rw-r--r--gui/main.cpp52
1 files changed, 32 insertions, 20 deletions
diff --git a/gui/main.cpp b/gui/main.cpp
index 42123ae..11c60a4 100644
--- a/gui/main.cpp
+++ b/gui/main.cpp
@@ -38,20 +38,40 @@ void signalHandler(int) {
exit(0);
}
+QString getAppName(QJsonValue info, QString provider) {
+ for (auto p: info.toArray()) {
+ QJsonObject item = p.toObject();
+ if (item["name"] == provider) {
+ return item["applicationName"].toString();
+ }
+ }
+ return "BitmaskVPN";
+}
+
int main(int argc, char **argv) {
signal(SIGINT, signalHandler);
Backend backend;
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
- QApplication::setApplicationName(backend.getAppName());
QApplication::setApplicationVersion(backend.getVersion());
QApplication app(argc, argv);
app.setQuitOnLastWindowClosed(false);
+ /* load providers json */
+ QFile providerJson (":/providers.json");
+ providerJson.open(QIODevice::ReadOnly | QIODevice::Text);
+ QJsonModel *providers = new QJsonModel;
+ providers->loadJson(providerJson.readAll());
+ QJsonValue defaultProvider = providers->json().object().value("default");
+ QJsonValue providersInfo = providers->json().object().value("providers");
+ QString appName = getAppName(providersInfo, defaultProvider.toString());
+
+ QApplication::setApplicationName(appName);
+
QCommandLineParser parser;
parser.setApplicationDescription(
- backend.getAppName() +
+ appName +
QApplication::translate(
"main", ": a fast and secure VPN. Powered by Bitmask."));
parser.addHelpOption();
@@ -80,30 +100,24 @@ int main(int argc, char **argv) {
{"v", "version"},
QApplication::translate(
"main",
- "Version of the bitmask-vpn."),
+ "Version of the bitmask-vpn."),
},
{
{"o", "obfs4"},
QApplication::translate(
"main",
- "Use obfs4 to obfuscate the traffic is available in the provider."),
+ "Use obfs4 to obfuscate the traffic, if available in the provider."),
},
{
{"a", "disable-autostart"},
QApplication::translate(
"main",
- "Disable the autostart for the next run."),
- },
- {
- {"s", "start-vpn"},
- QApplication::translate(
- "main",
- "Start the vpn in turned 'on' or 'off'."),
+ "Disable autostart for the next run."),
},
});
QCommandLineOption webPortOption("web-port", QApplication::translate("main", "Web api port (default: 8080)"), "port", "8080");
parser.addOption(webPortOption);
- QCommandLineOption startVPNOption("start-vpn", QApplication::translate("main", "Start the vpn in turned 'on' or 'off'."), "status", "");
+ QCommandLineOption startVPNOption("start-vpn", QApplication::translate("main", "Start the vpn, either 'on' or 'off'."), "status", "");
parser.addOption(startVPNOption);
parser.process(app);
@@ -121,6 +135,11 @@ int main(int argc, char **argv) {
exit(0);
}
+ if (startVPN != "" && startVPN != "on" && startVPN != "off") {
+ qDebug() << "Error: --start-vpn must be either 'on' or 'off'";
+ exit(0);
+ }
+
if (hideSystray) {
qDebug() << "Not showing systray icon because --no-systray option is set.";
}
@@ -144,12 +163,6 @@ int main(int argc, char **argv) {
QJsonModel *model = new QJsonModel;
- /* load providers json */
- QFile providerJson (":/providers.json");
- providerJson.open(QIODevice::ReadOnly | QIODevice::Text);
- QJsonModel *providers = new QJsonModel;
- providers->loadJson(providerJson.readAll());
-
/* the backend handler has slots for calling back to Go when triggered by
signals in Qml. */
ctx->setContextProperty("backend", &backend);
@@ -180,7 +193,6 @@ int main(int argc, char **argv) {
GoString statusChangedEvt = {stCh, (long int)strlen(stCh)};
SubscribeToEvent(statusChangedEvt, (void *)onStatusChanged);
- QJsonValue defaultProvider = providers->json().object().value("default");
/* we send json as bytes because it breaks as a simple string */
QString QProvidersJSON(providers->json().toJson(QJsonDocument::Compact));
@@ -188,7 +200,7 @@ int main(int argc, char **argv) {
InitializeBitmaskContext(
toGoStr(defaultProvider.toString()),
(char*)QProvidersJSON.toUtf8().data(), strlen(QProvidersJSON.toUtf8().data()),
- obfs4, disAutostart, toGoStr(startVPN));
+ obfs4, disAutostart, toGoStr(startVPN));
/* if requested, enable web api for controlling the VPN */
if (webAPI) {