diff --git a/bitmask.pro b/bitmask.pro index 910ba23ddb4605610077a194a51c84ba8d0a9faf..115aec710bee34a51d65f072f226e9f8f0c44314 100644 --- a/bitmask.pro +++ b/bitmask.pro @@ -1,7 +1,7 @@ # FIXME: this should be overwritten by build templates TARGET=riseup-vpn -CONFIG += qt static +CONFIG += qt staticlib windows:CONFIG += console unix:DEBUG:CONFIG += debug lessThan(QT_MAJOR_VERSION, 5): error("requires Qt 5") diff --git a/gui/backend.go b/gui/backend.go index 43f7b67c4527a01f05c9b1b14acd7f06e5adde71..d05ba7a97494919866ce458ec1fe0a3c0fa549c9 100644 --- a/gui/backend.go +++ b/gui/backend.go @@ -6,14 +6,18 @@ import ( "bytes" "encoding/json" "fmt" + "io" "log" "net/http" "os" + "path" "reflect" "sync" + //"time" "unsafe" "0xacab.org/leap/bitmask-vpn/pkg/bitmask" + "0xacab.org/leap/bitmask-vpn/pkg/config" "0xacab.org/leap/bitmask-vpn/pkg/pickle" "0xacab.org/leap/bitmask-vpn/pkg/systray2" "github.com/jmshal/go-locale" @@ -71,8 +75,6 @@ func trigger(event string) { /* connection status */ -const logFile = "systray.log" - const ( offStr = "off" startingStr = "starting" @@ -130,6 +132,7 @@ func (s status) fromString(st string) status { type connectionCtx struct { AppName string `json:"appName"` Provider string `json:"provider"` + Donate bool `json:"donate"` Status status `json:"status"` bm bitmask.Bitmask } @@ -170,8 +173,14 @@ func setStatus(st status) { go trigger(OnStatusChanged) } +func toggleDonate() { + stmut.Lock() + defer stmut.Unlock() + ctx.Donate = !ctx.Donate + go trigger(OnStatusChanged) +} + func setStatusFromStr(stStr string) { - log.Println("status:", stStr) setStatus(unknown.fromString(stStr)) } @@ -184,8 +193,18 @@ func initPrinter() *message.Printer { return message.NewPrinter(message.MatchLanguage(locale, "en")) } +const logFile = "systray.log" + +var logger io.Closer + // initializeBitmask instantiates a bitmask connection func initializeBitmask() { + _, err := config.ConfigureLogger(path.Join(config.Path, logFile)) + + if err != nil { + log.Println("Can't configure logger: ", err) + } + if ctx == nil { log.Println("error: cannot initialize bitmask, ctx is nil") os.Exit(1) @@ -223,6 +242,7 @@ func initializeContext(provider, appName string) { ctx = &connectionCtx{ AppName: appName, Provider: provider, + Donate: false, Status: st, } go trigger(OnStatusChanged) @@ -263,27 +283,32 @@ func mockUI() { //export SwitchOn func SwitchOn() { - setStatus(starting) - startVPN() + go setStatus(starting) + go startVPN() } //export SwitchOff func SwitchOff() { - setStatus(stopping) - stopVPN() + go setStatus(stopping) + go stopVPN() +} + +//export Unblock +func Unblock() { + fmt.Println("unblock... [not implemented]") } //export Quit func Quit() { if ctx.Status != off { - setStatus(stopping) + go setStatus(stopping) stopVPN() } } -//export Unblock -func Unblock() { - fmt.Println("unblock... [not implemented]") +//export ToggleDonate +func ToggleDonate() { + toggleDonate() } //export SubscribeToEvent @@ -293,12 +318,21 @@ func SubscribeToEvent(event string, f unsafe.Pointer) { //export InitializeBitmaskContext func InitializeBitmaskContext() { - provider := "black.riseup.net" - appName := "RiseupVPN" + provider := config.Provider + appName := config.ApplicationName initOnce.Do(func() { initializeContext(provider, appName) }) go ctx.updateStatus() + + /* DEBUG + timer := time.NewTimer(time.Second * 3) + go func() { + <-timer.C + fmt.Println("donate timer fired") + toggleDonate() + }() + */ } //export RefreshContext diff --git a/gui/gui.qrc b/gui/gui.qrc index 705c2b7427e1ef5dfe6e33680020337ce4aeff71..b0cd72c99d4ea33dd2d0c4a589632543d8260261 100644 --- a/gui/gui.qrc +++ b/gui/gui.qrc @@ -1,6 +1,7 @@ <RCC> <qresource prefix="/"> <file>qml/main.qml</file> + <file>qml/DonateDialog.qml</file> <file>assets/icon/png/black/vpn_off.png</file> <file>assets/icon/png/black/vpn_on.png</file> diff --git a/gui/handlers.cpp b/gui/handlers.cpp index 79fbb5829f6ce5d3d2af4a830893a12817d6695b..e37de2d162ba44f380155fa6c8cd6f4b0f71dc70 100644 --- a/gui/handlers.cpp +++ b/gui/handlers.cpp @@ -23,8 +23,14 @@ void Backend::unblock() Unblock(); } +void Backend::toggleDonate() +{ + ToggleDonate(); +} + void Backend::quit() { Quit(); emit this->quitDone(); } + diff --git a/gui/handlers.h b/gui/handlers.h index 0a8782d7f1a5f3c3ab47ae87ebbdd0feb6ad0f0a..3fe9eed5e18d32a172174fe94b59b40b12095132 100644 --- a/gui/handlers.h +++ b/gui/handlers.h @@ -33,6 +33,7 @@ public slots: void switchOn(); void switchOff(); void unblock(); + void toggleDonate(); void quit(); }; diff --git a/gui/main.cpp b/gui/main.cpp index c55b538b4325e46bfe144fea976c59bba597eb7a..5ecd4add775c734e838a0a4b4f96b5bb42e267c0 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -42,13 +42,11 @@ int main(int argc, char **argv) { exit(0); } - QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication app(argc, argv); if (!QSystemTrayIcon::isSystemTrayAvailable()) { - qDebug() << "No systray icon available. Things won't work for now, sorry..."; - exit(1); + qDebug() << "No systray icon available. Things might not work for now, sorry..."; } app.setQuitOnLastWindowClosed(false); diff --git a/gui/qml/DonateDialog.qml b/gui/qml/DonateDialog.qml new file mode 100644 index 0000000000000000000000000000000000000000..b7431abe4284b43fdc34bf0c9470e739c8d34cf7 --- /dev/null +++ b/gui/qml/DonateDialog.qml @@ -0,0 +1,27 @@ +import QtQuick 2.0 +import QtQuick.Dialogs 1.2 + +MessageDialog { + standardButtons: StandardButton.No | StandardButton.Yes + title: "Donate" + icon: StandardIcon.Warning + text: getText() + + function getText() { + var _name = ctx ? ctx.appName : "vpn" + var donateTxt = qsTr( + "The %1 service is expensive to run. Because we don't want to store personal information about you, there are no accounts or billing for this service. But if you want the service to continue, donate at least $5 each month.\n\nDo you want to donate now?").arg(_name) + return donateTxt + } + + onAccepted: { + if (backend) { + backend.donateAccepted(true) + } + } + onRejected: { + if (backend) { + backend.donateAccepted(false) + } + } +} diff --git a/gui/qml/main.qml b/gui/qml/main.qml index 80e5e62985cd3bae4527d38d45ae5b45e9699fde..98eac800a91d8d77cc62519caa376195a2a8ecd5 100644 --- a/gui/qml/main.qml +++ b/gui/qml/main.qml @@ -11,10 +11,16 @@ ApplicationWindow { property var ctx + Connections { target: jsonModel onDataChanged: { ctx = JSON.parse(jsonModel.getJson()); + if (ctx.donate == 'true') { + console.debug(jsonModel.getJson()) + donate.visible = true + backend.toggleDonate() + } } } @@ -92,6 +98,7 @@ ApplicationWindow { StateGroup { id: vpn state: ctx ? ctx.status : "" + states: [ State { name: "initializing" }, State { @@ -106,7 +113,7 @@ ApplicationWindow { }, State { name: "starting" - PropertyChanges { target: systray; tooltip: toHuman("connecting"); icon.source: icons["wait"] } + PropertyChanges { target: systray; tooltip: toHuman("connecting"); icon.source: icons["wait"] } PropertyChanges { target: statusItem; text: toHuman("connecting") } }, State { @@ -181,13 +188,17 @@ ApplicationWindow { } } + DonateDialog { + visible: false + id: donate + } +} + + /* LoginDialog { id: login } - DonateDialog { - id: donate - } MessageDialog { id: about buttons: MessageDialog.Ok @@ -223,7 +234,3 @@ ApplicationWindow { visible: ctxSystray.errorInitMsg != "" } */ - - - -}