feat: add more browser support
Add more browser support for opening links for accounts and statuses. Changes: - Add browser support if the BROWSER environment variable is set. - Add support for viewing accounts in the browser. - Add support for viewing statuses in the browser (if they are publicly viewable)
This commit is contained in:
parent
a7e72ac2c4
commit
8f0c507a02
4 changed files with 28 additions and 10 deletions
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
== Overview
|
== Overview
|
||||||
|
|
||||||
Enbas is a https://docs.gotosocial.org/en/latest/[GoToSocial] (GTS) client for your terminal written
|
Enbas is a https://docs.gotosocial.org/en/latest/[GoToSocial] client for your terminal written
|
||||||
in https://go.dev[Go]. The project is in its experimental stages of development so bugs and breaking
|
in https://go.dev[Go]. The project is in its experimental stages of development so bugs and breaking
|
||||||
changes may appear. Enbas has limited functionality at the moment and it is **not** recommended for use
|
changes may appear. Enbas has limited functionality at the moment and it is **not** recommended for use
|
||||||
with your production GoToSocial servers.
|
with your production GoToSocial servers.
|
||||||
|
@ -157,7 +157,8 @@ Use "enbas [command] --help" for more information about a command.
|
||||||
|
|
||||||
=== Log into your GoToSocial account
|
=== Log into your GoToSocial account
|
||||||
|
|
||||||
Enbas uses the Oauth2 authentication flow to log into your account on GTS. This process requires your input to give consent to allow Enbas access to your account.
|
Enbas uses the Oauth2 authentication flow to log into your account on GoToSocial.
|
||||||
|
This process requires your input to give consent to allow Enbas access to your account.
|
||||||
|
|
||||||
[WARNING]
|
[WARNING]
|
||||||
====
|
====
|
||||||
|
@ -176,14 +177,14 @@ The login flow is completed using the following steps:
|
||||||
enbas login --instance gotosocial-01.social.example
|
enbas login --instance gotosocial-01.social.example
|
||||||
----
|
----
|
||||||
|
|
||||||
2. The application will register itself and the GTS server will create a new client ID and secret that the app needs for authentication.
|
2. The application will register itself and the GoToSocial server will create a new client ID and secret that the app needs for authentication.
|
||||||
|
|
||||||
3. The application will then generate a link to the consent form for you to access in your browser.
|
3. The application will then generate a link to the consent form for you to access in your browser.
|
||||||
This link will be printed on your terminal screen along with a message explaining that you need to obtain the `out-of-band` token to continue.
|
This link will be printed on your terminal screen along with a message explaining that you need to obtain the `out-of-band` token to continue.
|
||||||
If you're on Linux the link will open in a new browser tab for you to sign into your account.
|
If you have the `BROWSER` environment variable set or if you're using Linux, the link will open in a new browser tab for you to sign into your account.
|
||||||
If you're using a different OS or the browser tab doesn't open, you can manually open the link in a new browser tab.
|
If the browser tab doesn't open, you can manually copy and paste the link in your favourite browser.
|
||||||
|
|
||||||
4. Once you've signed into GTS on your browser, you will be informed that Enbas would like to perform actions on your behalf.
|
4. Once you've signed into GoToSocial on your browser, you will be informed that Enbas would like to perform actions on your behalf.
|
||||||
If you're happy with this then click on the `Allow` button.
|
If you're happy with this then click on the `Allow` button.
|
||||||
+
|
+
|
||||||
image::assets/images/consent_form.png[A screenshot of the consent form]
|
image::assets/images/consent_form.png[A screenshot of the consent form]
|
||||||
|
@ -192,7 +193,7 @@ image::assets/images/consent_form.png[A screenshot of the consent form]
|
||||||
|
|
||||||
6. Paste the token into the prompt and press `ENTER`.
|
6. Paste the token into the prompt and press `ENTER`.
|
||||||
Enbas will then exchange the token for an access token which will be used to authentication to the
|
Enbas will then exchange the token for an access token which will be used to authentication to the
|
||||||
GTS server on your behalf.
|
GoToSocial server on your behalf.
|
||||||
Enbas will then verify the access token, save the credentials to the `credentials.json` file in your configuration directory,
|
Enbas will then verify the access token, save the credentials to the `credentials.json` file in your configuration directory,
|
||||||
and confirm that you have successfully logged into your account.
|
and confirm that you have successfully logged into your account.
|
||||||
+
|
+
|
||||||
|
|
|
@ -2,6 +2,7 @@ package executor
|
||||||
|
|
||||||
const (
|
const (
|
||||||
flagAccountName = "account-name"
|
flagAccountName = "account-name"
|
||||||
|
flagBrowser = "browser"
|
||||||
flagContent = "content"
|
flagContent = "content"
|
||||||
flagInstance = "instance"
|
flagInstance = "instance"
|
||||||
flagLimit = "limit"
|
flagLimit = "limit"
|
||||||
|
|
|
@ -15,6 +15,7 @@ type ShowExecutor struct {
|
||||||
myAccount bool
|
myAccount bool
|
||||||
skipAccountRelationship bool
|
skipAccountRelationship bool
|
||||||
showUserPreferences bool
|
showUserPreferences bool
|
||||||
|
showInBrowser bool
|
||||||
resourceType string
|
resourceType string
|
||||||
accountName string
|
accountName string
|
||||||
statusID string
|
statusID string
|
||||||
|
@ -33,6 +34,7 @@ func NewShowExecutor(tlf TopLevelFlags, name, summary string) *ShowExecutor {
|
||||||
command.BoolVar(&command.myAccount, flagMyAccount, false, "set to true to lookup your account")
|
command.BoolVar(&command.myAccount, flagMyAccount, false, "set to true to lookup your account")
|
||||||
command.BoolVar(&command.skipAccountRelationship, flagSkipRelationship, false, "set to true to skip showing your relationship to the specified account")
|
command.BoolVar(&command.skipAccountRelationship, flagSkipRelationship, false, "set to true to skip showing your relationship to the specified account")
|
||||||
command.BoolVar(&command.showUserPreferences, flagShowPreferences, false, "show your preferences")
|
command.BoolVar(&command.showUserPreferences, flagShowPreferences, false, "show your preferences")
|
||||||
|
command.BoolVar(&command.showInBrowser, flagBrowser, false, "set to true to view in the browser")
|
||||||
command.StringVar(&command.resourceType, flagType, "", "specify the type of resource to display")
|
command.StringVar(&command.resourceType, flagType, "", "specify the type of resource to display")
|
||||||
command.StringVar(&command.accountName, flagAccountName, "", "specify the account name in full (username@domain)")
|
command.StringVar(&command.accountName, flagAccountName, "", "specify the account name in full (username@domain)")
|
||||||
command.StringVar(&command.statusID, flagStatusID, "", "specify the ID of the status to display")
|
command.StringVar(&command.statusID, flagStatusID, "", "specify the ID of the status to display")
|
||||||
|
@ -108,6 +110,12 @@ func (c *ShowExecutor) showAccount(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.showInBrowser {
|
||||||
|
utilities.OpenLink(account.URL)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println(account)
|
fmt.Println(account)
|
||||||
|
|
||||||
if !c.myAccount && !c.skipAccountRelationship {
|
if !c.myAccount && !c.skipAccountRelationship {
|
||||||
|
@ -141,6 +149,12 @@ func (c *ShowExecutor) showStatus(gtsClient *client.Client) error {
|
||||||
return fmt.Errorf("unable to retrieve the status; %w", err)
|
return fmt.Errorf("unable to retrieve the status; %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.showInBrowser {
|
||||||
|
utilities.OpenLink(status.URL)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println(status)
|
fmt.Println(status)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
package utilities
|
package utilities
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func OpenLink(url string) {
|
func OpenLink(url string) {
|
||||||
var open string
|
var open string
|
||||||
//envBrower := os.Getenv("BROWSER")
|
|
||||||
|
envBrower := os.Getenv("BROWSER")
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
//case len(envBrower) > 0:
|
case len(envBrower) > 0:
|
||||||
// open = envBrower
|
open = envBrower
|
||||||
case runtime.GOOS == "linux":
|
case runtime.GOOS == "linux":
|
||||||
open = "xdg-open"
|
open = "xdg-open"
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue