summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-06-23 18:47:25 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-08-11 20:59:51 +0200
commit3e0764caa84a21a60f971ec3693429a9981c5921 (patch)
treee5f50c289536f15351bf325689e7037af6994554 /gui
parenteb97dc510c92a2fc1a340cccf4103068699947c4 (diff)
[feat] hide systray if -n option is passed
Diffstat (limited to 'gui')
-rw-r--r--gui/main.cpp37
-rw-r--r--gui/qml/main.qml6
2 files changed, 33 insertions, 10 deletions
diff --git a/gui/main.cpp b/gui/main.cpp
index e5486df..8033dba 100644
--- a/gui/main.cpp
+++ b/gui/main.cpp
@@ -48,17 +48,40 @@ int main(int argc, char **argv) {
QApplication::setApplicationName(backend.getAppName());
QApplication::setApplicationVersion(backend.getVersion());
QApplication app(argc, argv);
-
+ app.setQuitOnLastWindowClosed(false);
QCommandLineParser parser;
- parser.setApplicationDescription(backend.getAppName() + ": a fast and secure VPN. Powered by Bitmask.");
+ parser.setApplicationDescription(
+ backend.getAppName() +
+ QApplication::translate(
+ "main", ": a fast and secure VPN. Powered by Bitmask."));
parser.addHelpOption();
parser.addVersionOption();
+ parser.addOptions({
+ {
+ {"n", "no-systray"},
+ QApplication::translate("main",
+ "Do not show the systray icon (useful "
+ "together with gnome shell "
+ "extension, or to control VPN by other means)."),
+ },
+ {
+ {"i", "install-helpers"},
+ QApplication::translate(
+ "main",
+ "Install helpers (linux only, requires sudo)."),
+ },
+ });
parser.process(app);
- const QStringList args = parser.positionalArguments();
+ bool hideSystray = parser.isSet("no-systray");
+ bool installHelpers = parser.isSet("install-helpers");
- if (args.at(0) == "install-helpers") {
+ if (hideSystray) {
+ qDebug() << "Not showing systray icon because --no-systray option is set.";
+ }
+
+ if (installHelpers) {
qDebug() << "Will try to install helpers with sudo";
InstallHelpers();
exit(0);
@@ -72,21 +95,19 @@ int main(int argc, char **argv) {
translator.load(QLocale(), QLatin1String("main"), QLatin1String("_"), QLatin1String(":/i18n"));
app.installTranslator(&translator);
- app.setQuitOnLastWindowClosed(false);
QQmlApplicationEngine engine;
QQmlContext *ctx = engine.rootContext();
QJsonModel *model = new QJsonModel;
- std::string json = R"({"appName": "unknown", "provider": "unknown"})";
- model->loadJson(QByteArray::fromStdString(json));
/* the backend handler has slots for calling back to Go when triggered by
signals in Qml. */
ctx->setContextProperty("backend", &backend);
- /* set the json model, load the qml */
+ /* we pass the json model and set some useful flags */
ctx->setContextProperty("jsonModel", model);
ctx->setContextProperty("debugQml", debugQml);
+ ctx->setContextProperty("systrayVisible", !hideSystray);
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
diff --git a/gui/qml/main.qml b/gui/qml/main.qml
index 2ac9398..b4aa19a 100644
--- a/gui/qml/main.qml
+++ b/gui/qml/main.qml
@@ -80,7 +80,7 @@ ApplicationWindow {
SystemTrayIcon {
id: systray
- visible: true
+ visible: systrayVisible
onActivated: {
// this looks like a widget bug. middle click (reasons 3 or 4)
@@ -105,7 +105,9 @@ ApplicationWindow {
tooltip = qsTr("Checking status...")
console.debug("systray init completed")
hide();
- show();
+ if (systrayVisible) {
+ show();
+ }
}
menu: Menu {