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

[gui] motd

parent 18f52af5
No related branches found
No related tags found
No related merge requests found
......@@ -301,7 +301,8 @@ clean:
#########################################################################
qmllint:
@qmllint gui/qml/*.qml
@qmllint gui/*.qml
@qmllint gui/components/*.qml
qmlfmt:
# needs https://github.com/jesperhh/qmlfmt in your path
......
......@@ -47,6 +47,9 @@ func main() {
fmt.Printf("Platform: %s %v\n", msg.Platform, mark(msg.IsValidPlatform()))
fmt.Printf("Urgency: %s %v\n", msg.Urgency, mark(msg.IsValidUrgency()))
fmt.Printf("Languages: %d %v\n", len(msg.Text), mark(msg.HasLocalizedText()))
for _, t := range msg.Text {
fmt.Printf(t.Str)
}
if !msg.IsValid() {
os.Exit(1)
}
......
......@@ -9,17 +9,26 @@ import (
"0xacab.org/leap/bitmask-vpn/pkg/config"
)
const riseupMOTD = "https://static.riseup.net/vpn/motd.json"
func FetchLatest() []Message {
empty := []Message{}
if os.Getenv("SKIP_MOTD") == "1" {
return empty
}
url := ""
switch config.Provider {
case "riseup.net":
url = "https://downloads.leap.se/motd/riseup/motd.json"
default:
return empty
if os.Getenv("DEBUG") == "1" {
url = os.Getenv("MOTD_URL")
if url == "" {
url = riseupMOTD
}
} else {
switch config.Provider {
case "riseup.net":
url = riseupMOTD
default:
return empty
}
}
log.Println("Fetching MOTD for", config.Provider)
b, err := fetchURL(url)
......
......@@ -47,6 +47,11 @@ type Message struct {
Text []LocalizedText `json:"text"`
}
type LocalizedText struct {
Lang string `json:"lang"`
Str string `json:"str"`
}
func (m *Message) IsValid() bool {
valid := (m.IsValidBegin() && m.IsValidEnd() &&
m.IsValidType() && m.IsValidPlatform() && m.IsValidUrgency() &&
......@@ -111,8 +116,3 @@ func (m *Message) IsValidUrgency() bool {
func (m *Message) HasLocalizedText() bool {
return len(m.Text) > 0
}
type LocalizedText struct {
Lang string `json:"lang"`
Str string `json:"str"`
}
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