Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #17 from safing/fix/spn-notification-buttons
Browse files Browse the repository at this point in the history
Update SPN test phase notifications
  • Loading branch information
dhaavi authored Oct 6, 2021
2 parents 1e35536 + 351a681 commit 84778e3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 60 deletions.
62 changes: 26 additions & 36 deletions captain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ import (

var (
ready = abool.New()

spnTestPhaseStatusLinkButton = notifications.Action{
Text: "Test Phase Info",
Type: notifications.ActionTypeOpenURL,
Payload: "https://docs.safing.io/spn/broader-testing/status",
}
spnTestPhaseEnterCodeButton = notifications.Action{
Text: "Enter Code",
Type: notifications.ActionTypeOpenSetting,
Payload: &notifications.ActionTypeOpenSettingPayload{
Key: cfgOptionSpecialAccessCodeKey,
},
}
spnTestPhaseSettingsButton = notifications.Action{
Text: "Configure",
Type: notifications.ActionTypeOpenSetting,
Payload: &notifications.ActionTypeOpenSettingPayload{
Key: CfgOptionEnableSPNKey,
},
}
)

func ClientReady() bool {
Expand Down Expand Up @@ -58,18 +78,8 @@ func preFlightCheck(ctx context.Context) error {
"spn:no-access-code",
"SPN Requires Access Code",
"Please enter your special access code for the testing phase in the settings.",
notifications.Action{
Text: "Test Phase Info",
Type: notifications.ActionTypeOpenURL,
Payload: "https://github.com/safing/spn/wiki/SPN-Testing-Goals-and-Status",
},
notifications.Action{
Text: "Enter Code",
Type: notifications.ActionTypeOpenSetting,
Payload: &notifications.ActionTypeOpenSettingPayload{
Key: cfgOptionSpecialAccessCodeKey,
},
},
spnTestPhaseStatusLinkButton,
spnTestPhaseEnterCodeButton,
).AttachToModule(module)
return errors.New("no access code configured")
}
Expand All @@ -85,18 +95,8 @@ func preFlightCheck(ctx context.Context) error {
"spn:invalid-access-code",
"SPN Access Code Invalid",
"Your special access code is invalid: "+err.Error(),
notifications.Action{
Text: "Test Phase Info",
Type: notifications.ActionTypeOpenURL,
Payload: "https://github.com/safing/spn/wiki/SPN-Testing-Goals-and-Status",
},
notifications.Action{
Text: "Enter Code",
Type: notifications.ActionTypeOpenSetting,
Payload: &notifications.ActionTypeOpenSettingPayload{
Key: cfgOptionSpecialAccessCodeKey,
},
},
spnTestPhaseStatusLinkButton,
spnTestPhaseEnterCodeButton,
).AttachToModule(module)
return errors.New("invalid access code")
}
Expand All @@ -109,18 +109,8 @@ func preFlightCheck(ctx context.Context) error {
"spn:internal-access-code-error",
"SPN Access Code Invalid",
"Internal access code error: "+err.Error(),
notifications.Action{
Text: "Test Phase Info",
Type: notifications.ActionTypeOpenURL,
Payload: "https://github.com/safing/spn/wiki/SPN-Testing-Goals-and-Status",
},
notifications.Action{
Text: "Enter Code",
Type: notifications.ActionTypeOpenSetting,
Payload: &notifications.ActionTypeOpenSettingPayload{
Key: cfgOptionSpecialAccessCodeKey,
},
},
spnTestPhaseStatusLinkButton,
spnTestPhaseEnterCodeButton,
).AttachToModule(module)
return fmt.Errorf("failed to get access code: %s", err)
}
Expand Down
29 changes: 5 additions & 24 deletions captain/navigation.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,8 @@ managing:
"spn:home-hub-failure",
"SPN Failed to Connect",
fmt.Sprintf("Failed to connect to a home hub: %s. The Portmaster will retry to connect automatically.", err),
notifications.Action{
Text: "Test Phase Info",
Type: notifications.ActionTypeOpenURL,
Payload: "https://github.com/safing/spn/wiki/SPN-Testing-Goals-and-Status",
},
notifications.Action{
Text: "Configure",
Type: notifications.ActionTypeOpenSetting,
Payload: &notifications.ActionTypeOpenSettingPayload{
Key: CfgOptionEnableSPNKey,
},
},
spnTestPhaseStatusLinkButton,
spnTestPhaseSettingsButton,
).AttachToModule(module)
select {
case <-ctx.Done():
Expand All @@ -73,24 +63,15 @@ managing:
"spn:connected-to-home-hub",
"Connected to SPN Test Network",
fmt.Sprintf("You are connected to the SPN test network at %s. This notification is persistent for awareness.", homeTerminal.RemoteAddr()),
notifications.Action{
Text: "Test Phase Info",
Type: notifications.ActionTypeOpenURL,
Payload: "https://github.com/safing/spn/wiki/SPN-Testing-Goals-and-Status",
},
notifications.Action{
Text: "Configure",
Type: notifications.ActionTypeOpenSetting,
Payload: &notifications.ActionTypeOpenSettingPayload{
Key: CfgOptionEnableSPNKey,
},
},
spnTestPhaseStatusLinkButton,
spnTestPhaseSettingsButton,
).AttachToModule(module)
ready.Set()
log.Infof("spn/captain: established new home %s", home.Hub)
log.Infof("spn/captain: client is ready")
}
}

return nil
}

Expand Down

0 comments on commit 84778e3

Please sign in to comment.