diff --git a/captain/client.go b/captain/client.go index d3ef2f9..c488ae8 100644 --- a/captain/client.go +++ b/captain/client.go @@ -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: ¬ifications.ActionTypeOpenSettingPayload{ + Key: cfgOptionSpecialAccessCodeKey, + }, + } + spnTestPhaseSettingsButton = notifications.Action{ + Text: "Configure", + Type: notifications.ActionTypeOpenSetting, + Payload: ¬ifications.ActionTypeOpenSettingPayload{ + Key: CfgOptionEnableSPNKey, + }, + } ) func ClientReady() bool { @@ -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: ¬ifications.ActionTypeOpenSettingPayload{ - Key: cfgOptionSpecialAccessCodeKey, - }, - }, + spnTestPhaseStatusLinkButton, + spnTestPhaseEnterCodeButton, ).AttachToModule(module) return errors.New("no access code configured") } @@ -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: ¬ifications.ActionTypeOpenSettingPayload{ - Key: cfgOptionSpecialAccessCodeKey, - }, - }, + spnTestPhaseStatusLinkButton, + spnTestPhaseEnterCodeButton, ).AttachToModule(module) return errors.New("invalid access code") } @@ -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: ¬ifications.ActionTypeOpenSettingPayload{ - Key: cfgOptionSpecialAccessCodeKey, - }, - }, + spnTestPhaseStatusLinkButton, + spnTestPhaseEnterCodeButton, ).AttachToModule(module) return fmt.Errorf("failed to get access code: %s", err) } diff --git a/captain/navigation.go b/captain/navigation.go index 74c3d21..aa1c6eb 100644 --- a/captain/navigation.go +++ b/captain/navigation.go @@ -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: ¬ifications.ActionTypeOpenSettingPayload{ - Key: CfgOptionEnableSPNKey, - }, - }, + spnTestPhaseStatusLinkButton, + spnTestPhaseSettingsButton, ).AttachToModule(module) select { case <-ctx.Done(): @@ -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: ¬ifications.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 }