Skip to content
Snippets Groups Projects
Unverified Commit eb97dc51 authored by Kali Kaneko's avatar Kali Kaneko
Browse files

[refactor] use qt argument parsing

parent cf5ed56c
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,16 @@ import (
"0xacab.org/leap/bitmask-vpn/pkg/backend"
)
//export GetVersion
func GetVersion() *C.char {
return (*C.char)(backend.GetVersion())
}
//export GetAppName
func GetAppName() *C.char {
return (*C.char)(backend.GetAppName())
}
//export SwitchOn
func SwitchOn() {
backend.SwitchOn()
......
......@@ -10,6 +10,16 @@ Backend::Backend(QObject *parent) : QObject(parent)
{
}
QString Backend::getAppName()
{
return QString(GetAppName());
}
QString Backend::getVersion()
{
return QString(GetVersion());
}
void Backend::switchOn()
{
SwitchOn();
......
......@@ -30,6 +30,8 @@ signals:
void quitDone();
public slots:
QString getAppName();
QString getVersion();
void switchOn();
void switchOff();
void unblock();
......
#include <csignal>
#include <string>
#include <QApplication>
#include <QSystemTrayIcon>
#include <QTimer>
#include <QTranslator>
#include <QtQml>
#include <QQmlApplicationEngine>
#include <QCommandLineParser>
#include <QQuickWindow>
#include <QSystemTrayIcon>
#include <QtQml>
#include "handlers.h"
#include "qjsonmodel.h"
......@@ -42,18 +40,30 @@ void signalHandler(int) {
int main(int argc, char **argv) {
signal(SIGINT, signalHandler);
bool debugQml = getEnv("DEBUG_QML_DATA") == "yes";
if (argc > 1 && strcmp(argv[1], "install-helpers") == 0) {
Backend backend;
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setApplicationName(backend.getAppName());
QApplication::setApplicationVersion(backend.getVersion());
QApplication app(argc, argv);
QCommandLineParser parser;
parser.setApplicationDescription(backend.getAppName() + ": a fast and secure VPN. Powered by Bitmask.");
parser.addHelpOption();
parser.addVersionOption();
parser.process(app);
const QStringList args = parser.positionalArguments();
if (args.at(0) == "install-helpers") {
qDebug() << "Will try to install helpers with sudo";
InstallHelpers();
exit(0);
}
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
qDebug() << "No systray icon available. Things might not work for now, sorry...";
}
......@@ -72,7 +82,6 @@ int main(int argc, char **argv) {
/* the backend handler has slots for calling back to Go when triggered by
signals in Qml. */
Backend backend;
ctx->setContextProperty("backend", &backend);
/* set the json model, load the qml */
......
......@@ -9,6 +9,7 @@ import (
"unsafe"
"0xacab.org/leap/bitmask-vpn/pkg/bitmask"
"0xacab.org/leap/bitmask-vpn/pkg/config/version"
"0xacab.org/leap/bitmask-vpn/pkg/pickle"
)
......@@ -74,3 +75,17 @@ func EnableMockBackend() {
log.Println("[+] Mocking ui interaction on port 8080. \nTry 'curl localhost:8080/{on|off|failed}' to toggle status.")
go enableMockBackend()
}
/* these two are a bit redundant since we already add them to ctx. however, we
want to have them available before everything else, to be able to parse cli
arguments. In the long run, we probably want to move all vendoring to qt, so
this probably should not live in the backend. */
func GetVersion() *C.char {
return C.CString(version.VERSION)
}
func GetAppName() *C.char {
p := bitmask.GetConfiguredProvider()
return C.CString(p.AppName)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment