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

[feat] working donate dialog

parent 57b7f111
No related branches found
No related tags found
No related merge requests found
# FIXME: this should be overwritten by build templates # FIXME: this should be overwritten by build templates
TARGET=riseup-vpn TARGET=riseup-vpn
CONFIG += qt static CONFIG += qt staticlib
windows:CONFIG += console windows:CONFIG += console
unix:DEBUG:CONFIG += debug unix:DEBUG:CONFIG += debug
lessThan(QT_MAJOR_VERSION, 5): error("requires Qt 5") lessThan(QT_MAJOR_VERSION, 5): error("requires Qt 5")
......
...@@ -6,14 +6,18 @@ import ( ...@@ -6,14 +6,18 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"log" "log"
"net/http" "net/http"
"os" "os"
"path"
"reflect" "reflect"
"sync" "sync"
//"time"
"unsafe" "unsafe"
"0xacab.org/leap/bitmask-vpn/pkg/bitmask" "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/pickle"
"0xacab.org/leap/bitmask-vpn/pkg/systray2" "0xacab.org/leap/bitmask-vpn/pkg/systray2"
"github.com/jmshal/go-locale" "github.com/jmshal/go-locale"
...@@ -71,8 +75,6 @@ func trigger(event string) { ...@@ -71,8 +75,6 @@ func trigger(event string) {
/* connection status */ /* connection status */
const logFile = "systray.log"
const ( const (
offStr = "off" offStr = "off"
startingStr = "starting" startingStr = "starting"
...@@ -130,6 +132,7 @@ func (s status) fromString(st string) status { ...@@ -130,6 +132,7 @@ func (s status) fromString(st string) status {
type connectionCtx struct { type connectionCtx struct {
AppName string `json:"appName"` AppName string `json:"appName"`
Provider string `json:"provider"` Provider string `json:"provider"`
Donate bool `json:"donate"`
Status status `json:"status"` Status status `json:"status"`
bm bitmask.Bitmask bm bitmask.Bitmask
} }
...@@ -170,8 +173,14 @@ func setStatus(st status) { ...@@ -170,8 +173,14 @@ func setStatus(st status) {
go trigger(OnStatusChanged) go trigger(OnStatusChanged)
} }
func toggleDonate() {
stmut.Lock()
defer stmut.Unlock()
ctx.Donate = !ctx.Donate
go trigger(OnStatusChanged)
}
func setStatusFromStr(stStr string) { func setStatusFromStr(stStr string) {
log.Println("status:", stStr)
setStatus(unknown.fromString(stStr)) setStatus(unknown.fromString(stStr))
} }
...@@ -184,8 +193,18 @@ func initPrinter() *message.Printer { ...@@ -184,8 +193,18 @@ func initPrinter() *message.Printer {
return message.NewPrinter(message.MatchLanguage(locale, "en")) return message.NewPrinter(message.MatchLanguage(locale, "en"))
} }
const logFile = "systray.log"
var logger io.Closer
// initializeBitmask instantiates a bitmask connection // initializeBitmask instantiates a bitmask connection
func initializeBitmask() { func initializeBitmask() {
_, err := config.ConfigureLogger(path.Join(config.Path, logFile))
if err != nil {
log.Println("Can't configure logger: ", err)
}
if ctx == nil { if ctx == nil {
log.Println("error: cannot initialize bitmask, ctx is nil") log.Println("error: cannot initialize bitmask, ctx is nil")
os.Exit(1) os.Exit(1)
...@@ -223,6 +242,7 @@ func initializeContext(provider, appName string) { ...@@ -223,6 +242,7 @@ func initializeContext(provider, appName string) {
ctx = &connectionCtx{ ctx = &connectionCtx{
AppName: appName, AppName: appName,
Provider: provider, Provider: provider,
Donate: false,
Status: st, Status: st,
} }
go trigger(OnStatusChanged) go trigger(OnStatusChanged)
...@@ -263,27 +283,32 @@ func mockUI() { ...@@ -263,27 +283,32 @@ func mockUI() {
//export SwitchOn //export SwitchOn
func SwitchOn() { func SwitchOn() {
setStatus(starting) go setStatus(starting)
startVPN() go startVPN()
} }
//export SwitchOff //export SwitchOff
func SwitchOff() { func SwitchOff() {
setStatus(stopping) go setStatus(stopping)
stopVPN() go stopVPN()
}
//export Unblock
func Unblock() {
fmt.Println("unblock... [not implemented]")
} }
//export Quit //export Quit
func Quit() { func Quit() {
if ctx.Status != off { if ctx.Status != off {
setStatus(stopping) go setStatus(stopping)
stopVPN() stopVPN()
} }
} }
//export Unblock //export ToggleDonate
func Unblock() { func ToggleDonate() {
fmt.Println("unblock... [not implemented]") toggleDonate()
} }
//export SubscribeToEvent //export SubscribeToEvent
...@@ -293,12 +318,21 @@ func SubscribeToEvent(event string, f unsafe.Pointer) { ...@@ -293,12 +318,21 @@ func SubscribeToEvent(event string, f unsafe.Pointer) {
//export InitializeBitmaskContext //export InitializeBitmaskContext
func InitializeBitmaskContext() { func InitializeBitmaskContext() {
provider := "black.riseup.net" provider := config.Provider
appName := "RiseupVPN" appName := config.ApplicationName
initOnce.Do(func() { initOnce.Do(func() {
initializeContext(provider, appName) initializeContext(provider, appName)
}) })
go ctx.updateStatus() go ctx.updateStatus()
/* DEBUG
timer := time.NewTimer(time.Second * 3)
go func() {
<-timer.C
fmt.Println("donate timer fired")
toggleDonate()
}()
*/
} }
//export RefreshContext //export RefreshContext
......
<RCC> <RCC>
<qresource prefix="/"> <qresource prefix="/">
<file>qml/main.qml</file> <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_off.png</file>
<file>assets/icon/png/black/vpn_on.png</file> <file>assets/icon/png/black/vpn_on.png</file>
......
...@@ -23,8 +23,14 @@ void Backend::unblock() ...@@ -23,8 +23,14 @@ void Backend::unblock()
Unblock(); Unblock();
} }
void Backend::toggleDonate()
{
ToggleDonate();
}
void Backend::quit() void Backend::quit()
{ {
Quit(); Quit();
emit this->quitDone(); emit this->quitDone();
} }
...@@ -33,6 +33,7 @@ public slots: ...@@ -33,6 +33,7 @@ public slots:
void switchOn(); void switchOn();
void switchOff(); void switchOff();
void unblock(); void unblock();
void toggleDonate();
void quit(); void quit();
}; };
......
...@@ -42,13 +42,11 @@ int main(int argc, char **argv) { ...@@ -42,13 +42,11 @@ int main(int argc, char **argv) {
exit(0); exit(0);
} }
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv); QApplication app(argc, argv);
if (!QSystemTrayIcon::isSystemTrayAvailable()) { if (!QSystemTrayIcon::isSystemTrayAvailable()) {
qDebug() << "No systray icon available. Things won't work for now, sorry..."; qDebug() << "No systray icon available. Things might not work for now, sorry...";
exit(1);
} }
app.setQuitOnLastWindowClosed(false); app.setQuitOnLastWindowClosed(false);
......
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)
}
}
}
...@@ -11,10 +11,16 @@ ApplicationWindow { ...@@ -11,10 +11,16 @@ ApplicationWindow {
property var ctx property var ctx
Connections { Connections {
target: jsonModel target: jsonModel
onDataChanged: { onDataChanged: {
ctx = JSON.parse(jsonModel.getJson()); ctx = JSON.parse(jsonModel.getJson());
if (ctx.donate == 'true') {
console.debug(jsonModel.getJson())
donate.visible = true
backend.toggleDonate()
}
} }
} }
...@@ -92,6 +98,7 @@ ApplicationWindow { ...@@ -92,6 +98,7 @@ ApplicationWindow {
StateGroup { StateGroup {
id: vpn id: vpn
state: ctx ? ctx.status : "" state: ctx ? ctx.status : ""
states: [ states: [
State { name: "initializing" }, State { name: "initializing" },
State { State {
...@@ -106,7 +113,7 @@ ApplicationWindow { ...@@ -106,7 +113,7 @@ ApplicationWindow {
}, },
State { State {
name: "starting" 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") } PropertyChanges { target: statusItem; text: toHuman("connecting") }
}, },
State { State {
...@@ -181,13 +188,17 @@ ApplicationWindow { ...@@ -181,13 +188,17 @@ ApplicationWindow {
} }
} }
DonateDialog {
visible: false
id: donate
}
}
/* /*
LoginDialog { LoginDialog {
id: login id: login
} }
DonateDialog {
id: donate
}
MessageDialog { MessageDialog {
id: about id: about
buttons: MessageDialog.Ok buttons: MessageDialog.Ok
...@@ -223,7 +234,3 @@ ApplicationWindow { ...@@ -223,7 +234,3 @@ ApplicationWindow {
visible: ctxSystray.errorInitMsg != "" visible: ctxSystray.errorInitMsg != ""
} }
*/ */
}
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